Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSKIP 351 + RSKIP 144 #1930

Merged
merged 112 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
7302420
Header version based on activation block
ilanolkies Oct 3, 2022
8bb8859
Use byte type for header version
ilanolkies Oct 6, 2022
2a1186f
Test genesis version
ilanolkies Oct 6, 2022
e24f599
Fix merge
ilanolkies Oct 27, 2022
0ead12c
RSKIP 351 implementation
ilanolkies Nov 1, 2022
d9a0537
Add tests
ilanolkies Nov 14, 2022
79685df
Merge branch 'master' into rskip351
ilanolkies Nov 14, 2022
0d0e7d8
Fix build
ilanolkies Nov 14, 2022
febccd6
Block header addition (#1790)
julianlen Jun 1, 2022
89f9471
Modified the remasc payment.
julianlen Jun 1, 2022
5d00cce
Research/parallel-tx/header generation from master (#1792)
julianlen Jun 15, 2022
9516448
Research/parallel-tx/block validation (#1804)
julianlen Jun 15, 2022
3a23caa
Created a Constant with the number of threads (#1815)
julianlen Jun 22, 2022
2398add
Research/refactoring code (#1817)
julianlen Jun 27, 2022
74f9c8c
Research/parallel-tx/optimize writes (#1811)
ilanolkies Jun 27, 2022
fba1e7a
added validation for the rskip144 (#1824)
julianlen Jul 6, 2022
29b92e2
Fix write the same value - avoid write on add balance 0 (#1833)
ilanolkies Jul 19, 2022
ecb2a65
Research/parallel-tx/Refactor validblock (#1794)
ilanolkies Jul 19, 2022
90e5ea8
Research/main parallel tx revision (#1865)
julianlen Sep 23, 2022
5a63b2e
Research/main parallel tx remasc (#1895)
julianlen Nov 14, 2022
6de53a3
Merge branch 'research/main_parallel_tx' into rskip351
ilanolkies Nov 17, 2022
194fa4b
Move edges to block header extension
ilanolkies Nov 18, 2022
ccf4e1f
Merge branch 'master' into rskip351+rskip144
ilanolkies Nov 22, 2022
e532933
Add RSKIP 144 to fingerroot500
ilanolkies Nov 22, 2022
51608e3
General fixes + refactor getSublistCandidate
ilanolkies Nov 23, 2022
4306c44
Fixing addBalance with zero (#1932)
julianlen Nov 24, 2022
016d57c
Fix writes after writing to parallel (#1949)
ilanolkies Dec 14, 2022
60172eb
Merge branch 'master' into rskip351+rskip144
ilanolkies Dec 15, 2022
7dd23fe
Merge branch 'master' into rskip351+rskip144
ilanolkies Dec 26, 2022
8f3b752
Merge branch 'master' into rskip351+rskip144
ilanolkies Feb 8, 2023
d8bb353
RSKIP 144 - Fix state after executing parallel (#1973)
ilanolkies Feb 22, 2023
a690e36
RSKIP 144 tests (#1983)
ilanolkies Mar 1, 2023
2c9a6e8
RSKIP 351 updates (#1938)
ilanolkies Mar 13, 2023
735ead4
Remove unused import
ilanolkies Mar 13, 2023
ac3884f
Apart from testing, when RSKIP144 is deactivated, the txExecutionSubl…
julianlen Apr 10, 2023
b45f75b
Rskip351+rskip144+precompiled contracts (#1994)
julianlen Apr 10, 2023
0353532
The gas limit provided to the TransactionHandler is now divided into …
julianlen Apr 12, 2023
9b90491
Now the gas limit considered is the sublist gas limit
julianlen Apr 19, 2023
9689245
Refactored TxExecutorTest so there is no extra constructor in Transac…
julianlen Apr 20, 2023
3e1b9de
Changed the gas limits for all the tests since the new considered gas…
julianlen Apr 20, 2023
40e3ebf
Tested that even with the sublists full the used gas states below or …
julianlen Apr 25, 2023
fe1ba90
Renaming of variables
julianlen Apr 27, 2023
31eca8a
Merge pull request #2025 from rsksmart/rskip351+rskip144+gaslimit
javicid May 3, 2023
6b21bb6
Fixes for sonarcloud
julianlen May 3, 2023
7078ec9
Merge branch 'master' into rskip351+rskip144-even
ilanolkies May 9, 2023
61402c6
Merge branch 'master' into rskip351+rskip144
ilanolkies May 23, 2023
bda76ae
Change in the gas limit in the addBlockToBlockchain method for the Lo…
julianlen May 23, 2023
b19eecc
Merge remote-tracking branch 'origin/master' into rskip351+rskip144
Vovchyk Jul 7, 2023
c5cece8
Updated activation hf for rskips; Fixed unit tests
Vovchyk Jul 7, 2023
f70e601
Fixed integration tests
Vovchyk Jul 10, 2023
4592e1a
Added missing getEncoded(bool,bool) to BlockHeader
Vovchyk Jul 12, 2023
449d28f
Removed unused 144and351.conf file
Vovchyk Jul 12, 2023
693bb52
Fixed long sync
Vovchyk Jul 21, 2023
9321aa3
Using compressed header encoding for calculating HashForMergedMining
Vovchyk Jul 25, 2023
39275f1
Merge branch 'master' into rskip351+rskip144
Vovchyk Sep 6, 2023
c188238
Fixed testPush0 unit test
Vovchyk Sep 6, 2023
2fb6693
Enabled precompiles in parallel list (with option to disable if neede…
Vovchyk Sep 11, 2023
28bf995
Added posibility to specify in code which precompiles are allowed to …
Vovchyk Sep 13, 2023
306f80e
Implemented reusable thread pools; Added flag to force tx list execut…
Vovchyk Sep 15, 2023
82ba683
Reworked thread scheduling for parallel tx execution
Vovchyk Sep 18, 2023
07a1186
Merge branch 'master' into rskip351+rskip144
Vovchyk Sep 18, 2023
228a266
Used in-line tx execution if num of edges is less than 2
Vovchyk Sep 19, 2023
6ef1560
Merge remote-tracking branch 'origin/master' into rskip351+rskip144
Vovchyk Oct 2, 2023
e8b9910
Merge branch 'master' into rskip351+rskip144
Vovchyk Oct 4, 2023
027ee5b
Added tx gas limit validation before adding to mempool
Vovchyk Oct 19, 2023
501d5d8
Merge remote-tracking branch 'origin/master' into rskip351+rskip144
Vovchyk Nov 15, 2023
27f2a82
Merge remote-tracking branch 'origin/master' into master-rskip351+rsk…
Vovchyk Jan 30, 2024
1e133fb
Merge pull request #2240 from rsksmart/master-rskip351+rskip144-merge
Vovchyk Jan 30, 2024
33590c6
Refactor PTE gas distribution logic
rmoreliovlabs Feb 2, 2024
a214bff
Change refactor approach and update affected tests
rmoreliovlabs Feb 6, 2024
48df218
Merge pull request #2246 from rsksmart/pte-gas-distribution-refactor
Vovchyk Feb 7, 2024
964eb45
Merge pull request #2251 from rsksmart/master
Vovchyk Feb 7, 2024
e5f9086
Disabled PTE feature by default
Vovchyk Feb 7, 2024
0f61489
Merge pull request #2252 from rsksmart/pte-disabled-by-default
Vovchyk Feb 7, 2024
2f35b8f
Update tx execution threads constant value
rmoreliovlabs Feb 8, 2024
cb03dd4
Fix failing test
rmoreliovlabs Feb 8, 2024
ef9fdfb
Code cleaning
rmoreliovlabs Feb 8, 2024
ca111b6
Merge pull request #2253 from rsksmart/update-parallel-threads-amount
Vovchyk Feb 8, 2024
30ebfb8
Cover cases with uneven division in getSublistGasLimit
rmoreliovlabs Feb 16, 2024
5161f65
Add javadoc and inner comments
rmoreliovlabs Feb 16, 2024
ecf6522
Merge pull request #2257 from rsksmart/refactor-get-sublist-gas-limit
rmoreliovlabs Feb 22, 2024
e1dfd1d
Merge remote-tracking branch 'origin/master' into master-rskip351+rsk…
Vovchyk Apr 16, 2024
8f9ed2a
Fixed bridgeDelegateCall unit test
Vovchyk Apr 16, 2024
a84de30
Merge pull request #2288 from rsksmart/master-rskip351+rskip144-merge
Vovchyk Apr 16, 2024
594b1b0
Merge branch 'master' into rskip351+rskip144
Vovchyk May 27, 2024
79547e0
Fixed sonar complains / Removed unused imports
Vovchyk May 27, 2024
9eb6d75
Merge branch 'master' into rskip351+rskip144
Vovchyk May 27, 2024
f714316
Adding custom config
nagarev Jun 11, 2024
e389b5a
Adding test (wip)
nagarev Jun 11, 2024
66cd486
Adding pte edges field
nagarev Jun 12, 2024
e299f56
Updating test WIP
nagarev Jun 12, 2024
18f2c0f
Updating tests
nagarev Jun 17, 2024
d79f2a7
Updating package name
nagarev Jun 19, 2024
36a2d76
Removing duplicated stacktrace print
nagarev Jun 20, 2024
cc2b39a
Updating test
nagarev Jun 24, 2024
5cb310f
Merge branch 'master' into rskip351+rskip144
Vovchyk Jun 26, 2024
51ba9e1
Merge pull request #2477 from rsksmart/add-int-test
Vovchyk Jul 1, 2024
b639740
Merge branch 'master' into rskip351+rskip144
Vovchyk Jul 4, 2024
d894940
fixed executedContractWithDelegateCallToNonExistentContract test
Vovchyk Jul 4, 2024
559de16
Merge branch 'master' into rskip351+rskip144
Vovchyk Jul 18, 2024
398faa5
Merge remote-tracking branch 'origin/master' into vovchyk/master-rski…
Vovchyk Sep 4, 2024
baf4c9a
Merge pull request #2708 from rsksmart/vovchyk/master-rskip351+rskip1…
Vovchyk Sep 4, 2024
3856836
fix(pte): fixing sonar complaints
Vovchyk Sep 5, 2024
731751d
Merge pull request #2709 from rsksmart/vovchyk/rskip351+rskip144-fix-…
Vovchyk Sep 5, 2024
79523ca
fix(pte): suppress sonar warnings
Vovchyk Sep 5, 2024
3850591
Merge pull request #2710 from rsksmart/vovchyk/rskip351+rskip144-supp…
Vovchyk Sep 5, 2024
3059c4c
Merge remote-tracking branch 'origin/master' into vovchyk/master-rski…
Vovchyk Sep 25, 2024
ecbb0ad
feat(pte): fix unit tests after merge from master
Vovchyk Sep 26, 2024
ebc5664
Merge pull request #2755 from rsksmart/vovchyk/master-rskip351+rskip1…
Vovchyk Sep 26, 2024
b6227a3
Merge branch 'master' into rskip351+rskip144
fmacleal Sep 27, 2024
f46f15f
Merge branch 'master' into rskip351+rskip144
Vovchyk Oct 8, 2024
63c08da
Merge branch 'master' into rskip351+rskip144
Vovchyk Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ public class OkHttpClientTestFixture {
" \"jsonrpc\": \"2.0\"\n" +
"}]";

public static final String ETH_GET_BLOCK_BY_NUMBER =
"{\n" +
" \"method\": \"eth_getBlockByNumber\",\n" +
" \"params\": [\n" +
" \"<BLOCK_NUM_OR_TAG>\",\n" +
" true\n" +
" ],\n" +
" \"id\": 1,\n" +
" \"jsonrpc\": \"2.0\"\n" +
"}";

public static final String ETH_SEND_TRANSACTION =
"{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"eth_sendTransaction\",\n" +
" \"id\": 1,\n" +
" \"params\": [{\n" +
" \"from\": \"<ADDRESS_FROM>\",\n" +
" \"to\": \"<ADDRESS_TO>\",\n" +
" \"gas\": \"<GAS>\",\n" +
" \"gasPrice\": \"<GAS_PRICE>\",\n" +
" \"value\": \"<VALUE>\"\n" +
" }]\n" +
"}";

private OkHttpClientTestFixture() {
}

Expand Down Expand Up @@ -101,4 +126,9 @@ public static JsonNode getJsonResponseForGetBestBlockMessage(int port) throws IO
Response response = sendJsonRpcGetBestBlockMessage(port);
return new ObjectMapper().readTree(response.body().string());
}

public static String getEnvelopedMethodCalls(String... methodCall) {
return "[\n" + String.join(",\n", methodCall) + "]";
}

}
244 changes: 244 additions & 0 deletions rskj-core/src/integrationTest/java/pte/PteIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
* This file is part of RskJ
* Copyright (C) 2024 RSK Labs Ltd.
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package pte;

import co.rsk.util.OkHttpClientTestFixture;
import co.rsk.util.cli.CommandLineFixture;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.squareup.okhttp.Response;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Stream;

import static co.rsk.util.OkHttpClientTestFixture.*;

public class PteIntegrationTest {

/*
When running this test locally, don't forget to build the .jar for the code you're trying to
test ('./gradlew clean' and './gradlew assemble' should be sufficient for most cases).
*/

private static final int RPC_PORT = 9999;
private static final int MAX_BLOCKS_TO_GET = 20;

private final ObjectMapper objectMapper = new ObjectMapper();

private String buildLibsPath;
private String jarName;
private String strBaseArgs;
private String baseJavaCmd;

@TempDir
private Path tempDir;

@BeforeEach
public void setup() throws IOException {
String projectPath = System.getProperty("user.dir");
buildLibsPath = String.format("%s/build/libs", projectPath);
String integrationTestResourcesPath = String.format("%s/src/integrationTest/resources", projectPath);
String logbackXmlFile = String.format("%s/logback.xml", integrationTestResourcesPath);
String rskConfFile = String.format("%s/pte-integration-test-rskj.conf", integrationTestResourcesPath);
Stream<Path> pathsStream = Files.list(Paths.get(buildLibsPath));
jarName = pathsStream.filter(p -> !p.toFile().isDirectory())
.map(p -> p.getFileName().toString())
.filter(fn -> fn.endsWith("-all.jar"))
.findFirst()
.orElse("");

Path databaseDirPath = tempDir.resolve("database");
String databaseDir = databaseDirPath.toString();
String[] baseArgs = new String[]{
String.format("-Xdatabase.dir=%s", databaseDir),
"--regtest",
String.format("-Xrpc.providers.web.http.port=%s", RPC_PORT)
};
strBaseArgs = String.join(" ", baseArgs);
baseJavaCmd = String.format("java %s %s", String.format("-Dlogback.configurationFile=%s", logbackXmlFile), String.format("-Drsk.conf.file=%s", rskConfFile));
}

@Test
void whenParallelizableTransactionsAreSent_someAreExecutedInParallel() throws Exception {

// Given

// Pre-funded Test Accounts on Regtest
List<String> accounts = Arrays.asList(
"0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826",
"0x7986b3df570230288501eea3d890bd66948c9b79",
"0x0a3aa774752ec2042c46548456c094a76c7f3a79",
"0xcf7cdbbb5f7ba79d3ffe74a0bba13fc0295f6036",
"0x39b12c05e8503356e3a7df0b7b33efa4c054c409",
"0xc354d97642faa06781b76ffb6786f72cd7746c97",
"0xdebe71e1de41fc77c44df4b6db940026e31b0e71",
"0x7857288e171c6159c5576d1bd9ac40c0c48a771c",
"0xa4dea4d5c954f5fd9e87f0e9752911e83a3d18b3",
"0x09a1eda29f664ac8f68106f6567276df0c65d859",
"0xec4ddeb4380ad69b3e509baad9f158cdf4e4681d"
);

Map<String, Response> txResponseMap = new HashMap<>();
Map<String, Map<Integer, String>> blocksResponseMap = new HashMap<>();

String cmd = String.format(
"%s -cp %s/%s co.rsk.Start --reset %s",
baseJavaCmd,
buildLibsPath,
jarName,
strBaseArgs);

// When

CommandLineFixture.runCommand(
cmd,
1,
TimeUnit.MINUTES,
proc -> {
try {

// Send bulk transactions

Response txResponse = sendBulkTransactions(
accounts.get(0), accounts.get(1), accounts.get(2), accounts.get(3),
accounts.get(4), accounts.get(5), accounts.get(6), accounts.get(7));

txResponseMap.put("bulkTransactionsResponse", txResponse);

// Await for n blocks to be mined and return them

Future<Map<Integer, String>> future = getBlocksAsync();

try {

blocksResponseMap.put("asyncBlocksResult", future.get());

} catch (ExecutionException | InterruptedException e) {
Assertions.fail(e);
}

} catch (IOException e) {
Assertions.fail(e);
}
}
);

// Then

Assertions.assertEquals(200, txResponseMap.get("bulkTransactionsResponse").code());

Map<Integer, String> blocksResult = blocksResponseMap.get("asyncBlocksResult");
Assertions.assertEquals(MAX_BLOCKS_TO_GET, blocksResult.size());

boolean pteFound = false;
int i = blocksResult.size(); // Start from the last element (optimization)
while (!pteFound && i >= 0) {
i -= 1;

JsonNode blockResponse = objectMapper.readTree(blocksResult.get(i));
JsonNode result = blockResponse.get(0).get("result");

if (!result.isNull()) {
JsonNode pteEdges = result.get("rskPteEdges");
if (pteEdges.isArray() && pteEdges.size() > 0) {
Assertions.assertTrue(result.get("transactions").isArray());
Assertions.assertTrue(result.get("transactions").size() > 1);
pteFound = true;
}
}
}

Assertions.assertTrue(pteFound);

}

private Response getBlockByNumber(String number) throws IOException {
String content = getEnvelopedMethodCalls(
ETH_GET_BLOCK_BY_NUMBER.replace(
"<BLOCK_NUM_OR_TAG>",
number)
);

System.out.println(content);

return OkHttpClientTestFixture.sendJsonRpcMessage(content, RPC_PORT);
}

private Response sendBulkTransactions(
String addressFrom1, String addressTo1,
String addressFrom2, String addressTo2,
String addressFrom3, String addressTo3,
String addressFrom4, String addressTo4) throws IOException {

String gas = "0x9C40";
String gasPrice = "0x10";
String value = "0x500";

String[] placeholders = new String[]{
"<ADDRESS_FROM>", "<ADDRESS_TO>", "<GAS>",
"<GAS_PRICE>", "<VALUE>"
};

String content = getEnvelopedMethodCalls(
StringUtils.replaceEach(ETH_SEND_TRANSACTION, placeholders,
new String[]{addressFrom1, addressTo1, gas, gasPrice, value}),
StringUtils.replaceEach(ETH_SEND_TRANSACTION, placeholders,
new String[]{addressFrom2, addressTo2, gas, gasPrice, value}),
StringUtils.replaceEach(ETH_SEND_TRANSACTION, placeholders,
new String[]{addressFrom3, addressTo3, gas, gasPrice, value}),
StringUtils.replaceEach(ETH_SEND_TRANSACTION, placeholders,
new String[]{addressFrom4, addressTo4, gas, gasPrice, value})
);

System.out.println(content);

return OkHttpClientTestFixture.sendJsonRpcMessage(content, RPC_PORT);
}

private Future<Map<Integer, String>> getBlocksAsync() {
CompletableFuture<Map<Integer, String>> completableFuture = new CompletableFuture<>();

Executors.newCachedThreadPool().submit(() -> {
Map<Integer, String> results = new HashMap<>();

for (int i = 0; i < MAX_BLOCKS_TO_GET; i++) {
String response = getBlockByNumber("0x" + String.format("%02x", i)).body().string();

results.put(i, response);
Thread.sleep(500);
}

completableFuture.complete(results);
return null;
});

return completableFuture;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
miner {

server {
enabled = true
updateWorkOnNewTransaction = true
}

client {
enabled = true
automine = false
delayBetweenBlocks = 5 seconds
delayBetweenRefreshes = 1 second
}

}

peer {

discovery = {

# if peer discovery is off
# the peer window will show
# only what retrieved by active
# peer [true/false]
enabled = false

# List of the peers to start
# the search of the online peers
# values: [ip:port]
ip.list = []

}

}
9 changes: 5 additions & 4 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ public synchronized BlockExecutor getBlockExecutor() {

if (blockExecutor == null) {
blockExecutor = new BlockExecutor(
getRskSystemProperties().getActivationConfig(),
getRepositoryLocator(),
getTransactionExecutorFactory()
getTransactionExecutorFactory(),
getRskSystemProperties()
);
}

Expand Down Expand Up @@ -1093,7 +1093,7 @@ public synchronized BlockValidationRule getBlockValidationRule() {
rskSystemProperties.getActivationConfig(),
rskSystemProperties.getNetworkConstants()
);
blockValidationRule = new BlockValidatorRule(
blockValidationRule = new BlockCompositeRule(
new TxsMinGasPriceRule(),
new BlockTxsMaxGasPriceRule(rskSystemProperties.getActivationConfig()),
new BlockUnclesValidationRule(
Expand All @@ -1120,7 +1120,8 @@ public synchronized BlockValidationRule getBlockValidationRule() {
blockTimeStampValidationRule,
new GasLimitRule(commonConstants.getMinGasLimit()),
new ExtraDataRule(commonConstants.getMaximumExtraDataSize()),
getForkDetectionDataRule()
getForkDetectionDataRule(),
new ValidTxExecutionSublistsEdgesRule(getRskSystemProperties().getActivationConfig())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void executeBlocks(BlockExecutor blockExecutor, BlockStore blockStore, T
Block block = blockStore.getChainBlockByNumber(n);
Block parent = blockStore.getBlockByHash(block.getParentHash().getBytes());

BlockResult blockResult = blockExecutor.execute(block, parent.getHeader(), false, false, true);
BlockResult blockResult = blockExecutor.execute(null, 0, block, parent.getHeader(), false, false, true);

Keccak256 stateRootHash = stateRootHandler.translate(block.getHeader());
if (!Arrays.equals(blockResult.getFinalState().getHash().getBytes(), stateRootHash.getBytes())) {
Expand Down
Loading
Loading