diff --git a/CHANGELOG.md b/CHANGELOG.md index 927fbf2f90d..0275bd837a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ ### Additions and Improvements - Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) +- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211) +- Set Ethereum Classic mainnet activation block for Spiral network upgrade [#6267](https://github.com/hyperledger/besu/pull/6267) +- Add custom genesis file name to config overview if specified [#6297](https://github.com/hyperledger/besu/pull/6297) +- Update Gradle plugins and replace unmaintained License Gradle Plugin with the actively maintained Gradle License Report [#6275](https://github.com/hyperledger/besu/pull/6275) ### Bug fixes diff --git a/acceptance-tests/test-plugins/build.gradle b/acceptance-tests/test-plugins/build.gradle index f9e960b4944..c31175cee8f 100644 --- a/acceptance-tests/test-plugins/build.gradle +++ b/acceptance-tests/test-plugins/build.gradle @@ -11,7 +11,6 @@ dependencies { implementation 'com.google.auto.service:auto-service' implementation 'info.picocli:picocli' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java b/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java index 5fd73b66b8f..57797462739 100644 --- a/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java +++ b/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java @@ -29,13 +29,13 @@ import org.assertj.core.api.Assertions; import org.assertj.core.api.ThrowableAssert; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class BesuPluginContextImplTest { - @BeforeClass + @BeforeAll public static void createFakePluginDir() throws IOException { if (System.getProperty("besu.plugins.dir") == null) { final Path pluginDir = Files.createTempDirectory("besuTest"); @@ -44,7 +44,7 @@ public static void createFakePluginDir() throws IOException { } } - @After + @AfterEach public void clearTestPluginState() { System.clearProperty("testPicoCLIPlugin.testOption"); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java index 5c4b58ec019..a407b389e44 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java @@ -43,15 +43,8 @@ import org.apache.commons.compress.utils.IOUtils; public class AbstractPreexistingNodeTest extends AcceptanceTestBase { - protected final String testName; - protected final String dataPath; protected Path hostDataPath; - public AbstractPreexistingNodeTest(final String testName, final String dataPath) { - this.testName = testName; - this.dataPath = dataPath; - } - protected static void extract(final Path path, final String destDirectory) throws IOException { try (final TarArchiveInputStream fin = new TarArchiveInputStream( diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java index e0276842f06..1c1f0c33b68 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java @@ -21,7 +21,7 @@ import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LoggingTest extends AcceptanceTestBase { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java index 5136cc64ab3..aa58ffb2fdf 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java @@ -29,7 +29,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder; -import java.io.IOException; import java.math.BigInteger; import java.net.URL; import java.nio.file.Files; @@ -37,64 +36,42 @@ import java.nio.file.Paths; import java.util.List; import java.util.function.UnaryOperator; +import java.util.stream.Stream; import javax.annotation.Nonnull; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class BackupRoundTripAcceptanceTest extends AbstractPreexistingNodeTest { - private final Path backupPath; - private final Path restorePath; - private final Path rebackupPath; - - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final List testAccounts; - - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final long expectedChainHeight; + private Path backupPath; + private Path restorePath; + private Path rebackupPath; + + public static Stream getParameters() { + // First 10 blocks of ropsten + return Stream.of( + Arguments.of( + "After versioning was enabled and using multiple RocksDB columns", + "version1", + 0xA, + singletonList( + new AccountData( + "0xd1aeb42885a43b72b518182ef893125814811048", + BigInteger.valueOf(0xA), + Wei.fromHexString("0x2B5E3AF16B1880000"))))); + } - public BackupRoundTripAcceptanceTest( - final String testName, - final String dataPath, - final long expectedChainHeight, - final List testAccounts) - throws IOException { - super(testName, dataPath); - this.expectedChainHeight = expectedChainHeight; - this.testAccounts = testAccounts; + public void setUp(final String testName, final String dataPath) throws Exception { backupPath = Files.createTempDirectory("backup"); backupPath.toFile().deleteOnExit(); restorePath = Files.createTempDirectory("restore"); restorePath.toFile().deleteOnExit(); rebackupPath = Files.createTempDirectory("rebackup"); rebackupPath.toFile().deleteOnExit(); - } - @Parameters(name = "{0}") - public static Object[][] getParameters() { - return new Object[][] { - // First 10 blocks of ropsten - new Object[] { - "After versioning was enabled and using multiple RocksDB columns", - "version1", - 0xA, - singletonList( - new AccountData( - "0xd1aeb42885a43b72b518182ef893125814811048", - BigInteger.valueOf(0xA), - Wei.fromHexString("0x2B5E3AF16B1880000"))) - } - }; - } - - @Before - public void setUp() throws Exception { final URL rootURL = DatabaseMigrationAcceptanceTest.class.getResource(dataPath); hostDataPath = copyDataDir(rootURL); final Path databaseArchive = @@ -105,8 +82,16 @@ public void setUp() throws Exception { extract(databaseArchive, hostDataPath.toAbsolutePath().toString()); } - @Test - public void backupRoundtripAndBack() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void backupRoundtripAndBack( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + + setUp(testName, dataPath); // backup from existing files final BesuNode backupNode = diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java index c4c9e42671c..e7ad04dc594 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java @@ -17,15 +17,15 @@ import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterAcceptanceTest extends AcceptanceTestBase { private Node minerNode; private Node fullNode; - @Before + @BeforeEach public void setUp() throws Exception { minerNode = besu.createMinerNode("node1"); fullNode = besu.createArchiveNode("node2"); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java index 6c7c8127997..3a7da4f4768 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterNoDiscoveryAcceptanceTest extends AcceptanceTestBase { @@ -29,7 +29,7 @@ public class ClusterNoDiscoveryAcceptanceTest extends AcceptanceTestBase { private Node noDiscoveryNode; private Cluster noDiscoveryCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java index 805749a0bf8..8fbd0d3d625 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java @@ -23,15 +23,15 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterThreadNodeRunnerAcceptanceTest extends AcceptanceTestBase { private Node fullNode; private Cluster noDiscoveryCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java index aa71839b181..67a9bf2754f 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java @@ -20,14 +20,14 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class P2pDisabledAcceptanceTest extends AcceptanceTestBase { private Node node; private Cluster p2pDisabledCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java index 1f28a4a9f3c..0ce5ea02b13 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java @@ -20,15 +20,15 @@ import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class StaticNodesAcceptanceTest extends AcceptanceTestBase { private Node otherNode; private Node node; - @Before + @BeforeEach public void setUp() throws Exception { otherNode = besu.createNodeWithNoDiscovery("other-node"); cluster.start(otherNode); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java index 1ad2587ded3..616afc19669 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java @@ -29,9 +29,9 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BootNodesGenesisSetupTest extends AcceptanceTestBase { private static final String CURVE_NAME = "secp256k1"; @@ -42,13 +42,13 @@ public class BootNodesGenesisSetupTest extends AcceptanceTestBase { private Node nodeA; private Node nodeB; - @BeforeClass + @BeforeAll public static void environment() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); } - @Before + @BeforeEach public void setUp() throws Exception { int nodeAP2pBindingPort; int nodeBP2pBindingPort; diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java index 8b4ef9f864b..7164de0b7aa 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java @@ -32,8 +32,8 @@ import java.util.List; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256R1AcceptanceTest extends AcceptanceTestBase { private Node minerNode; @@ -49,7 +49,7 @@ public class SECP256R1AcceptanceTest extends AcceptanceTestBase { private static final SECP256R1 SECP256R1_SIGNATURE_ALGORITHM = new SECP256R1(); - @Before + @BeforeEach public void setUp() throws Exception { KeyPair minerNodeKeyPair = createKeyPair(MINER_NODE_PRIVATE_KEY); KeyPair otherNodeKeyPair = createKeyPair(OTHER_NODE_PRIVATE_KEY); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java index 291506498ba..b2166a1cc58 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java @@ -28,49 +28,31 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class DatabaseMigrationAcceptanceTest extends org.hyperledger.besu.tests.acceptance.AbstractPreexistingNodeTest { - private final long expectedChainHeight; private BesuNode node; - private final List testAccounts; - public DatabaseMigrationAcceptanceTest( - final String testName, - final String dataPath, - final long expectedChainHeight, - final List testAccounts) { - super(testName, dataPath); - this.expectedChainHeight = expectedChainHeight; - this.testAccounts = testAccounts; + public static Stream getParameters() { + // First 10 blocks of ropsten + return Stream.of( + Arguments.of( + "After versioning was enabled and using multiple RocksDB columns", + "version1", + 0xA, + singletonList( + new AccountData( + "0xd1aeb42885a43b72b518182ef893125814811048", + BigInteger.valueOf(0xA), + Wei.fromHexString("0x2B5E3AF16B1880000"))))); } - @Parameters(name = "{0}") - public static Object[][] getParameters() { - return new Object[][] { - // First 10 blocks of ropsten - new Object[] { - "After versioning was enabled and using multiple RocksDB columns", - "version1", - 0xA, - singletonList( - new AccountData( - "0xd1aeb42885a43b72b518182ef893125814811048", - BigInteger.valueOf(0xA), - Wei.fromHexString("0x2B5E3AF16B1880000"))) - } - }; - } - - @Before - public void setUp() throws Exception { + public void setUp(final String testName, final String dataPath) throws Exception { final URL rootURL = DatabaseMigrationAcceptanceTest.class.getResource(dataPath); hostDataPath = copyDataDir(rootURL); final Path databaseArchive = @@ -83,13 +65,27 @@ public void setUp() throws Exception { cluster.start(node); } - @Test - public void shouldReturnCorrectBlockHeight() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void shouldReturnCorrectBlockHeight( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + setUp(testName, dataPath); blockchain.currentHeight(expectedChainHeight).verify(node); } - @Test - public void shouldReturnCorrectAccountBalance() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void shouldReturnCorrectAccountBalance( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + setUp(testName, dataPath); testAccounts.forEach( accountData -> accounts diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java index 508fb891c0e..86b037c1578 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java @@ -30,7 +30,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; -import java.util.stream.Collectors; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -40,10 +40,12 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; abstract class AbstractJsonRpcTest { - private static final MediaType MEDIA_TYPE_JSON = + protected static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); static class JsonRpcTestsContext { @@ -69,16 +71,14 @@ public void tearDown() { } private final JsonRpcTestsContext testsContext; - private final URI testCaseFileURI; - public AbstractJsonRpcTest( - final String ignored, final JsonRpcTestsContext testsContext, final URI testCaseFileURI) { - this.testCaseFileURI = testCaseFileURI; + public AbstractJsonRpcTest(final JsonRpcTestsContext testsContext) { this.testsContext = testsContext; } - @Test - public void test() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("testCases") + public void test(final URI testCaseFileURI) throws IOException { final JsonRpcTestCase testCase = testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class); @@ -118,7 +118,7 @@ protected void evaluateResponse( final JsonRpcTestCase testCase, final URL url) {} - private String getRpcUrl(final String rpcMethod) { + protected String getRpcUrl(final String rpcMethod) { if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) { return testsContext.besuNode.engineRpcUrl().get(); } @@ -126,14 +126,12 @@ private String getRpcUrl(final String rpcMethod) { return testsContext.besuNode.jsonRpcBaseUrl().get(); } - public static Iterable testCases(final String testCasesPath) throws URISyntaxException { + public static Stream testCasesFromPath(final String testCasesPath) + throws URISyntaxException { final File[] testCasesList = new File(AbstractJsonRpcTest.class.getResource(testCasesPath).toURI()).listFiles(); - return Arrays.stream(testCasesList) - .sorted() - .map(file -> new Object[] {file.getName(), file.toURI()}) - .collect(Collectors.toList()); + return Arrays.stream(testCasesList).sorted().map(File::toURI).map(Arguments::of); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java index 0b6f76f4de2..aa8547d83bb 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class DebugReplayBlockAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/debug/replayBlock/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/debug/replayBlock/test-cases/"; private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext; - public DebugReplayBlockAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public DebugReplayBlockAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java index b4db91a39aa..4a2b956efcd 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class DebugSetHeadAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/debug/setHead/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/debug/setHead/test-cases/"; private static JsonRpcTestsContext testsContext; - public DebugSetHeadAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public DebugSetHeadAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java index b8b4e2e45f4..5326c5763cb 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java @@ -28,8 +28,8 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase { @@ -38,7 +38,7 @@ public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase { List> testCase = new ArrayList<>(); - @Before + @BeforeEach public void setUp() throws Exception { node = besu.createMinerNode( diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java index f50e6c4a3bf..e795ee27abc 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java @@ -15,15 +15,13 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class EthGetBlockByNumberAndHashShanghaiAcceptanceTest extends AbstractJsonRpcTest { private static final String TEST_RESOURCES_DIR = "/jsonrpc/eth/getBlockBy/"; private static final String GENESIS_FILE = TEST_RESOURCES_DIR + "genesis.json"; @@ -31,22 +29,20 @@ public class EthGetBlockByNumberAndHashShanghaiAcceptanceTest extends AbstractJs private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext; - public EthGetBlockByNumberAndHashShanghaiAcceptanceTest( - final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public EthGetBlockByNumberAndHashShanghaiAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java index 7fe498e4c94..a9acdd14c5b 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java @@ -19,39 +19,35 @@ import org.hyperledger.besu.tests.acceptance.dsl.rpc.JsonRpcTestCase; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.node.ObjectNode; import okhttp3.Call; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineCancunBlockBuildingAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/cancun/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/cancun/test-cases/block-production"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineCancunBlockBuildingAcceptanceTest( - final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineCancunBlockBuildingAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } @Override @@ -90,7 +86,7 @@ protected void evaluateResponse( } } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java index d1771ac5990..e77f011d9b4 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineEip6110AcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/eip6110/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/eip6110/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineEip6110AcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineEip6110AcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java index c6cb8a62ea4..e7cb8a9150e 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineParisAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/paris/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/paris/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineParisAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineParisAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java index c676af5922b..85f966e3d2d 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java @@ -15,36 +15,32 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineShanghaiAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/shanghai/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/shanghai/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineShanghaiAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineShanghaiAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws Exception { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java index c13c195cb33..b1887303ba2 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java @@ -29,8 +29,8 @@ import java.util.Collections; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.web3j.protocol.Web3j; import org.web3j.protocol.core.Request; import org.web3j.protocol.core.methods.response.NetVersion; @@ -41,7 +41,7 @@ public class Web3JSupportAcceptanceTest extends AcceptanceTestBase { private Node node; private Path socketPath; - @Before + @BeforeEach public void setUp() throws Exception { socketPath = Files.createTempFile("besu-test-", ".ipc"); node = diff --git a/besu/build.gradle b/besu/build.gradle index fe5bb45c30d..0b31c4a43c2 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -99,10 +99,8 @@ dependencies { testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'org.mockito:mockito-junit-jupiter' testImplementation 'org.testcontainers:testcontainers' testImplementation 'tech.pegasys.discovery:discovery' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' annotationProcessor 'com.google.dagger:dagger-compiler' } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 9b3be817102..8131eda92dd 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -78,6 +78,7 @@ import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand; import org.hyperledger.besu.cli.subcommands.RetestethSubCommand; +import org.hyperledger.besu.cli.subcommands.TxParseSubCommand; import org.hyperledger.besu.cli.subcommands.ValidateConfigSubCommand; import org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand; import org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommand; @@ -145,7 +146,7 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.evm.precompile.AbstractAltBnPrecompiledContract; import org.hyperledger.besu.evm.precompile.BigIntegerModularExponentiationPrecompiledContract; import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract; @@ -1494,6 +1495,8 @@ private void addSubCommands(final InputStream in) { jsonBlockImporterFactory, rlpBlockExporterFactory, commandLine.getOut())); + commandLine.addSubcommand( + TxParseSubCommand.COMMAND_NAME, new TxParseSubCommand(commandLine.getOut())); commandLine.addSubcommand( PublicKeySubCommand.COMMAND_NAME, new PublicKeySubCommand(commandLine.getOut())); commandLine.addSubcommand( @@ -2121,8 +2124,6 @@ private void configure() throws Exception { instantiateSignatureAlgorithmFactory(); logger.info(generateConfigurationOverview()); - logger.info("Connecting to {} static nodes.", staticNodes.size()); - logger.trace("Static Nodes = {}", staticNodes); logger.info("Security Module: {}", securityModuleName); } @@ -3120,9 +3121,14 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) { if (listBootNodes != null) { if (!p2PDiscoveryOptionGroup.peerDiscoveryEnabled) { logger.warn("Discovery disabled: bootnodes will be ignored."); + } else { + logger.info("Configured {} bootnodes.", listBootNodes.size()); + logger.debug("Bootnodes = {}", listBootNodes); } DiscoveryConfiguration.assertValidBootnodes(listBootNodes); builder.setBootNodes(listBootNodes); + } else { + logger.info("0 Bootnodes configured"); } return builder.build(); } @@ -3225,7 +3231,11 @@ private Set loadStaticNodes() throws IOException { staticNodesPath = dataDir().resolve(staticNodesFilename); } logger.debug("Static Nodes file: {}", staticNodesPath); - return StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration()); + final Set staticNodes = + StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration()); + logger.info("Connecting to {} static nodes.", staticNodes.size()); + logger.debug("Static Nodes = {}", staticNodes); + return staticNodes; } private List buildEnodes( @@ -3237,7 +3247,7 @@ private List buildEnodes( } /** - * Besu CLI Paramaters exception handler used by VertX. Visible for testing. + * Besu CLI Parameters exception handler used by VertX. Visible for testing. * * @return instance of BesuParameterExceptionHandler */ @@ -3517,6 +3527,9 @@ private String generateConfigurationOverview() { } builder.setHasCustomGenesis(genesisFile != null); + if (genesisFile != null) { + builder.setCustomGenesis(genesisFile.getAbsolutePath()); + } builder.setNetworkId(ethNetworkConfig.getNetworkId()); builder diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index 5ed209ca311..4fd870e99ce 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -42,6 +42,7 @@ public class ConfigurationOverviewBuilder { private String network; private BigInteger networkId; private boolean hasCustomGenesis; + private String customGenesisFileName; private String dataStorage; private String syncMode; private Integer rpcPort; @@ -98,6 +99,17 @@ public ConfigurationOverviewBuilder setHasCustomGenesis(final boolean hasCustomG return this; } + /** + * Sets location of custom genesis file specified. + * + * @param customGenesisFileName the filename of the custom genesis file, only set if specified + * @return the builder + */ + public ConfigurationOverviewBuilder setCustomGenesis(final String customGenesisFileName) { + this.customGenesisFileName = customGenesisFileName; + return this; + } + /** * Sets data storage. * @@ -269,7 +281,9 @@ public String build() { } if (hasCustomGenesis) { - lines.add("Network: Custom genesis file specified"); + lines.add("Network: Custom genesis file"); + lines.add( + customGenesisFileName == null ? "Custom genesis file is null" : customGenesisFileName); } if (networkId != null) { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java index 3b34c4d2a61..0b6718387b1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMAT_HELP; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.cli.converter.FractionConverter; @@ -171,10 +172,10 @@ static class Layered { @CommandLine.ArgGroup( validate = false, - heading = "@|bold Tx Pool Legacy Implementation Options|@%n") - private final Legacy legacyOptions = new Legacy(); + heading = "@|bold Tx Pool Sequenced Implementation Options|@%n") + private final Sequenced sequencedOptions = new Sequenced(); - static class Legacy { + static class Sequenced { private static final String TX_POOL_RETENTION_HOURS = "--tx-pool-retention-hours"; private static final String TX_POOL_LIMIT_BY_ACCOUNT_PERCENTAGE = "--tx-pool-limit-by-account-percentage"; @@ -272,10 +273,10 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati config.getPendingTransactionsLayerMaxCapacityBytes(); options.layeredOptions.txPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); options.layeredOptions.txPoolMaxFutureBySender = config.getMaxFutureBySender(); - options.legacyOptions.txPoolLimitByAccountPercentage = + options.sequencedOptions.txPoolLimitByAccountPercentage = config.getTxPoolLimitByAccountPercentage(); - options.legacyOptions.txPoolMaxSize = config.getTxPoolMaxSize(); - options.legacyOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); + options.sequencedOptions.txPoolMaxSize = config.getTxPoolMaxSize(); + options.sequencedOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); options.unstableOptions.txMessageKeepAliveSeconds = config.getUnstable().getTxMessageKeepAliveSeconds(); options.unstableOptions.eth65TrxAnnouncedBufferingPeriod = @@ -295,14 +296,14 @@ public void validate( final CommandLine commandLine, final GenesisConfigOptions genesisConfigOptions) { CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", !txPoolImplementation.equals(LAYERED), - CommandLineUtils.getCLIOptionNames(Legacy.class)); + CommandLineUtils.getCLIOptionNames(Sequenced.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use layered transaction pool options with legacy implementation", - !txPoolImplementation.equals(LEGACY), + "Could not use layered transaction pool options with legacy or sequenced implementation", + !txPoolImplementation.equals(LEGACY) && !txPoolImplementation.equals(SEQUENCED), CommandLineUtils.getCLIOptionNames(Layered.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( @@ -327,9 +328,9 @@ public TransactionPoolConfiguration toDomainObject() { .pendingTransactionsLayerMaxCapacityBytes(layeredOptions.txPoolLayerMaxCapacity) .maxPrioritizedTransactions(layeredOptions.txPoolMaxPrioritized) .maxFutureBySender(layeredOptions.txPoolMaxFutureBySender) - .txPoolLimitByAccountPercentage(legacyOptions.txPoolLimitByAccountPercentage) - .txPoolMaxSize(legacyOptions.txPoolMaxSize) - .pendingTxRetentionPeriod(legacyOptions.pendingTxRetentionPeriod) + .txPoolLimitByAccountPercentage(sequencedOptions.txPoolLimitByAccountPercentage) + .txPoolMaxSize(sequencedOptions.txPoolMaxSize) + .pendingTxRetentionPeriod(sequencedOptions.pendingTxRetentionPeriod) .unstable( ImmutableTransactionPoolConfiguration.Unstable.builder() .txMessageKeepAliveSeconds(unstableOptions.txMessageKeepAliveSeconds) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java new file mode 100644 index 00000000000..221675c9dc5 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java @@ -0,0 +1,129 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.subcommands; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hyperledger.besu.cli.subcommands.TxParseSubCommand.COMMAND_NAME; + +import org.hyperledger.besu.cli.util.VersionProvider; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.ethereum.core.encoding.EncodingContext; +import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import org.apache.tuweni.bytes.Bytes; +import picocli.CommandLine; + +/** + * txparse sub command implementing txparse spec from + * https://github.com/holiman/txparse/tree/main/cmd/txparse + */ +@CommandLine.Command( + name = COMMAND_NAME, + description = "Parse input transactions and return the sender, or an error.", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class) +public class TxParseSubCommand implements Runnable { + + /** The constant COMMAND_NAME. */ + public static final String COMMAND_NAME = "txparse"; + + @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. + @CommandLine.Option( + names = "--corpus-file", + arity = "1..1", + description = "file to read transaction data lines from, otherwise defaults to stdin") + private String corpusFile = null; + + static final BigInteger halfCurveOrder = + SignatureAlgorithmFactory.getInstance().getHalfCurveOrder(); + static final BigInteger chainId = new BigInteger("1", 10); + + private final PrintWriter out; + + /** + * Instantiates a new TxParse sub command. + * + * @param out the PrintWriter where validation results will be reported. + */ + public TxParseSubCommand(final PrintWriter out) { + this.out = out; + } + + @SuppressWarnings("StreamResourceLeak") + Stream fileStreamReader(final String filePath) { + try { + return Files.lines(Paths.get(filePath)) + // skip comments + .filter(line -> !line.startsWith("#")) + // strip out non-alphanumeric characters + .map(line -> line.replaceAll("[^a-zA-Z0-9]", "")); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void run() { + + Stream txStream; + if (corpusFile != null) { + txStream = fileStreamReader(corpusFile); + } else { + txStream = new BufferedReader(new InputStreamReader(System.in, UTF_8)).lines(); + } + + txStream.forEach( + line -> { + try { + Bytes bytes = Bytes.fromHexStringLenient(line); + dump(bytes); + } catch (Exception ex) { + err(ex.getMessage()); + } + }); + } + + void dump(final Bytes tx) { + try { + var transaction = TransactionDecoder.decodeOpaqueBytes(tx, EncodingContext.BLOCK_BODY); + + // https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L252 + if (transaction.getChainId().isPresent() && !transaction.getChainId().get().equals(chainId)) { + throw new Exception("wrong chain id"); + } + + // https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L270 + if (transaction.getS().compareTo(halfCurveOrder) > 0) { + throw new Exception("signature s out of range"); + } + out.println(transaction.getSender()); + + } catch (Exception ex) { + err(ex.getMessage()); + } + } + + void err(final String message) { + out.println("err: " + message); + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/BackupState.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/BackupState.java index 0c5c4c0e32e..401b824d5e3 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/BackupState.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/BackupState.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.api.query.StateBackupService.BackupStatus; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -82,7 +82,7 @@ public void run() { final BesuController besuController = createBesuController(); final MutableBlockchain blockchain = besuController.getProtocolContext().getBlockchain(); final WorldStateStorage worldStateStorage = - ((DefaultWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive()) + ((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive()) .getWorldStateStorage(); final EthScheduler scheduler = new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()); try { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java index 47452b6eb32..a4b36bd5a6e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.trie.Node; import org.hyperledger.besu.ethereum.trie.PersistVisitor; import org.hyperledger.besu.ethereum.trie.RestoreVisitor; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.util.io.RollingFileReader; @@ -250,7 +250,7 @@ private void newWorldStateUpdater() { updater.commit(); } final WorldStateStorage worldStateStorage = - ((DefaultWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive()) + ((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive()) .getWorldStateStorage(); updater = worldStateStorage.updater(); } diff --git a/besu/src/main/java/org/hyperledger/besu/components/BesuComponent.java b/besu/src/main/java/org/hyperledger/besu/components/BesuComponent.java index 0edc5f15e4b..f0093243a6c 100644 --- a/besu/src/main/java/org/hyperledger/besu/components/BesuComponent.java +++ b/besu/src/main/java/org/hyperledger/besu/components/BesuComponent.java @@ -17,10 +17,10 @@ package org.hyperledger.besu.components; import org.hyperledger.besu.cli.BesuCommand; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoaderModule; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoaderModule; import org.hyperledger.besu.metrics.MetricsSystemModule; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.services.BesuPluginContextImpl; diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 643aed546cb..92cbf320e84 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -31,10 +31,6 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.chain.ChainDataPruner; @@ -84,12 +80,16 @@ import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.pruner.MarkSweepPruner; +import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; -import org.hyperledger.besu.ethereum.worldstate.MarkSweepPruner; -import org.hyperledger.besu.ethereum.worldstate.Pruner; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -657,7 +657,7 @@ public BesuController build() { Optional.of( new Pruner( new MarkSweepPruner( - ((DefaultWorldStateArchive) worldStateArchive).getWorldStateStorage(), + ((ForestWorldStateArchive) worldStateArchive).getWorldStateStorage(), blockchain, storageProvider.getStorageBySegmentIdentifier( KeyValueSegmentIdentifier.PRUNING_STATE), @@ -1093,7 +1093,7 @@ yield new BonsaiWorldStateProvider( case FOREST -> { final WorldStatePreimageStorage preimageStorage = storageProvider.createWorldStatePreimageStorage(); - yield new DefaultWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration); + yield new ForestWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration); } }; } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 921289c66e5..1d9356f5c76 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -56,8 +56,8 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration; import org.hyperledger.besu.ethereum.storage.StorageProvider; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 8231f8e26a5..65aadd46c63 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -52,9 +52,9 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.storage.StorageProvider; +import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.Pruner; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index 5bc1c30bd61..7a83cd87515 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -147,8 +147,9 @@ public static Collection parameters() { new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L), new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133), new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 14525000L), - new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L), - new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L)) + new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 19250000L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L)) }); } diff --git a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java index 89e1b255479..faa6bd34b95 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java @@ -46,29 +46,30 @@ import java.io.File; import java.io.IOException; import java.math.BigInteger; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.junit.jupiter.MockitoExtension; /** Tests for {@link BlockExporter}. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public final class RlpBlockExporterTest { - @ClassRule public static final TemporaryFolder folder = new TemporaryFolder(); + @TempDir public static Path folder; private static Blockchain blockchain; private static long chainHead; private static ProtocolSchedule protocolSchedule; - @BeforeClass + @BeforeAll public static void setupBlockchain() throws IOException { - final BesuController controller = createController(); - final Path blocks = folder.newFile("1000.blocks").toPath(); + final BesuController controller = + createController(Files.createTempDirectory(folder, "rlpBlockExporterTestData")); + final Path blocks = Files.createTempFile(folder, "1000", "blocks"); BlockTestUtil.write1000Blocks(blocks); blockchain = importBlocks(controller, blocks); chainHead = blockchain.getChainHeadBlockNumber(); @@ -83,8 +84,7 @@ private static Blockchain importBlocks(final BesuController controller, final Pa return controller.getProtocolContext().getBlockchain(); } - private static BesuController createController() throws IOException { - final Path dataDir = folder.newFolder().toPath(); + private static BesuController createController(final @TempDir Path dataDir) throws IOException { return new BesuController.Builder() .fromGenesisConfig(GenesisConfigFile.mainnet(), SyncMode.FAST) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) @@ -105,13 +105,13 @@ private static BesuController createController() throws IOException { } @Test - public void exportBlocks_noBounds() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_noBounds(final @TempDir Path outputDir) throws IOException { + final Path outputPath = outputDir.resolve("output"); final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); - exporter.exportBlocks(outputPath, Optional.empty(), Optional.empty()); + exporter.exportBlocks(outputPath.toFile(), Optional.empty(), Optional.empty()); // Iterate over blocks and check that they match expectations - final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath()); + final RawBlockIterator blockIterator = getBlockIterator(outputPath); long currentBlockNumber = 0; while (blockIterator.hasNext()) { final Block actual = blockIterator.next(); @@ -125,15 +125,15 @@ public void exportBlocks_noBounds() throws IOException { } @Test - public void exportBlocks_withLowerBound() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_withLowerBound(final @TempDir Path outputDir) throws IOException { + final Path outputPath = outputDir.resolve("output"); final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); final long lowerBound = 990; - exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.empty()); + exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.empty()); // Iterate over blocks and check that they match expectations - final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath()); + final RawBlockIterator blockIterator = getBlockIterator(outputPath); long currentBlockNumber = lowerBound; while (blockIterator.hasNext()) { final Block actual = blockIterator.next(); @@ -147,15 +147,15 @@ public void exportBlocks_withLowerBound() throws IOException { } @Test - public void exportBlocks_withUpperBound() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_withUpperBound(final @TempDir Path outputDir) throws IOException { + final Path outputPath = outputDir.resolve("output"); final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); final long upperBound = 10; - exporter.exportBlocks(outputPath, Optional.empty(), Optional.of(upperBound)); + exporter.exportBlocks(outputPath.toFile(), Optional.empty(), Optional.of(upperBound)); // Iterate over blocks and check that they match expectations - final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath()); + final RawBlockIterator blockIterator = getBlockIterator(outputPath); long currentBlockNumber = 0; while (blockIterator.hasNext()) { final Block actual = blockIterator.next(); @@ -169,16 +169,17 @@ public void exportBlocks_withUpperBound() throws IOException { } @Test - public void exportBlocks_withUpperAndLowerBounds() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_withUpperAndLowerBounds(final @TempDir Path outputDir) + throws IOException { + final Path outputPath = outputDir.resolve("output"); final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); final long lowerBound = 5; final long upperBound = 10; - exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.of(upperBound)); + exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.of(upperBound)); // Iterate over blocks and check that they match expectations - final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath()); + final RawBlockIterator blockIterator = getBlockIterator(outputPath); long currentBlockNumber = lowerBound; while (blockIterator.hasNext()) { final Block actual = blockIterator.next(); @@ -192,16 +193,17 @@ public void exportBlocks_withUpperAndLowerBounds() throws IOException { } @Test - public void exportBlocks_withRangeBeyondChainHead() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_withRangeBeyondChainHead(final @TempDir Path outputDir) + throws IOException { + final Path outputPath = outputDir.resolve("output"); final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); final long lowerBound = chainHead - 10; final long upperBound = chainHead + 10; - exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.of(upperBound)); + exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.of(upperBound)); // Iterate over blocks and check that they match expectations - final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath()); + final RawBlockIterator blockIterator = getBlockIterator(outputPath); long currentBlockNumber = lowerBound; while (blockIterator.hasNext()) { final Block actual = blockIterator.next(); @@ -215,8 +217,7 @@ public void exportBlocks_withRangeBeyondChainHead() throws IOException { } @Test - public void exportBlocks_negativeStartNumber() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_negativeStartNumber(final @TempDir File outputPath) throws IOException { final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(-1L), Optional.empty())) @@ -225,8 +226,7 @@ public void exportBlocks_negativeStartNumber() throws IOException { } @Test - public void exportBlocks_negativeEndNumber() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_negativeEndNumber(final @TempDir File outputPath) throws IOException { final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.empty(), Optional.of(-1L))) @@ -235,8 +235,7 @@ public void exportBlocks_negativeEndNumber() throws IOException { } @Test - public void exportBlocks_outOfOrderBounds() throws IOException { - final File outputPath = folder.newFile(); + public void exportBlocks_outOfOrderBounds(final @TempDir File outputPath) throws IOException { final RlpBlockExporter exporter = new RlpBlockExporter(blockchain); assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(10L), Optional.of(2L))) diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java index 00ebc610823..4b59491dc18 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -48,29 +48,28 @@ import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.io.Resources; import org.apache.tuweni.bytes.Bytes; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; public abstract class JsonBlockImporterTest { - @Rule public final TemporaryFolder folder = new TemporaryFolder(); + @TempDir public Path dataDir; - protected final String consensusEngine; - protected final GenesisConfigFile genesisConfigFile; - protected final boolean isEthash; + protected String consensusEngine; + protected GenesisConfigFile genesisConfigFile; + protected boolean isEthash; - protected JsonBlockImporterTest(final String consensusEngine) throws IOException { + protected void setup(final String consensusEngine) throws IOException { this.consensusEngine = consensusEngine; final String genesisData = getFileContents("genesis.json"); this.genesisConfigFile = GenesisConfigFile.fromConfig(genesisData); @@ -78,8 +77,10 @@ protected JsonBlockImporterTest(final String consensusEngine) throws IOException } public static class SingletonTests extends JsonBlockImporterTest { - public SingletonTests() throws IOException { - super("unsupported"); + + @BeforeEach + public void setup() throws IOException { + super.setup("unsupported"); } @Test @@ -97,21 +98,23 @@ public void importChain_unsupportedConsensusAlgorithm() throws IOException { } } - @RunWith(Parameterized.class) public static class ParameterizedTests extends JsonBlockImporterTest { - public ParameterizedTests(final String consensusEngine) throws IOException { - super(consensusEngine); + @Override + public void setup(final String consensusEngine) throws IOException { + super.setup(consensusEngine); } - @Parameters(name = "Name: {0}") - public static Collection getParameters() { - final Object[][] params = {{"ethash"}, {"clique"}}; - return Arrays.asList(params); + public static Stream getParameters() { + return Stream.of(Arguments.of("ethash"), Arguments.of("clique")); } - @Test - public void importChain_validJson_withBlockNumbers() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_validJson_withBlockNumbers(final String consensusEngine) + throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -201,8 +204,12 @@ public void importChain_validJson_withBlockNumbers() throws IOException { assertThat(tx.getNonce()).isEqualTo(1L); } - @Test - public void importChain_validJson_noBlockIdentifiers() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_validJson_noBlockIdentifiers(final String consensusEngine) + throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -292,8 +299,12 @@ public void importChain_validJson_noBlockIdentifiers() throws IOException { assertThat(tx.getNonce()).isEqualTo(1L); } - @Test - public void importChain_validJson_withParentHashes() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_validJson_withParentHashes(final String consensusEngine) + throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -343,8 +354,11 @@ public void importChain_validJson_withParentHashes() throws IOException { assertThat(tx.getNonce()).isEqualTo(2L); } - @Test - public void importChain_invalidParent() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_invalidParent(final String consensusEngine) throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -355,8 +369,11 @@ public void importChain_invalidParent() throws IOException { .hasMessageStartingWith("Unable to locate block parent at 2456"); } - @Test - public void importChain_invalidTransaction() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_invalidTransaction(final String consensusEngine) throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -368,8 +385,11 @@ public void importChain_invalidTransaction() throws IOException { "Unable to create block. 1 transaction(s) were found to be invalid."); } - @Test - public void importChain_specialFields() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void importChain_specialFields(final String consensusEngine) throws IOException { + setup(consensusEngine); + final BesuController controller = createController(); final JsonBlockImporter importer = new JsonBlockImporter(controller); @@ -414,7 +434,6 @@ protected BesuController createController() throws IOException { protected BesuController createController(final GenesisConfigFile genesisConfigFile) throws IOException { - final Path dataDir = folder.newFolder().toPath(); return new BesuController.Builder() .fromGenesisConfig(genesisConfigFile, SyncMode.FAST) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 955c9df7aaf..3db626287fa 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -83,8 +83,8 @@ import org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration; import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration; import org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.evm.precompile.AbstractAltBnPrecompiledContract; import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract; import org.hyperledger.besu.metrics.StandardMetricCategory; @@ -127,19 +127,18 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.toml.Toml; import org.apache.tuweni.toml.TomlParseResult; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuCommandTest extends CommandTestAbstract { private static final String ENCLAVE_URI = "http://1.2.3.4:5555"; @@ -198,7 +197,7 @@ public class BesuCommandTest extends CommandTestAbstract { DEFAULT_API_CONFIGURATION = ImmutableApiConfiguration.builder().build(); } - @Before + @BeforeEach public void setup() { try { // optimistically tear down a potential previous loaded trusted setup @@ -210,7 +209,7 @@ public void setup() { MergeConfigOptions.setMergeEnabled(false); } - @After + @AfterEach public void tearDown() { MergeConfigOptions.setMergeEnabled(false); @@ -366,10 +365,10 @@ public void callingWithConfigOptionButInvalidValueTomlFileShouldDisplayHelp() th } @Test - public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException { + public void overrideDefaultValuesIfKeyIsPresentInConfigFile(final @TempDir File dataFolder) + throws IOException { final URL configFile = this.getClass().getResource("/complete_config.toml"); final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); - final File dataFolder = temp.newFolder(); final String updatedConfig = Resources.toString(configFile, UTF_8) .replace("/opt/besu/genesis.json", escapeTomlString(genesisFile.toString())) @@ -3745,7 +3744,7 @@ public void colorCanBeEnabledOrDisabledExplicitly() { }); } - @Ignore + @Disabled public void pruningIsEnabledIfSyncModeIsFast() { parseCommand("--sync-mode", "FAST"); @@ -3756,7 +3755,7 @@ public void pruningIsEnabledIfSyncModeIsFast() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } - @Ignore + @Disabled public void pruningIsDisabledIfSyncModeIsFull() { parseCommand("--sync-mode", "FULL"); @@ -3778,7 +3777,7 @@ public void pruningEnabledExplicitly() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } - @Ignore + @Disabled public void pruningDisabledExplicitly() { parseCommand("--pruning-enabled=false", "--sync-mode=FAST"); @@ -4373,14 +4372,11 @@ public void privacyWithPruningMustError() { assertThat(commandOutput.toString(UTF_8)).isEmpty(); } - @Rule public TemporaryFolder testFolder = new TemporaryFolder(); - @Test - public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException { - final File staticNodesFile = testFolder.newFile("static-nodes.json"); - staticNodesFile.deleteOnExit(); - final File permissioningConfig = testFolder.newFile("permissioning"); - permissioningConfig.deleteOnExit(); + public void errorIsRaisedIfStaticNodesAreNotAllowed(final @TempDir Path testFolder) + throws IOException { + final Path staticNodesFile = testFolder.resolve("static-nodes.json"); + final Path permissioningConfig = testFolder.resolve("permissioning.json"); final EnodeURL staticNodeURI = EnodeURLImpl.builder() @@ -4399,17 +4395,16 @@ public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException { .listeningPort(30304) .build(); + Files.write(staticNodesFile, ("[\"" + staticNodeURI.toString() + "\"]").getBytes(UTF_8)); Files.write( - staticNodesFile.toPath(), ("[\"" + staticNodeURI.toString() + "\"]").getBytes(UTF_8)); - Files.write( - permissioningConfig.toPath(), + permissioningConfig, ("nodes-allowlist=[\"" + allowedNode.toString() + "\"]").getBytes(UTF_8)); parseCommand( - "--data-path=" + testFolder.getRoot().getPath(), + "--data-path=" + testFolder, "--bootnodes", "--permissions-nodes-config-file-enabled=true", - "--permissions-nodes-config-file=" + permissioningConfig.getPath()); + "--permissions-nodes-config-file=" + permissioningConfig); assertThat(commandErrorOutput.toString(UTF_8)) .contains(staticNodeURI.toString(), "not in nodes-allowlist"); } @@ -4985,12 +4980,10 @@ public void pkiBlockCreationPasswordFileRequired() { "File containing password to unlock keystore is required when PKI Block Creation is enabled"); } - @Rule public TemporaryFolder pkiTempFolder = new TemporaryFolder(); - @Test - public void pkiBlockCreationFullConfig() throws Exception { + public void pkiBlockCreationFullConfig(final @TempDir Path pkiTempFolder) throws Exception { // Create temp file with password - final File pwdFile = pkiTempFolder.newFile("pwd"); + final File pwdFile = pkiTempFolder.resolve("pwd").toFile(); FileUtils.writeStringToFile(pwdFile, "foo", UTF_8); parseCommand( diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandLineUtilsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandLineUtilsTest.java index f8bc8d8972d..726bf38965e 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandLineUtilsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandLineUtilsTest.java @@ -35,18 +35,18 @@ import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.RunLast; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CommandLineUtilsTest { @SuppressWarnings("PrivateStaticFinalLoggers") // @Mocks are inited by JUnit @Mock diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index 8597c0582df..e9d8d559641 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -112,22 +112,20 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.awaitility.Awaitility; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.RunLast; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class CommandTestAbstract { private static final Logger TEST_LOGGER = LoggerFactory.getLogger(CommandTestAbstract.class); protected static final JsonObject VALID_GENESIS_QBFT_POST_LONDON = @@ -156,17 +154,30 @@ public abstract class CommandTestAbstract { protected static final RpcEndpointServiceImpl rpcEndpointServiceImpl = new RpcEndpointServiceImpl(); - @Mock protected RunnerBuilder mockRunnerBuilder; + @Mock(lenient = true) + protected RunnerBuilder mockRunnerBuilder; + @Mock protected Runner mockRunner; - @Mock protected BesuController.Builder mockControllerBuilderFactory; + @Mock(lenient = true) + protected BesuController.Builder mockControllerBuilderFactory; + + @Mock(lenient = true) + protected BesuControllerBuilder mockControllerBuilder; + + @Mock(lenient = true) + protected EthProtocolManager mockEthProtocolManager; - @Mock protected BesuControllerBuilder mockControllerBuilder; - @Mock protected EthProtocolManager mockEthProtocolManager; @Mock protected ProtocolSchedule mockProtocolSchedule; - @Mock protected ProtocolContext mockProtocolContext; + + @Mock(lenient = true) + protected ProtocolContext mockProtocolContext; + @Mock protected BlockBroadcaster mockBlockBroadcaster; - @Mock protected BesuController mockController; + + @Mock(lenient = true) + protected BesuController mockController; + @Mock protected RlpBlockExporter rlpBlockExporter; @Mock protected JsonBlockImporter jsonBlockImporter; @Mock protected RlpBlockImporter rlpBlockImporter; @@ -188,7 +199,8 @@ public abstract class CommandTestAbstract { @Mock protected Logger mockLogger; - @Mock protected BesuComponent mockBesuComponent; + @Mock(lenient = true) + protected BesuComponent mockBesuComponent; @Mock protected PkiBlockCreationConfigurationProvider mockPkiBlockCreationConfigProvider; @Mock protected PkiBlockCreationConfiguration mockPkiBlockCreationConfiguration; @@ -218,9 +230,7 @@ public abstract class CommandTestAbstract { @Captor protected ArgumentCaptor ethstatsOptionsArgumentCaptor; - @Rule public final TemporaryFolder temp = new TemporaryFolder(); - - @Before + @BeforeEach public void initMocks() throws Exception { // doReturn used because of generic BesuController doReturn(mockControllerBuilder) @@ -353,7 +363,7 @@ public void initMocks() throws Exception { when(mockBesuComponent.getBesuCommandLogger()).thenReturn(mockLogger); } - @Before + @BeforeEach public void setUpStreams() { // reset the global opentelemetry singleton GlobalOpenTelemetry.resetForTest(); @@ -364,7 +374,7 @@ public void setUpStreams() { } // Display outputs for debug purpose - @After + @AfterEach public void displayOutput() throws IOException { TEST_LOGGER.info("Standard output {}", commandOutput.toString(UTF_8)); TEST_LOGGER.info("Standard error {}", commandErrorOutput.toString(UTF_8)); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java index 44718e96c67..eee55c3975b 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import static org.mockito.Mockito.mock; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -57,8 +58,9 @@ void setGenesisFile() { assertThat(networkSet).contains("Network: foobar"); builder.setHasCustomGenesis(true); + builder.setCustomGenesis("file.name"); final String genesisSet = builder.build(); - assertThat(genesisSet).contains("Network: Custom genesis file specified"); + assertThat(genesisSet).contains("Network: Custom genesis file"); assertThat(genesisSet).doesNotContain("Network: foobar"); } @@ -180,6 +182,13 @@ void setTxPoolImplementationLegacy() { assertThat(legacyTxPoolSelected).contains("Using LEGACY transaction pool implementation"); } + @Test + void setTxPoolImplementationSequenced() { + builder.setTxPoolImplementation(SEQUENCED); + final String sequencedTxPoolSelected = builder.build(); + assertThat(sequencedTxPoolSelected).contains("Using SEQUENCED transaction pool implementation"); + } + @Test void setWorldStateUpdateModeDefault() { builder.setWorldStateUpdateMode(EvmConfiguration.DEFAULT.worldUpdaterMode()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/EnvironmentVariableDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/EnvironmentVariableDefaultProviderTest.java index af609327340..9953ca519f7 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/EnvironmentVariableDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/EnvironmentVariableDefaultProviderTest.java @@ -21,13 +21,13 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.OptionSpec; import picocli.CommandLine.Model.PositionalParamSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EnvironmentVariableDefaultProviderTest { private final Map environment = new HashMap<>(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/PasswordSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/PasswordSubCommandTest.java index 62d35830c0b..5d661f92038 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/PasswordSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/PasswordSubCommandTest.java @@ -19,12 +19,12 @@ import org.hyperledger.besu.BesuInfo; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.CommandSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PasswordSubCommandTest extends CommandTestAbstract { @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/PublicKeySubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/PublicKeySubCommandTest.java index 3da574e8e32..d2ca00990a0 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/PublicKeySubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/PublicKeySubCommandTest.java @@ -35,14 +35,14 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.CommandSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PublicKeySubCommandTest extends CommandTestAbstract { private static final String EXPECTED_PUBLIC_KEY_USAGE = @@ -126,13 +126,13 @@ public class PublicKeySubCommandTest extends CommandTestAbstract { private static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; private static ECDomainParameters curve; - @BeforeClass + @BeforeAll public static void setUp() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); } - @Before + @BeforeEach public void before() { SignatureAlgorithmFactory.resetInstance(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java index 1481db9526d..5185a4133e3 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java @@ -26,31 +26,29 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.OptionSpec; import picocli.CommandLine.ParameterException; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TomlConfigFileDefaultProviderTest { @Mock CommandLine mockCommandLine; @Mock CommandSpec mockCommandSpec; - @Rule public final TemporaryFolder temp = new TemporaryFolder(); - @Test - public void defaultValueForMatchingKey() throws IOException { + public void defaultValueForMatchingKey(final @TempDir Path temp) throws IOException { when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); Map validOptionsMap = new HashMap<>(); validOptionsMap.put("--a-short-option", null); @@ -58,7 +56,7 @@ public void defaultValueForMatchingKey() throws IOException { validOptionsMap.put("--a-longer-option", null); when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8)) { @@ -106,7 +104,7 @@ public void defaultValueForMatchingKey() throws IOException { } @Test - public void defaultValueForOptionMustMatchType() throws IOException { + public void defaultValueForOptionMustMatchType(final @TempDir Path temp) throws IOException { when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); Map validOptionsMap = new HashMap<>(); validOptionsMap.put("--a-boolean-option", null); @@ -124,7 +122,7 @@ public void defaultValueForOptionMustMatchType() throws IOException { when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8)) { @@ -238,9 +236,9 @@ public void configFileNotFoundMustThrow() { } @Test - public void invalidConfigMustThrow() throws IOException { + public void invalidConfigMustThrow(final @TempDir Path temp) throws IOException { - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = Files.createTempFile("invalid", "toml").toFile(); final TomlConfigFileDefaultProvider providerUnderTest = new TomlConfigFileDefaultProvider(mockCommandLine, tempConfigFile); @@ -254,9 +252,9 @@ public void invalidConfigMustThrow() throws IOException { } @Test - public void invalidConfigContentMustThrow() throws IOException { + public void invalidConfigContentMustThrow(final @TempDir Path temp) throws IOException { - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8); fileWriter.write("an-invalid-syntax=======...."); @@ -276,13 +274,13 @@ public void invalidConfigContentMustThrow() throws IOException { } @Test - public void unknownOptionMustThrow() throws IOException { + public void unknownOptionMustThrow(final @TempDir Path temp) throws IOException { when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); Map validOptionsMap = new HashMap<>(); when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8); fileWriter.write("invalid_option=true"); @@ -300,7 +298,7 @@ public void unknownOptionMustThrow() throws IOException { } @Test - public void tomlTableHeadingsMustBeIgnored() throws IOException { + public void tomlTableHeadingsMustBeIgnored(final @TempDir Path temp) throws IOException { when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); @@ -310,7 +308,7 @@ public void tomlTableHeadingsMustBeIgnored() throws IOException { validOptionsMap.put("--onemore-valid-option", null); when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8); fileWriter.write("a-valid-option=123"); @@ -343,7 +341,8 @@ public void tomlTableHeadingsMustBeIgnored() throws IOException { } @Test - public void tomlTableHeadingsMustNotSkipValidationOfUnknownOptions() throws IOException { + public void tomlTableHeadingsMustNotSkipValidationOfUnknownOptions(final @TempDir Path temp) + throws IOException { when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); @@ -351,7 +350,7 @@ public void tomlTableHeadingsMustNotSkipValidationOfUnknownOptions() throws IOEx validOptionsMap.put("--a-valid-option", null); when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); - final File tempConfigFile = temp.newFile("config.toml"); + final File tempConfigFile = temp.resolve("config.toml").toFile(); final BufferedWriter fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8); fileWriter.write("[ignoreme]"); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/ValidateConfigSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/ValidateConfigSubCommandTest.java index dc8d0548e0c..ac6efbf405b 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/ValidateConfigSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/ValidateConfigSubCommandTest.java @@ -25,12 +25,12 @@ import java.nio.file.Path; import com.google.common.io.Resources; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.CommandSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ValidateConfigSubCommandTest extends CommandTestAbstract { private static final String EXPECTED_PUBLIC_KEY_USAGE = diff --git a/besu/src/test/java/org/hyperledger/besu/cli/config/EthNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/cli/config/EthNetworkConfigTest.java index 66e8592b5e4..3bddc7724bc 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/config/EthNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/config/EthNetworkConfigTest.java @@ -23,11 +23,11 @@ import java.math.BigInteger; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EthNetworkConfigTest { @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/converter/FractionConverterTest.java b/besu/src/test/java/org/hyperledger/besu/cli/converter/FractionConverterTest.java index 611109274d5..74abdeef5ae 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/converter/FractionConverterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/converter/FractionConverterTest.java @@ -20,11 +20,11 @@ import org.hyperledger.besu.cli.converter.exception.FractionConversionException; import org.hyperledger.besu.util.number.Fraction; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FractionConverterTest { private final FractionConverter fractionConverter = new FractionConverter(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java b/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java index db34fb9d5e4..8c78b7fecc2 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java @@ -20,20 +20,20 @@ import org.hyperledger.besu.plugin.services.metrics.MetricCategory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MetricCategoryConverterTest { private MetricCategoryConverter metricCategoryConverter; @Mock MetricCategory metricCategory; - @Before + @BeforeEach public void setUp() { metricCategoryConverter = new MetricCategoryConverter(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/converter/PercentageConverterTest.java b/besu/src/test/java/org/hyperledger/besu/cli/converter/PercentageConverterTest.java index 829a4ef35f6..8ee5143c207 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/converter/PercentageConverterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/converter/PercentageConverterTest.java @@ -20,11 +20,11 @@ import org.hyperledger.besu.cli.converter.exception.PercentageConversionException; import org.hyperledger.besu.util.number.Percentage; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PercentageConverterTest { private final PercentageConverter percentageConverter = new PercentageConverter(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/custom/RpcAuthFileValidatorTest.java b/besu/src/test/java/org/hyperledger/besu/cli/custom/RpcAuthFileValidatorTest.java index 714086245a4..32db1368af8 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/custom/RpcAuthFileValidatorTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/custom/RpcAuthFileValidatorTest.java @@ -17,14 +17,14 @@ import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; import picocli.CommandLine.ParameterException; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class RpcAuthFileValidatorTest { private static final String CORRECT_TOML = "/rpcauth/auth_correct.toml"; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java index 414412ebb4a..ac1ec2e5777 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java @@ -52,13 +52,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonObject; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.CommandSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class OperatorSubCommandTest extends CommandTestAbstract { private static final String EXPECTED_OPERATOR_USAGE = @@ -80,7 +80,7 @@ public class OperatorSubCommandTest extends CommandTestAbstract { private Path tmpOutputDirectoryPath; - @Before + @BeforeEach public void init() throws IOException { SignatureAlgorithmFactory.resetInstance(); tmpOutputDirectoryPath = createTempDirectory(format("output-%d", currentTimeMillis())); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java index 09b4e3b1365..35dcaa4baee 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.function.Consumer; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class AbstractCLIOptionsTest> extends CommandTestAbstract { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java index 9d1d696ab43..6f7aa637cdd 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java @@ -21,11 +21,11 @@ import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EthProtocolOptionsTest extends AbstractCLIOptionsTest { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java index 8044770a9b4..e88462216f4 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java @@ -17,10 +17,10 @@ import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MetricsCLIOptionsTest extends AbstractCLIOptionsTest { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java index 0b7cc5e1224..404c021e3b9 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java @@ -35,12 +35,12 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MiningOptionsTest extends AbstractCLIOptionsTest { @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index a2cbdc5942b..4b4601bb9ca 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -23,11 +23,11 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class NetworkingOptionsTest extends AbstractCLIOptionsTest { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/OptionParserTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/OptionParserTest.java index db5e69e174b..d57e15d2612 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/OptionParserTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/OptionParserTest.java @@ -21,11 +21,11 @@ import com.google.common.collect.Range; import org.apache.tuweni.units.bigints.UInt256; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class OptionParserTest { @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java index 0e814a07e26..3b1a9e6839a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java @@ -23,10 +23,10 @@ import java.util.List; import com.google.common.collect.Range; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SynchronizerOptionsTest extends AbstractCLIOptionsTest { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java index 5b5fff5014e..00d4efc3b9f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.datatypes.Address; @@ -27,11 +28,11 @@ import java.time.Duration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TransactionPoolOptionsTest extends AbstractCLIOptionsTest { @@ -63,7 +64,7 @@ public void strictTxReplayProtection_default() { } @Test - public void pendingTransactionRetentionPeriod() { + public void pendingTransactionRetentionPeriodLegacy() { final int pendingTxRetentionHours = 999; internalTestSuccess( config -> @@ -73,6 +74,17 @@ public void pendingTransactionRetentionPeriod() { "--tx-pool=legacy"); } + @Test + public void pendingTransactionRetentionPeriodSequenced() { + final int pendingTxRetentionHours = 999; + internalTestSuccess( + config -> + assertThat(config.getPendingTxRetentionPeriod()).isEqualTo(pendingTxRetentionHours), + "--tx-pool-retention-hours", + String.valueOf(pendingTxRetentionHours), + "--tx-pool=sequenced"); + } + @Test public void disableLocalsDefault() { internalTestSuccess(config -> assertThat(config.getNoLocalPriority()).isFalse()); @@ -193,17 +205,24 @@ public void selectLegacyImplementationByArg() { "--tx-pool=legacy"); } + @Test + public void selectSequencedImplementationByArg() { + internalTestSuccess( + config -> assertThat(config.getTxPoolImplementation()).isEqualTo(SEQUENCED), + "--tx-pool=sequenced"); + } + @Test public void failIfLegacyOptionsWhenLayeredSelectedByDefault() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool-max-size=1000"); } @Test public void failIfLegacyOptionsWhenLayeredSelectedByArg() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool=layered", "--tx-pool-max-size=1000"); } @@ -211,11 +230,19 @@ public void failIfLegacyOptionsWhenLayeredSelectedByArg() { @Test public void failIfLayeredOptionsWhenLegacySelectedByArg() { internalTestFailure( - "Could not use layered transaction pool options with legacy implementation", + "Could not use layered transaction pool options with legacy or sequenced implementation", "--tx-pool=legacy", "--tx-pool-max-prioritized=1000"); } + @Test + public void failIfLayeredOptionsWhenSequencedSelectedByArg() { + internalTestFailure( + "Could not use layered transaction pool options with legacy or sequenced implementation", + "--tx-pool=sequenced", + "--tx-pool-max-prioritized=1000"); + } + @Test public void byDefaultNoPrioritySenders() { internalTestSuccess(config -> assertThat(config.getPrioritySenders()).isEmpty()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java index 5b4e0228550..437053afd56 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DataStorageOptionsTest extends AbstractCLIOptionsTest { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java index 4d0a67e75ca..18b09434dee 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java @@ -21,8 +21,8 @@ import java.util.Arrays; import org.apache.logging.log4j.Level; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.ParameterException; @@ -31,7 +31,7 @@ public class LoggingLevelOptionTest { private LoggingLevelOption levelOption; - @Before + @BeforeEach public void setUp() { levelOption = new LoggingLevelOption(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java index 822c7322718..3eca54df252 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java @@ -24,11 +24,12 @@ import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import picocli.CommandLine.Model.CommandSpec; public class RLPSubCommandTest extends CommandTestAbstract { @@ -158,10 +159,10 @@ public void encodeWithOutputFileMustWriteInThisFile() throws Exception { } @Test - public void encodeWithInputFilePathMustReadFromThisFile() throws Exception { - - final File tempJsonFile = temp.newFile("test.json"); - try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) { + public void encodeWithInputFilePathMustReadFromThisFile(final @TempDir Path dir) + throws Exception { + final Path tempJsonFile = Files.createTempFile(dir, "input", "json"); + try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) { fileWriter.write( "[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]"); @@ -169,7 +170,10 @@ public void encodeWithInputFilePathMustReadFromThisFile() throws Exception { fileWriter.flush(); parseCommand( - RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); + RLP_SUBCOMMAND_NAME, + RLP_ENCODE_SUBCOMMAND_NAME, + "--from", + tempJsonFile.toFile().getAbsolutePath()); final String expectedRlpString = "0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d" @@ -180,9 +184,9 @@ public void encodeWithInputFilePathMustReadFromThisFile() throws Exception { } @Test - public void canEncodeToQbftExtraData() throws IOException { - final File tempJsonFile = temp.newFile("test.json"); - try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) { + public void canEncodeToQbftExtraData(final @TempDir Path dir) throws Exception { + final Path tempJsonFile = Files.createTempFile(dir, "qbft", "json"); + try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) { fileWriter.write( "[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]"); @@ -193,7 +197,7 @@ public void canEncodeToQbftExtraData() throws IOException { RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", - tempJsonFile.getPath(), + tempJsonFile.toFile().getAbsolutePath(), "--type", RLP_QBFT_TYPE); @@ -206,17 +210,19 @@ public void canEncodeToQbftExtraData() throws IOException { } @Test - public void encodeWithInvalidInputMustRaiseAnError() throws Exception { - - final File tempJsonFile = temp.newFile("invalid_test.json"); - try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) { + public void encodeWithInvalidInputMustRaiseAnError(final @TempDir Path dir) throws Exception { + final Path tempJsonFile = Files.createTempFile(dir, "invalid", "json"); + try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) { fileWriter.write("{\"property\":0}"); fileWriter.flush(); parseCommand( - RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); + RLP_SUBCOMMAND_NAME, + RLP_ENCODE_SUBCOMMAND_NAME, + "--from", + tempJsonFile.toFile().getAbsolutePath()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -226,11 +232,13 @@ public void encodeWithInvalidInputMustRaiseAnError() throws Exception { } @Test - public void encodeWithEmptyInputMustRaiseAnError() throws Exception { - - final File tempJsonFile = temp.newFile("empty.json"); - - parseCommand(RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); + public void encodeWithEmptyInputMustRaiseAnError(final @TempDir Path dir) throws Exception { + final Path emptyFile = Files.createTempFile(dir, "empty", "json"); + parseCommand( + RLP_SUBCOMMAND_NAME, + RLP_ENCODE_SUBCOMMAND_NAME, + "--from", + emptyFile.toFile().getAbsolutePath()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -251,7 +259,7 @@ public void encodeWithEmptyStdInputMustRaiseAnError() throws Exception { .startsWith("An error occurred while trying to read the JSON data."); } - @After + @AfterEach public void restoreStdin() { System.setIn(System.in); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java new file mode 100644 index 00000000000..85839cc5b78 --- /dev/null +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java @@ -0,0 +1,69 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.subcommands; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + +public class TxParseSubCommandTest { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, UTF_8), true); + TxParseSubCommand txParseSubCommand = new TxParseSubCommand(writer); + + @Test + public void smokeTest() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x02f875018363bc5a8477359400850c570bd200825208943893d427c770de9b92065da03a8c825f13498da28702fbf8ccf8530480c080a0dd49141ecf93eeeaed5f3499a6103d6a9778e24a37b1f5c6a336c60c8a078c15a0511b51a3050771f66c1b779210a46a51be521a2446a3f87fc656dcfd1782aa5e")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("0xeb2629a2734e272bcc07bda959863f316f4bd4cf\n"); + } + + @Test + public void assertInvalidRlp() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x03f90124f9011e010516058261a89403040500000000000000000000000000000000006383000000f8b6f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a002000000000000000000000000000000000000000000000000000000000000000fc080a082f96cae43a3f2554cad899a6e9168a3cd613454f82e93488f9b4c1a998cc814a06b7519cd0e3159d6ce9bf811ff3ca4e9c5d7ac63fc52142370a0725e4c5273b2c0c0c0")); + String output = baos.toString(UTF_8); + assertThat(output).startsWith("err: "); + assertThat(output).contains("arbitrary precision scalar"); + } + + @Test + public void assertValidRlp() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x03f9013f010516058261a89403040500000000000000000000000000000000006383000000f8b6f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a002000000000000000000000000000000000000000000000000000000000000000fe1a0010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c44401401a0d98465c5489a09933e6428657f1fc4461d49febd8556c1c7e7053ed0be49cc4fa02c0d67e40aed75f87ea640cc47064d79f4383e24dec283ac6eb81e19da46cc26")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("0x730aa72228b55236de378f5267dfc77723b1380c\n"); + } + + @Test + public void assertInvalidChainId() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0xf901fc303083303030803030b901ae30303030303030303030433030303030303030303030303030303030303030303030303030303030203030413030303030303030303000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038390030000000002800380000413159000021000000002b0000000000003800000000003800000000000000000000002b633279315a00633200303041374222610063416200325832325a002543323861795930314130383058435931317a633043304239623900310031254363384361000023433158253041380037000027285839005a007937000000623700002761002b5a003937622e000000006300007863410000002a2e320000000000005a0000000000000037242778002039006120412e6362002138300000002a313030303030303030303030373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030a03030303030303030303030303030303030303030303030303030303030303030a03030303030303030303030303030303030303030303030303030303030303030")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("err: wrong chain id\n"); + } +} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java index 5c62076e692..29f519f8911 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java @@ -36,17 +36,16 @@ import java.nio.file.Paths; import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine.Model.CommandSpec; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BlocksSubCommandTest extends CommandTestAbstract { - @Rule public final TemporaryFolder folder = new TemporaryFolder(); + @TempDir public Path folder; private static final String EXPECTED_BLOCK_USAGE = "Usage: besu blocks [-hV] [COMMAND]" @@ -187,10 +186,13 @@ public void callingBlockImportSubCommandVersionMustDisplayVersion() { } @Test - public void callingBlockImportSubCommandWithPathMustImportBlocksWithThisPath() throws Exception { - final File fileToImport = temp.newFile("blocks.file"); + public void callingBlockImportSubCommandWithPathMustImportBlocksWithThisPath( + final @TempDir File fileToImport) throws Exception { parseCommand( - BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--from", fileToImport.getPath()); + BLOCK_SUBCOMMAND_NAME, + BLOCK_IMPORT_SUBCOMMAND_NAME, + "--from", + fileToImport.getAbsolutePath().toString()); verify(rlpBlockImporter) .importBlockchain(pathArgumentCaptor.capture(), any(), anyBoolean(), anyLong(), anyLong()); @@ -202,8 +204,7 @@ public void callingBlockImportSubCommandWithPathMustImportBlocksWithThisPath() t } @Test - public void blocksImport_rlpFormat() throws Exception { - final File fileToImport = temp.newFile("blocks.file"); + public void blocksImport_rlpFormat(final @TempDir File fileToImport) throws Exception { parseCommand( BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, @@ -222,10 +223,11 @@ public void blocksImport_rlpFormat() throws Exception { } @Test - public void blocksImport_rlpFormatMultiple() throws Exception { - final File fileToImport = temp.newFile("blocks.file"); - final File file2ToImport = temp.newFile("blocks2.file"); - final File file3ToImport = temp.newFile("blocks3.file"); + public void blocksImport_rlpFormatMultiple( + final @TempDir File fileToImport, + final @TempDir File file2ToImport, + final @TempDir File file3ToImport) + throws Exception { parseCommand( BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, @@ -247,10 +249,10 @@ public void blocksImport_rlpFormatMultiple() throws Exception { } @Test - public void blocksImport_jsonFormat() throws Exception { + public void blocksImport_jsonFormat(final @TempDir Path dir) throws Exception { final String fileContent = "test"; - final File fileToImport = temp.newFile("blocks.file"); - final Writer fileWriter = Files.newBufferedWriter(fileToImport.toPath(), UTF_8); + final Path fileToImport = Files.createTempFile(dir, "tmp", "json"); + final Writer fileWriter = Files.newBufferedWriter(fileToImport, UTF_8); fileWriter.write(fileContent); fileWriter.close(); @@ -260,7 +262,7 @@ public void blocksImport_jsonFormat() throws Exception { "--format", "JSON", "--from", - fileToImport.getPath()); + fileToImport.toFile().getAbsolutePath()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); @@ -274,9 +276,7 @@ public void blocksImport_jsonFormat() throws Exception { public void blocksExport_missingFileParam() throws IOException { createDbDirectory(true); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), - BLOCK_SUBCOMMAND_NAME, - BLOCK_EXPORT_SUBCOMMAND_NAME); + "--data-path=" + folder.getRoot(), BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME); final String expectedErrorOutputStart = "Missing required option: '--to='"; assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).startsWith(expectedErrorOutputStart); @@ -285,17 +285,17 @@ public void blocksExport_missingFileParam() throws IOException { } @Test - public void blocksExport_noDbDirectory() throws IOException { - final File outputFile = folder.newFile("blocks.bin"); + public void blocksExport_noDbDirectory(final @TempDir Path noDbDir) throws IOException { + final File outputFile = noDbDir.resolve("blocks.bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + noDbDir, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", - outputFile.getPath()); + outputFile.getAbsolutePath()); final String expectedErrorOutputStart = "Chain is empty. Unable to export blocks from specified data directory: " - + folder.getRoot().getAbsolutePath() + + noDbDir + File.separator + BesuController.DATABASE_PATH; assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -307,16 +307,16 @@ public void blocksExport_noDbDirectory() throws IOException { @Test public void blocksExport_emptyDbDirectory() throws IOException { createDbDirectory(false); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createFile(folder.resolve("empty")).toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", outputFile.getPath()); final String expectedErrorOutputStart = "Chain is empty. Unable to export blocks from specified data directory: " - + folder.getRoot().getAbsolutePath() + + folder + File.separator + BesuController.DATABASE_PATH; assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -328,13 +328,13 @@ public void blocksExport_emptyDbDirectory() throws IOException { @Test public void blocksExport_noStartOrEnd() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", - outputFile.getPath()); + outputFile.getAbsolutePath()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); @@ -344,9 +344,9 @@ public void blocksExport_noStartOrEnd() throws IOException { @Test public void blocksExport_withStartAndNoEnd() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createFile(folder.resolve("blocks.bin")).toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", @@ -361,9 +361,9 @@ public void blocksExport_withStartAndNoEnd() throws IOException { @Test public void blocksExport_withEndAndNoStart() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", @@ -378,13 +378,13 @@ public void blocksExport_withEndAndNoStart() throws IOException { @Test public void blocksExport_withStartAndEnd() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", - outputFile.getPath(), + outputFile.getAbsolutePath(), "--start-block=1", "--end-block=10"); assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -396,13 +396,13 @@ public void blocksExport_withStartAndEnd() throws IOException { @Test public void blocksExport_withOutOfOrderStartAndEnd() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", - outputFile.getPath(), + outputFile.getAbsolutePath(), "--start-block=10", "--end-block=1"); assertThat(commandErrorOutput.toString(UTF_8)) @@ -415,9 +415,9 @@ public void blocksExport_withOutOfOrderStartAndEnd() throws IOException { @Test public void blocksExport_withEmptyRange() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder, BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", @@ -434,9 +434,9 @@ public void blocksExport_withEmptyRange() throws IOException { @Test public void blocksExport_withInvalidStart() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder.getRoot(), BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", @@ -452,9 +452,9 @@ public void blocksExport_withInvalidStart() throws IOException { @Test public void blocksExport_withInvalidEnd() throws IOException { createDbDirectory(true); - final File outputFile = folder.newFile("blocks.bin"); + final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile(); parseCommand( - "--data-path=" + folder.getRoot().getAbsolutePath(), + "--data-path=" + folder.getRoot(), BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME, "--to", @@ -482,17 +482,18 @@ public void callingBlockExportSubCommandVersionMustDisplayVersion() { } private void createDbDirectory(final boolean createDataFiles) throws IOException { - final File dbDir = folder.newFolder(BesuController.DATABASE_PATH); + final Path dbDir = Files.createDirectory(folder.resolve(BesuController.DATABASE_PATH)); + if (createDataFiles) { - final Path dataFilePath = Paths.get(dbDir.getAbsolutePath(), "0000001.sst"); - final boolean success = new File(dataFilePath.toString()).createNewFile(); + final Path dataFilePath = Paths.get(dbDir.toFile().getAbsolutePath(), "0000001.sst"); + final boolean success = new File(dataFilePath.toFile().getAbsolutePath()).createNewFile(); assertThat(success).isTrue(); } } @Test - public void blocksImportWithNoSyncModeDoesNotRaiseNPE() throws IOException { - final File fileToImport = temp.newFile("blocks.file"); + public void blocksImportWithNoSyncModeDoesNotRaiseNPE(final @TempDir File fileToImport) + throws IOException { parseCommand( BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--from", fileToImport.getPath()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommandTest.java index e3b67d8b430..3ca4f41aaf8 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommandTest.java @@ -36,11 +36,11 @@ import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.Silent.class) +@ExtendWith(MockitoExtension.class) public class StorageSubCommandTest extends CommandTestAbstract { @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/util/BesuCommandCustomFactoryTest.java b/besu/src/test/java/org/hyperledger/besu/cli/util/BesuCommandCustomFactoryTest.java index d83fa43a655..f3494b506b0 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/util/BesuCommandCustomFactoryTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/util/BesuCommandCustomFactoryTest.java @@ -22,18 +22,18 @@ import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuCommandCustomFactoryTest { @Mock private PluginVersionsProvider pluginVersionsProvider; - @Before + @BeforeEach public void initMocks() { when(pluginVersionsProvider.getPluginVersions()).thenReturn(Arrays.asList("v1", "v2")); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigOptionSearchAndRunHandlerTest.java b/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigOptionSearchAndRunHandlerTest.java index 0f0c1e696a3..bd33703d9cc 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigOptionSearchAndRunHandlerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigOptionSearchAndRunHandlerTest.java @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -28,18 +29,19 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; import picocli.CommandLine.IDefaultValueProvider; import picocli.CommandLine.IExecutionStrategy; @@ -49,11 +51,11 @@ import picocli.CommandLine.ParseResult; import picocli.CommandLine.RunLast; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ConfigOptionSearchAndRunHandlerTest { private static final String CONFIG_FILE_OPTION_NAME = "--config-file"; - @Rule public final TemporaryFolder temp = new TemporaryFolder(); + @TempDir public Path temp; private LoggingLevelOption levelOption; private final IExecutionStrategy resultHandler = new RunLast(); @@ -68,16 +70,18 @@ public class ConfigOptionSearchAndRunHandlerTest { @Mock IGetter mockConfigOptionGetter; @Mock BesuParameterExceptionHandler mockParameterExceptionHandler; - @Before + @BeforeEach public void initMocks() { - when(mockCommandSpec.commandLine()).thenReturn(mockCommandLine); - when(mockParseResult.commandSpec()).thenReturn(mockCommandSpec); + lenient().when(mockCommandSpec.commandLine()).thenReturn(mockCommandLine); + lenient().when(mockParseResult.commandSpec()).thenReturn(mockCommandSpec); final List originalArgs = new ArrayList<>(); originalArgs.add(CONFIG_FILE_OPTION_NAME); - when(mockParseResult.originalArgs()).thenReturn(originalArgs); - when(mockParseResult.matchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(mockConfigOptionSpec); - when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(true); - when(mockConfigOptionSpec.getter()).thenReturn(mockConfigOptionGetter); + lenient().when(mockParseResult.originalArgs()).thenReturn(originalArgs); + lenient() + .when(mockParseResult.matchedOption(CONFIG_FILE_OPTION_NAME)) + .thenReturn(mockConfigOptionSpec); + lenient().when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(true); + lenient().when(mockConfigOptionSpec.getter()).thenReturn(mockConfigOptionGetter); levelOption = new LoggingLevelOption(); levelOption.setLogLevel("INFO"); configParsingHandler = @@ -87,7 +91,7 @@ public void initMocks() { @Test public void handleWithCommandLineOption() throws Exception { - when(mockConfigOptionGetter.get()).thenReturn(temp.newFile()); + when(mockConfigOptionGetter.get()).thenReturn(Files.createTempFile("tmp", "txt").toFile()); final List result = configParsingHandler.handle(mockParseResult); verify(mockCommandLine).setDefaultValueProvider(any(IDefaultValueProvider.class)); verify(mockCommandLine).setExecutionStrategy(eq(resultHandler)); @@ -105,7 +109,9 @@ public void handleWithEnvironmentVariable() throws IOException { new ConfigOptionSearchAndRunHandler( resultHandler, mockParameterExceptionHandler, - singletonMap("BESU_CONFIG_FILE", temp.newFile().getAbsolutePath())); + singletonMap( + "BESU_CONFIG_FILE", + Files.createFile(temp.resolve("tmp")).toFile().getAbsolutePath())); when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(false); @@ -160,7 +166,7 @@ public void handleThrowsErrorWithWithEnvironmentVariableAndCommandLineSpecified( new ConfigOptionSearchAndRunHandler( resultHandler, mockParameterExceptionHandler, - singletonMap("BESU_CONFIG_FILE", temp.newFile().getAbsolutePath())); + singletonMap("BESU_CONFIG_FILE", temp.resolve("tmp").toFile().getAbsolutePath())); when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(true); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/util/VersionProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/util/VersionProviderTest.java index 6fba9cf66a4..57f16c90210 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/util/VersionProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/util/VersionProviderTest.java @@ -23,12 +23,12 @@ import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class VersionProviderTest { @Mock private PluginVersionsProvider pluginVersionsProvider; diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java index a24479e8617..bb7304d9f77 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java @@ -30,9 +30,6 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.GasLimitCalculator; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; @@ -45,10 +42,13 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index 6245a8a6ba8..25db1cb9b49 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -76,15 +77,15 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("unchecked") -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuEventsImplTest { private static final Supplier SIGNATURE_ALGORITHM = @@ -113,7 +114,7 @@ public class BesuEventsImplTest { private MutableBlockchain blockchain; private final BlockDataGenerator gen = new BlockDataGenerator(); - @Before + @BeforeEach public void setUp() { blockchain = DefaultBlockchain.createMutable( @@ -128,18 +129,22 @@ public void setUp() { when(mockEthContext.getEthMessages()).thenReturn(mockEthMessages); when(mockEthContext.getEthPeers()).thenReturn(mockEthPeers); when(mockEthContext.getScheduler()).thenReturn(mockEthScheduler); - when(mockEthPeers.streamAvailablePeers()).thenAnswer(z -> Stream.empty()); + lenient().when(mockEthPeers.streamAvailablePeers()).thenAnswer(z -> Stream.empty()); when(mockProtocolContext.getBlockchain()).thenReturn(blockchain); - when(mockProtocolContext.getWorldStateArchive()).thenReturn(mockWorldStateArchive); - when(mockProtocolSchedule.getByBlockHeader(any())).thenReturn(mockProtocolSpec); - when(mockProtocolSpec.getTransactionValidatorFactory()) + lenient().when(mockProtocolContext.getWorldStateArchive()).thenReturn(mockWorldStateArchive); + lenient().when(mockProtocolSchedule.getByBlockHeader(any())).thenReturn(mockProtocolSpec); + lenient() + .when(mockProtocolSpec.getTransactionValidatorFactory()) .thenReturn(mockTransactionValidatorFactory); - when(mockProtocolSpec.getFeeMarket()).thenReturn(FeeMarket.london(0L)); - when(mockTransactionValidatorFactory.get().validate(any(), any(Optional.class), any())) + lenient().when(mockProtocolSpec.getFeeMarket()).thenReturn(FeeMarket.london(0L)); + lenient() + .when(mockTransactionValidatorFactory.get().validate(any(), any(Optional.class), any())) .thenReturn(ValidationResult.valid()); - when(mockTransactionValidatorFactory.get().validateForSender(any(), any(), any())) + lenient() + .when(mockTransactionValidatorFactory.get().validateForSender(any(), any(), any())) .thenReturn(ValidationResult.valid()); - when(mockWorldStateArchive.getMutable(any(), anyBoolean())) + lenient() + .when(mockWorldStateArchive.getMutable(any(), anyBoolean())) .thenReturn(Optional.of(mockWorldState)); blockBroadcaster = new BlockBroadcaster(mockEthContext); diff --git a/besu/src/test/java/org/hyperledger/besu/services/PicoCLIOptionsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/PicoCLIOptionsImplTest.java index ac7e7fb9593..52f37f769a9 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/PicoCLIOptionsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/PicoCLIOptionsImplTest.java @@ -17,16 +17,16 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.UnmatchedArgumentException; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PicoCLIOptionsImplTest { @Command @@ -46,7 +46,7 @@ static final class MixinOptions { private CommandLine commandLine; private PicoCLIOptionsImpl serviceImpl; - @Before + @BeforeEach public void setUp() { command = new SimpleCommand(); mixin = new MixinOptions(); diff --git a/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java b/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java index a5b3bb90d99..84344c24918 100644 --- a/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java +++ b/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java @@ -232,7 +232,6 @@ public void nodeAllowlistCheckShouldNotWorkWithUnknownHostnameWhenOnlyDnsEnabled true, toml.toAbsolutePath().toString())) .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining( - "Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false."); + .hasMessageContaining("Invalid IP address"); } } diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index be337272e97..e516060da86 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -185,7 +185,7 @@ tx-pool-save-file="txpool.dump" tx-pool-layer-max-capacity=12345678 tx-pool-max-prioritized=9876 tx-pool-max-future-by-sender=321 -## Legacy +## Legacy/Sequenced tx-pool-retention-hours=999 tx-pool-max-size=1234 tx-pool-limit-by-account-percentage=0.017 diff --git a/build.gradle b/build.gradle index 1d331ebd051..e30bd9d2ed5 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ */ +import com.github.jk1.license.filter.LicenseBundleNormalizer import groovy.transform.CompileStatic import groovy.transform.Memoized import net.ltgt.gradle.errorprone.CheckSeverity @@ -22,13 +23,13 @@ import java.text.SimpleDateFormat import java.util.regex.Pattern plugins { - id 'com.diffplug.spotless' version '6.12.0' - id 'com.github.ben-manes.versions' version '0.42.0' - id 'com.github.hierynomus.license' version '0.16.1-fix' - id 'com.jfrog.artifactory' version '4.28.3' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' - id 'me.champeau.jmh' version '0.7.0' apply false - id 'net.ltgt.errorprone' version '2.0.2' + id 'com.diffplug.spotless' version '6.23.3' + id 'com.github.ben-manes.versions' version '0.50.0' + id 'com.github.jk1.dependency-license-report' version '2.5' + id 'com.jfrog.artifactory' version '5.1.11' + id 'io.spring.dependency-management' version '1.1.4' + id 'me.champeau.jmh' version '0.7.2' apply false + id 'net.ltgt.errorprone' version '3.0.1' id 'maven-publish' } @@ -74,13 +75,35 @@ def _strListCmdArg(name) { return _strListCmdArg(name, null) } +licenseReport { + // This is for the allowed-licenses-file in checkLicense Task + // Accepts File, URL or String path to local or remote file + allowedLicensesFile = new File("$rootDir/gradle/allowed-licenses.json") + + excludes = [ + // only used for static analysis, not actually shipped + 'com.google.errorprone:javac', + 'org.checkerframework:dataflow-shaded', + 'org.checkerframework:dataflow-errorprone', + // exclude Kotlin multiplatform dependencies container, they have the same license of what they contain + 'com.squareup.okio:okio', + 'org.jetbrains.kotlinx:kotlinx-coroutines-core' + ] + + // If set to true, then all boms will be excluded from the report + excludeBoms = true + + filters = [ + new LicenseBundleNormalizer(bundlePath: "$rootDir/gradle/license-normalizer-bundle.json") + ] +} + allprojects { apply plugin: 'java-library' apply plugin: 'io.spring.dependency-management' apply plugin: 'jacoco' apply plugin: 'net.ltgt.errorprone' apply from: "${rootDir}/gradle/versions.gradle" - apply from: "${rootDir}/gradle/check-licenses.gradle" version = rootProject.version @@ -164,7 +187,7 @@ allprojects { } groovyGradle { target '*.gradle' - greclipse('4.21.0').configFile(rootProject.file('gradle/formatter.properties')) + greclipse('4.21').configFile(rootProject.file('gradle/formatter.properties')) endWithNewline() } // Below this line are currently only license header tasks @@ -310,7 +333,6 @@ allprojects { options.addStringOption('Xwerror', '-html5') options.encoding = 'UTF-8' } - } task deploy() {} @@ -602,10 +624,10 @@ task autocomplete(type: JavaExec) { } } -installDist { dependsOn checkLicenses, untunedStartScripts, evmToolStartScripts } +installDist { dependsOn checkLicense, untunedStartScripts, evmToolStartScripts } distTar { - dependsOn checkLicenses, autocomplete, untunedStartScripts, evmToolStartScripts + dependsOn checkLicense, autocomplete, untunedStartScripts, evmToolStartScripts doFirst { delete fileTree(dir: 'build/distributions', include: '*.tar.gz') } @@ -615,7 +637,7 @@ distTar { } distZip { - dependsOn checkLicenses, autocomplete, untunedStartScripts, evmToolStartScripts + dependsOn checkLicense, autocomplete, untunedStartScripts, evmToolStartScripts doFirst { delete fileTree(dir: 'build/distributions', include: '*.zip') } @@ -913,7 +935,6 @@ task checkSpdxHeader(type: CheckSpdxHeader) { "(.*${sep}build${sep}.*)", "(.*${sep}src${sep}[^${sep}]+${sep}generated${sep}.*)" ].join("|") - } task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { diff --git a/config/src/main/resources/classic.json b/config/src/main/resources/classic.json index efbc5be4fcf..ea7c49e1fa3 100644 --- a/config/src/main/resources/classic.json +++ b/config/src/main/resources/classic.json @@ -13,10 +13,12 @@ "thanosBlock": 11700000, "magnetoBlock": 13189133, "mystiqueBlock": 14525000, + "spiralBlock": 19250000, "ethash": { }, "discovery" : { + "dns": "enrtree://AJE62Q4DUX4QMMXEHCSSCSC65TDHZYSMONSD64P3WULVLSF6MRQ3K@all.classic.blockd.info", "bootnodes" : [ "enode://8e73168affd8d445edda09c561d607081ca5d7963317caae2702f701eb6546b06948b7f8687a795de576f6a5f33c44828e25a90aa63de18db380a11e660dd06f@159.203.37.80:30303", "enode://2b1ef75e8b7119b6e0294f2e51ead2cf1a5400472452c199e9587727ada99e7e2b1199e36adcad6cbae65dce2410559546e4d83d8c93d45a559e723e56444c03@67.207.93.100:30303", diff --git a/consensus/clique/build.gradle b/consensus/clique/build.gradle index 4c5634f17c2..f09e5837771 100644 --- a/consensus/clique/build.gradle +++ b/consensus/clique/build.gradle @@ -60,6 +60,4 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/consensus/common/build.gradle b/consensus/common/build.gradle index 04132ab6d00..0043fe07115 100644 --- a/consensus/common/build.gradle +++ b/consensus/common/build.gradle @@ -59,8 +59,6 @@ dependencies { testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - testSupportImplementation project( path: ':crypto:services', configuration: 'testSupportArtifacts') testSupportImplementation project( path: ':ethereum:core', configuration: 'testSupportArtifacts') testSupportImplementation 'org.mockito:mockito-core' diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java index 6d8c64a835f..58ad24a2882 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java @@ -104,7 +104,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolMetrics; import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -241,7 +241,7 @@ public TestContext build() { } final MutableBlockchain blockChain; - final DefaultWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); + final ForestWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); if (genesisFile.isPresent()) { try { diff --git a/crypto/algorithms/build.gradle b/crypto/algorithms/build.gradle index 638838db9f8..b9bb6d62fae 100644 --- a/crypto/algorithms/build.gradle +++ b/crypto/algorithms/build.gradle @@ -42,6 +42,4 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/crypto/services/build.gradle b/crypto/services/build.gradle index 9b0b06611b9..6188462f550 100644 --- a/crypto/services/build.gradle +++ b/crypto/services/build.gradle @@ -32,11 +32,8 @@ dependencies { api project(':crypto:algorithms') api project(':plugin-api') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } artifacts { testSupportArtifacts testSupportJar } diff --git a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java index 68d369ae538..fac403e041d 100644 --- a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java +++ b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java @@ -20,26 +20,22 @@ import org.hyperledger.besu.crypto.SECPPublicKey; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; -import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.security.spec.ECPoint; import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class KeyPairSecurityModuleTest { - @Rule public final TemporaryFolder temp = new TemporaryFolder(); + @TempDir public Path keyFile; @Test public void validatePublicKeyFromECPointCanBeConstructed() throws IOException { - final File keyDirectory = temp.newFolder(); - final File keyFile = new File(keyDirectory, "key"); - - final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile); + final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile.resolve("key")); final KeyPairSecurityModule keyPairSecurityModule = new KeyPairSecurityModule(keyPair); final ECPoint ecPoint = keyPairSecurityModule.getPublicKey().getW(); diff --git a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java index 07008f06cbc..261271aee9b 100644 --- a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java +++ b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java @@ -21,12 +21,12 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class NodeKeyTest { - @Before + @BeforeEach public void resetInstance() { SignatureAlgorithmFactory.resetInstance(); } diff --git a/datatypes/build.gradle b/datatypes/build.gradle index 20821e66d81..dbffc1e5633 100644 --- a/datatypes/build.gradle +++ b/datatypes/build.gradle @@ -39,8 +39,6 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } configurations { testArtifacts } diff --git a/errorprone-checks/build.gradle b/errorprone-checks/build.gradle index 1aff3a23b23..a04fa27e473 100644 --- a/errorprone-checks/build.gradle +++ b/errorprone-checks/build.gradle @@ -38,8 +38,6 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - epJavac 'com.google.errorprone:error_prone_check_api' } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/AccountAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/AccountAdapter.java index f9098089e42..13caadab6ab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/AccountAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/AccountAdapter.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.bonsai.BonsaiAccount; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiAccount; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java index 3f4995d7abd..d88f6cba8e5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java @@ -31,6 +31,7 @@ import java.util.Optional; import com.fasterxml.jackson.core.JsonGenerator.Feature; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @@ -46,6 +47,10 @@ public class WebSocketMessageHandler { + private static final ObjectMapper jsonObjectMapper = + new ObjectMapper() + .registerModule(new Jdk8Module()); // Handle JDK8 Optionals (de)serialization + private static final Logger LOG = LoggerFactory.getLogger(WebSocketMessageHandler.class); private static final ObjectWriter JSON_OBJECT_WRITER = new ObjectMapper() @@ -161,6 +166,7 @@ public void handle( } private void replyToClient(final ServerWebSocket websocket, final Object result) { + traceResponse(result); try { // underlying output stream lifecycle is managed by the json object writer JSON_OBJECT_WRITER.writeValue(new JsonResponseStreamer(websocket), result); @@ -172,4 +178,12 @@ private void replyToClient(final ServerWebSocket websocket, final Object result) private JsonRpcResponse errorResponse(final Object id, final RpcErrorType error) { return new JsonRpcErrorResponse(id, error); } + + private void traceResponse(final Object response) { + try { + LOG.trace(jsonObjectMapper.writeValueAsString(response)); + } catch (JsonProcessingException e) { + LOG.error("Error tracing JSON-RPC response", e); + } + } } diff --git a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/worldstate/PrunerIntegrationTest.java b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerIntegrationTest.java similarity index 93% rename from ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/worldstate/PrunerIntegrationTest.java rename to ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerIntegrationTest.java index 77f871f1002..77ffc461f86 100644 --- a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/worldstate/PrunerIntegrationTest.java +++ b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; @@ -26,11 +26,15 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner.PruningPhase; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.Pruner.PruningPhase; +import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -57,9 +61,10 @@ public class PrunerIntegrationTest { private final NoOpMetricsSystem metricsSystem = new NoOpMetricsSystem(); private final Map> hashValueStore = new HashMap<>(); private final InMemoryKeyValueStorage stateStorage = new TestInMemoryStorage(hashValueStore); - private final WorldStateStorage worldStateStorage = new WorldStateKeyValueStorage(stateStorage); + private final WorldStateStorage worldStateStorage = + new ForestWorldStateKeyValueStorage(stateStorage); private final WorldStateArchive worldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( worldStateStorage, new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java index a69e920dd20..87d45be8184 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java @@ -32,9 +32,9 @@ import org.hyperledger.besu.ethereum.core.Withdrawal; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.log.LogsBloomFilter; @@ -134,12 +134,12 @@ private static void writeAccountsTo( } private static Hash calculateGenesisStateHash(final List genesisAccounts) { - final WorldStateKeyValueStorage stateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + final ForestWorldStateKeyValueStorage stateStorage = + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStatePreimageKeyValueStorage preimageStorage = new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()); final MutableWorldState worldState = - new DefaultMutableWorldState(stateStorage, preimageStorage, EvmConfiguration.DEFAULT); + new ForestMutableWorldState(stateStorage, preimageStorage, EvmConfiguration.DEFAULT); writeAccountsTo(worldState, genesisAccounts, null); return worldState.rootHash(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/PrivacyParameters.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/PrivacyParameters.java index 1d4cfdf6c1b..f5e6f05a05d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/PrivacyParameters.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/PrivacyParameters.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivateWorldStateReader; import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -340,7 +340,7 @@ public PrivacyParameters build() { final WorldStatePreimageStorage privatePreimageStorage = storageProvider.createWorldStatePreimageStorage(); final WorldStateArchive privateWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( privateWorldStateStorage, privatePreimageStorage, EvmConfiguration.DEFAULT); final PrivateStateStorage privateStateStorage = storageProvider.createPrivateStateStorage(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java index 103fb3782d1..8f1b01a50c1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java @@ -21,8 +21,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.BlockProcessingOutputs; import org.hyperledger.besu.ethereum.BlockProcessingResult; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Deposit; @@ -33,6 +31,8 @@ import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.vm.BlockHashLookup; import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; import org.hyperledger.besu.evm.tracing.OperationTracer; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 7e0a0da76b5..876fa65d298 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -505,9 +505,15 @@ public TransactionProcessingResult processTransaction( gasUsedByTransaction, refundedGas, validationResult, initialFrame.getRevertReason()); } } catch (final MerkleTrieException re) { + operationTracer.traceEndTransaction( + worldState.updater(), transaction, false, Bytes.EMPTY, List.of(), 0, 0L); + // need to throw to trigger the heal throw re; } catch (final RuntimeException re) { + operationTracer.traceEndTransaction( + worldState.updater(), transaction, false, Bytes.EMPTY, List.of(), 0, 0L); + LOG.error("Critical Exception Processing Transaction", re); return TransactionProcessingResult.invalid( ValidationResult.invalid( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java similarity index 94% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java index e52319463cc..fc20db7f813 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.privacy; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -26,12 +26,12 @@ // This class uses a public WorldUpdater and a private WorldUpdater to provide a // MutableWorldStateUpdater that can read and write from the private world state and can read from // the public world state, but cannot write to it. -public class DefaultMutablePrivateWorldStateUpdater implements WorldUpdater { +public class PrivateMutableWorldStateUpdater implements WorldUpdater { protected final WorldUpdater publicWorldUpdater; protected final WorldUpdater privateWorldUpdater; - public DefaultMutablePrivateWorldStateUpdater( + public PrivateMutableWorldStateUpdater( final WorldUpdater publicWorldUpdater, final WorldUpdater privateWorldUpdater) { this.publicWorldUpdater = publicWorldUpdater; this.privateWorldUpdater = privateWorldUpdater; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java index c953ed93d1d..9c85fb39fb3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutablePrivateWorldStateUpdater; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.code.CodeV0; @@ -109,7 +108,7 @@ public TransactionProcessingResult processTransaction( sender.getNonce()); final WorldUpdater mutablePrivateWorldStateUpdater = - new DefaultMutablePrivateWorldStateUpdater(publicWorldState, privateWorldState); + new PrivateMutableWorldStateUpdater(publicWorldState, privateWorldState); final MessageFrame.Builder commonMessageFrameBuilder = MessageFrame.builder() .maxStackSize(maxStackSize) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/storage/keyvalue/PrivacyKeyValueStorageProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/storage/keyvalue/PrivacyKeyValueStorageProvider.java index d54a4ba164f..1596765bfb1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/storage/keyvalue/PrivacyKeyValueStorageProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/storage/keyvalue/PrivacyKeyValueStorageProvider.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; @@ -48,7 +48,7 @@ public PrivacyKeyValueStorageProvider( @Override public WorldStateStorage createWorldStateStorage() { - return new WorldStateKeyValueStorage(privateWorldStateKeyValueStorage); + return new ForestWorldStateKeyValueStorage(privateWorldStateKeyValueStorage); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java index 8a7eef8ee5d..dea6b932c32 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java @@ -14,12 +14,13 @@ */ package org.hyperledger.besu.ethereum.storage.keyvalue; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.chain.VariablesStorage; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.storage.StorageProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -78,7 +79,7 @@ public WorldStateStorage createWorldStateStorage(final DataStorageFormat dataSto if (dataStorageFormat.equals(DataStorageFormat.BONSAI)) { return new BonsaiWorldStateKeyValueStorage(this, metricsSystem); } else { - return new WorldStateKeyValueStorage( + return new ForestWorldStateKeyValueStorage( getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.WORLD_STATE)); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiAccount.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiAccount.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiAccount.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiAccount.java index 476a0ab22e1..d93f550cafa 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiAccount.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiAccount.java @@ -14,18 +14,18 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import org.hyperledger.besu.datatypes.AccountValue; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldView; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldView; import org.hyperledger.besu.evm.ModificationNotAllowedException; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.evm.account.MutableAccount; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiValue.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java index 7d862c7fb95..5d14c882750 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiValue.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java @@ -14,7 +14,7 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateProvider.java similarity index 95% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateProvider.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateProvider.java index 5313977c037..4c783888c09 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateProvider.java @@ -14,19 +14,12 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; -import static org.hyperledger.besu.ethereum.bonsai.cache.CachedWorldStorageManager.RETAINED_LAYERS; +import static org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedWorldStorageManager.RETAINED_LAYERS; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedWorldStorageManager; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogManager; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MutableWorldState; @@ -34,6 +27,13 @@ import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedWorldStorageManager; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogManager; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedBonsaiWorldView.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedBonsaiWorldView.java similarity index 88% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedBonsaiWorldView.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedBonsaiWorldView.java index 473933b3959..6cdfd10cf9c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedBonsaiWorldView.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedBonsaiWorldView.java @@ -13,17 +13,17 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.cache; +package org.hyperledger.besu.ethereum.trie.bonsai.cache; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class CachedBonsaiWorldView implements BonsaiStorageSubscriber { +public class CachedBonsaiWorldView + implements BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber { private BonsaiWorldStateKeyValueStorage worldStateStorage; private final BlockHeader blockHeader; private long worldViewSubscriberId; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoader.java similarity index 95% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoader.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoader.java index f53342d6317..832ca6f7dbd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoader.java @@ -13,15 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.cache; +package org.hyperledger.besu.ethereum.trie.bonsai.cache; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.ObservableMetricsSystem; @@ -38,7 +37,8 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -public class CachedMerkleTrieLoader implements BonsaiStorageSubscriber { +public class CachedMerkleTrieLoader + implements BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber { private static final int ACCOUNT_CACHE_SIZE = 100_000; private static final int STORAGE_CACHE_SIZE = 200_000; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoaderModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoaderModule.java similarity index 94% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoaderModule.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoaderModule.java index 51cfdd8707e..63c8051f253 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoaderModule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedMerkleTrieLoaderModule.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.cache; +package org.hyperledger.besu.ethereum.trie.bonsai.cache; import org.hyperledger.besu.metrics.ObservableMetricsSystem; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedWorldStorageManager.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedWorldStorageManager.java similarity index 92% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedWorldStorageManager.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedWorldStorageManager.java index bf205f05b72..8a09c136a5e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedWorldStorageManager.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/cache/CachedWorldStorageManager.java @@ -12,16 +12,15 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.cache; +package org.hyperledger.besu.ethereum.trie.bonsai.cache; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiSnapshotWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateLayerStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiSnapshotWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateLayerStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; @@ -37,7 +36,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class CachedWorldStorageManager implements BonsaiStorageSubscriber { +public class CachedWorldStorageManager + implements BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber { public static final long RETAINED_LAYERS = 512; // at least 256 + typical rollbacks private static final Logger LOG = LoggerFactory.getLogger(CachedWorldStorageManager.class); private final BonsaiWorldStateProvider archive; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiPreImageProxy.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiPreImageProxy.java index 248e5d895fd..16cda3104f0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiPreImageProxy.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage; +package org.hyperledger.besu.ethereum.trie.bonsai.storage; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java index 80bd2ce86eb..69c74ec27ca 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiSnapshotWorldStateKeyValueStorage.java @@ -13,11 +13,11 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage; +package org.hyperledger.besu.ethereum.trie.bonsai.storage; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorage.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorage.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorage.java index 28e2c5bd7aa..54089c7e212 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorage.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.storage; +package org.hyperledger.besu.ethereum.trie.bonsai.storage; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_STORAGE_STORAGE; @@ -21,12 +21,12 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.storage.flat.FlatDbStrategy; -import org.hyperledger.besu.ethereum.bonsai.storage.flat.FullFlatDbStrategy; -import org.hyperledger.besu.ethereum.bonsai.storage.flat.PartialFlatDbStrategy; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.flat.FlatDbStrategy; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.flat.FullFlatDbStrategy; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.flat.PartialFlatDbStrategy; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateLayerStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateLayerStorage.java similarity index 92% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateLayerStorage.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateLayerStorage.java index aa96354789a..0dd61b8d7a6 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateLayerStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateLayerStorage.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage; +package org.hyperledger.besu.ethereum.trie.bonsai.storage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FlatDbStrategy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FlatDbStrategy.java similarity index 99% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FlatDbStrategy.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FlatDbStrategy.java index c561dcd8609..6c1c918172b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FlatDbStrategy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FlatDbStrategy.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage.flat; +package org.hyperledger.besu.ethereum.trie.bonsai.storage.flat; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_STORAGE_STORAGE; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FullFlatDbStrategy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FullFlatDbStrategy.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FullFlatDbStrategy.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FullFlatDbStrategy.java index de42ba50979..1885069e3d4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/FullFlatDbStrategy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/FullFlatDbStrategy.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage.flat; +package org.hyperledger.besu.ethereum.trie.bonsai.storage.flat; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_STORAGE_STORAGE; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/PartialFlatDbStrategy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/PartialFlatDbStrategy.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/PartialFlatDbStrategy.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/PartialFlatDbStrategy.java index 1dc4288b21a..632f433f9b0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/flat/PartialFlatDbStrategy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/PartialFlatDbStrategy.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.storage.flat; +package org.hyperledger.besu.ethereum.trie.bonsai.storage.flat; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_STORAGE_STORAGE; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogAddedEvent.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogAddedEvent.java similarity index 93% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogAddedEvent.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogAddedEvent.java index c9df72f0040..3e1387997b4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogAddedEvent.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogAddedEvent.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogEvent; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryImpl.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java index ebac500061c..36a6510c91e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java @@ -13,17 +13,17 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import org.hyperledger.besu.datatypes.AccountValue; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.BonsaiValue; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiValue; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayer.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayer.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayer.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayer.java index 7d61e501266..ff1e29c41b8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayer.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayer.java @@ -14,7 +14,7 @@ * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import static com.google.common.base.Preconditions.checkState; @@ -22,7 +22,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.BonsaiValue; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiValue; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import java.util.HashMap; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManager.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManager.java similarity index 96% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManager.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManager.java index 3a874de6b67..ffb4e0bedcf 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManager.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManager.java @@ -13,14 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.services.TrieLogService; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPruner.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPruner.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPruner.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPruner.java index 6ba88170742..747a82e1621 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPruner.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPruner.java @@ -13,13 +13,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import java.util.Comparator; import java.util.Optional; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java similarity index 92% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java index 7c7f7fd5516..b9cfcbeb368 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java @@ -14,32 +14,32 @@ * */ -package org.hyperledger.besu.ethereum.bonsai.worldview; +package org.hyperledger.besu.ethereum.trie.bonsai.worldview; -import static org.hyperledger.besu.ethereum.bonsai.BonsaiAccount.fromRLP; -import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; -import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; +import static org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; +import static org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; +import static org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldView.encodeTrieValue; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.BonsaiAccount; -import org.hyperledger.besu.ethereum.bonsai.BonsaiValue; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedWorldStorageManager; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiSnapshotWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateLayerStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogManager; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator.StorageConsumingMap; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.trie.NodeLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiAccount; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiValue; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedWorldStorageManager; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiSnapshotWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.BonsaiStorageSubscriber; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateLayerStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogManager; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator.StorageConsumingMap; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.account.Account; @@ -282,7 +282,10 @@ private void updateAccountStorageState( worldStateUpdater.getAccountsToUpdate().get(updatedAddress); final BonsaiAccount accountOriginal = accountValue.getPrior(); final Hash storageRoot = - (accountOriginal == null) ? Hash.EMPTY_TRIE_HASH : accountOriginal.getStorageRoot(); + (accountOriginal == null + || worldStateUpdater.getStorageToClear().contains(updatedAddress)) + ? Hash.EMPTY_TRIE_HASH + : accountOriginal.getStorageRoot(); final StoredMerklePatriciaTrie storageTrie = createTrie( (location, key) -> @@ -306,7 +309,7 @@ private void updateAccountStorageState( bonsaiUpdater -> bonsaiUpdater.putStorageValueBySlotHash( updatedAddressHash, slotHash, updatedStorage)); - storageTrie.put(slotHash, BonsaiWorldView.encodeTrieValue(updatedStorage)); + storageTrie.put(slotHash, encodeTrieValue(updatedStorage)); } } catch (MerkleTrieException e) { // need to throw to trigger the heal @@ -344,7 +347,8 @@ private void clearStorage( final BonsaiAccount oldAccount = worldStateStorage .getAccount(address.addressHash()) - .map(bytes -> fromRLP(BonsaiWorldState.this, address, bytes, true)) + .map( + bytes -> BonsaiAccount.fromRLP(BonsaiWorldState.this, address, bytes, true)) .orElse(null); if (oldAccount == null) { // This is when an account is both created and deleted within the scope of the same @@ -534,7 +538,7 @@ public Stream streamAccounts(final Bytes32 startKeyHash, fina public Account get(final Address address) { return worldStateStorage .getAccount(address.addressHash()) - .map(bytes -> fromRLP(accumulator, address, bytes, true)) + .map(bytes -> BonsaiAccount.fromRLP(accumulator, address, bytes, true)) .orElse(null); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java index fc431812d00..285d0de1f34 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java @@ -14,18 +14,18 @@ * */ -package org.hyperledger.besu.ethereum.bonsai.worldview; +package org.hyperledger.besu.ethereum.trie.bonsai.worldview; import org.hyperledger.besu.datatypes.AccountValue; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.bonsai.BonsaiAccount; -import org.hyperledger.besu.ethereum.bonsai.BonsaiValue; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiAccount; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiValue; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -328,17 +328,6 @@ public void commit() { } if (tracked.getStorageWasCleared()) { updatedAccount.clearStorage(); - wrappedWorldView() - .getAllAccountStorage(updatedAddress, updatedAccount.getStorageRoot()) - .forEach( - (keyHash, entryValue) -> { - final StorageSlotKey storageSlotKey = - new StorageSlotKey(Hash.wrap(keyHash), Optional.empty()); - final UInt256 value = UInt256.fromBytes(RLP.decodeOne(entryValue)); - pendingStorageUpdates.put( - storageSlotKey, new BonsaiValue<>(value, null, true)); - }); - updatedAccount.setStorageRoot(Hash.EMPTY_TRIE_HASH); } tracked.getUpdatedStorage().forEach(updatedAccount::setStorageValue); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldView.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldView.java similarity index 93% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldView.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldView.java index 7a307ec3f40..cd16e7dec8a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldView.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldView.java @@ -14,13 +14,13 @@ * */ -package org.hyperledger.besu.ethereum.bonsai.worldview; +package org.hyperledger.besu.ethereum.trie.bonsai.worldview; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldView; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultWorldStateArchive.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java similarity index 88% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultWorldStateArchive.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java index a29bd9b2ff4..b04c22a5543 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultWorldStateArchive.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -22,6 +22,10 @@ import org.hyperledger.besu.ethereum.proof.WorldStateProof; import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; +import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.worldstate.WorldState; @@ -32,7 +36,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; -public class DefaultWorldStateArchive implements WorldStateArchive { +public class ForestWorldStateArchive implements WorldStateArchive { private final WorldStateStorage worldStateStorage; private final WorldStatePreimageStorage preimageStorage; private final WorldStateProofProvider worldStateProof; @@ -40,7 +44,7 @@ public class DefaultWorldStateArchive implements WorldStateArchive { private static final Hash EMPTY_ROOT_HASH = Hash.wrap(MerkleTrie.EMPTY_TRIE_NODE_HASH); - public DefaultWorldStateArchive( + public ForestWorldStateArchive( final WorldStateStorage worldStateStorage, final WorldStatePreimageStorage preimageStorage, final EvmConfiguration evmConfiguration) { @@ -72,7 +76,7 @@ public Optional getMutable(final Hash rootHash, final Hash bl return Optional.empty(); } return Optional.of( - new DefaultMutableWorldState( + new ForestMutableWorldState( rootHash, worldStateStorage, preimageStorage, evmConfiguration)); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPruner.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPruner.java similarity index 98% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPruner.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPruner.java index 136e8b01445..0559400a874 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPruner.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPruner.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -20,6 +20,8 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; +import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/Pruner.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/Pruner.java similarity index 99% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/Pruner.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/Pruner.java index 04949b55e12..bad8b2da302 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/Pruner.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/Pruner.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; import static com.google.common.base.Preconditions.checkArgument; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/PrunerConfiguration.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerConfiguration.java similarity index 96% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/PrunerConfiguration.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerConfiguration.java index f2336ee9a3f..871bdf8f300 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/PrunerConfiguration.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerConfiguration.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; public class PrunerConfiguration { public static final int DEFAULT_PRUNING_BLOCKS_RETAINED = 1024; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestWorldStateKeyValueStorage.java similarity index 97% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestWorldStateKeyValueStorage.java index 74051b5e9b7..f53d3e53ce2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestWorldStateKeyValueStorage.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.storage.keyvalue; +package org.hyperledger.besu.ethereum.trie.forest.storage; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.trie.MerkleTrie; @@ -35,13 +35,13 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -public class WorldStateKeyValueStorage implements WorldStateStorage { +public class ForestWorldStateKeyValueStorage implements WorldStateStorage { private final Subscribers nodeAddedListeners = Subscribers.create(); private final KeyValueStorage keyValueStorage; private final ReentrantLock lock = new ReentrantLock(); - public WorldStateKeyValueStorage(final KeyValueStorage keyValueStorage) { + public ForestWorldStateKeyValueStorage(final KeyValueStorage keyValueStorage) { this.keyValueStorage = keyValueStorage; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java similarity index 94% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldState.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java index d50f702af31..e9ba94c1a39 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.worldview; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -24,6 +24,9 @@ import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; +import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; +import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -47,7 +50,7 @@ import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; -public class DefaultMutableWorldState implements MutableWorldState { +public class ForestMutableWorldState implements MutableWorldState { private final EvmConfiguration evmConfiguration; private final WorldStateStorage worldStateStorage; @@ -59,14 +62,14 @@ public class DefaultMutableWorldState implements MutableWorldState { private final Map newStorageKeyPreimages = new HashMap<>(); private final Map newAccountKeyPreimages = new HashMap<>(); - public DefaultMutableWorldState( + public ForestMutableWorldState( final WorldStateStorage storage, final WorldStatePreimageStorage preimageStorage, final EvmConfiguration evmConfiguration) { this(MerkleTrie.EMPTY_TRIE_NODE_HASH, storage, preimageStorage, evmConfiguration); } - public DefaultMutableWorldState( + public ForestMutableWorldState( final Bytes32 rootHash, final WorldStateStorage worldStateStorage, final WorldStatePreimageStorage preimageStorage, @@ -77,12 +80,12 @@ public DefaultMutableWorldState( this.evmConfiguration = evmConfiguration; } - public DefaultMutableWorldState( + public ForestMutableWorldState( final WorldState worldState, final EvmConfiguration evmConfiguration) { // TODO: this is an abstraction leak (and kind of incorrect in that we reuse the underlying // storage), but the reason for this is that the accounts() method is unimplemented below and // can't be until NC-754. - if (!(worldState instanceof DefaultMutableWorldState other)) { + if (!(worldState instanceof ForestMutableWorldState other)) { throw new UnsupportedOperationException(); } @@ -156,7 +159,7 @@ public int hashCode() { @Override public final boolean equals(final Object other) { - if (!(other instanceof DefaultMutableWorldState that)) { + if (!(other instanceof ForestMutableWorldState that)) { return false; } @@ -288,7 +291,7 @@ public Hash getCodeHash() { public UInt256 getStorageValue(final UInt256 key) { return storageTrie() .get(Hash.hash(key)) - .map(DefaultMutableWorldState::convertToUInt256) + .map(ForestMutableWorldState::convertToUInt256) .orElse(UInt256.ZERO); } @@ -332,16 +335,16 @@ private Optional getStorageTrieKeyPreimage(final Bytes32 trieKey) { } protected static class Updater - extends AbstractWorldUpdater { + extends AbstractWorldUpdater { protected Updater( - final DefaultMutableWorldState world, final EvmConfiguration evmConfiguration) { + final ForestMutableWorldState world, final EvmConfiguration evmConfiguration) { super(world, evmConfiguration); } @Override protected WorldStateAccount getForMutation(final Address address) { - final DefaultMutableWorldState wrapped = wrappedWorldView(); + final ForestMutableWorldState wrapped = wrappedWorldView(); final Hash addressHash = address.addressHash(); return wrapped .accountStateTrie @@ -368,7 +371,7 @@ public void revert() { @Override public void commit() { - final DefaultMutableWorldState wrapped = wrappedWorldView(); + final ForestMutableWorldState wrapped = wrappedWorldView(); for (final Address address : getDeletedAccounts()) { final Hash addressHash = address.addressHash(); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java index fc8bfe77fba..514c8821098 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java @@ -14,10 +14,6 @@ */ package org.hyperledger.besu.ethereum.core; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -28,11 +24,15 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -78,9 +78,9 @@ public static MutableBlockchain createInMemoryBlockchain( 0); } - public static DefaultWorldStateArchive createInMemoryWorldStateArchive() { - return new DefaultWorldStateArchive( - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), + public static ForestWorldStateArchive createInMemoryWorldStateArchive() { + return new ForestWorldStateArchive( + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); } @@ -110,7 +110,7 @@ public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive( public static MutableWorldState createInMemoryWorldState() { final InMemoryKeyValueStorageProvider provider = new InMemoryKeyValueStorageProvider(); - return new DefaultMutableWorldState( + return new ForestMutableWorldState( provider.createWorldStateStorage(DataStorageFormat.FOREST), provider.createWorldStatePreimageStorage(), EvmConfiguration.DEFAULT); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryPrivacyStorageProvider.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryPrivacyStorageProvider.java index 91e115cffab..abecd974d87 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryPrivacyStorageProvider.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryPrivacyStorageProvider.java @@ -19,10 +19,10 @@ import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -32,15 +32,15 @@ public class InMemoryPrivacyStorageProvider implements PrivacyStorageProvider { public static WorldStateArchive createInMemoryWorldStateArchive() { - return new DefaultWorldStateArchive( - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), + return new ForestWorldStateArchive( + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); } public static MutableWorldState createInMemoryWorldState() { final InMemoryPrivacyStorageProvider provider = new InMemoryPrivacyStorageProvider(); - return new DefaultMutableWorldState( + return new ForestMutableWorldState( provider.createWorldStateStorage(), provider.createWorldStatePreimageStorage(), EvmConfiguration.DEFAULT); @@ -48,7 +48,7 @@ public static MutableWorldState createInMemoryWorldState() { @Override public WorldStateStorage createWorldStateStorage() { - return new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + return new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); } @Override diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java index 9ee15e0775b..757238a5d86 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java @@ -16,9 +16,9 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java index a33f6a2b04e..f8ac492c93f 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java @@ -23,9 +23,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -44,6 +41,9 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.storage.StorageProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java index 4bc2c6944e2..3e40784ad42 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java @@ -28,20 +28,29 @@ import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; +import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.vm.BlockHashLookup; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; +import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.processor.AbstractMessageProcessor; +import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; +import org.hyperledger.besu.evm.worldstate.WorldView; +import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Mock; @@ -67,6 +76,7 @@ class MainnetTransactionProcessorTest { @Mock private BlockHashLookup blockHashLookup; @Mock private MutableAccount senderAccount; + @Mock private MutableAccount receiverAccount; MainnetTransactionProcessor createTransactionProcessor(final boolean warmCoinbase) { return new MainnetTransactionProcessor( @@ -83,9 +93,9 @@ MainnetTransactionProcessor createTransactionProcessor(final boolean warmCoinbas @Test void shouldWarmCoinbaseIfRequested() { - Optional
toAddresss = + Optional
toAddress = Optional.of(Address.fromHexString("0x2222222222222222222222222222222222222222")); - when(transaction.getTo()).thenReturn(toAddresss); + when(transaction.getTo()).thenReturn(toAddress); Address senderAddress = Address.fromHexString("0x5555555555555555555555555555555555555555"); Address coinbaseAddress = Address.fromHexString("0x4242424242424242424242424242424242424242"); @@ -141,6 +151,81 @@ void shouldWarmCoinbaseIfRequested() { assertThat(coinbaseWarmed).isFalse(); } + @ParameterizedTest + @MethodSource("provideExceptionsForTransactionProcessing") + /* + This test is to ensure that the OperationTracer.traceEndTxCalled is called even if the transaction processing fails. + @param exception will either be of class RuntimeException or MerkleTrieException + */ + void shouldTraceEndTxOnFailingTransaction(final Exception exception) { + Optional
toAddress = + Optional.of(Address.fromHexString("0x2222222222222222222222222222222222222222")); + Address senderAddress = Address.fromHexString("0x5555555555555555555555555555555555555555"); + Address coinbaseAddress = Address.fromHexString("0x4242424242424242424242424242424242424242"); + + when(transaction.getTo()).thenReturn(toAddress); + when(transaction.getHash()).thenReturn(Hash.EMPTY); + when(transaction.getPayload()).thenReturn(Bytes.EMPTY); + when(transaction.getSender()).thenReturn(senderAddress); + when(transaction.getValue()).thenReturn(Wei.ZERO); + when(transactionValidatorFactory.get().validate(any(), any(), any())) + .thenReturn(ValidationResult.valid()); + when(transactionValidatorFactory.get().validateForSender(any(), any(), any())) + .thenReturn(ValidationResult.valid()); + when(worldState.getOrCreateSenderAccount(senderAddress)).thenReturn(senderAccount); + when(worldState.get(toAddress.get())).thenReturn(receiverAccount); + when(worldState.updater()).thenReturn(worldState); + // throw exception when processing the transaction + doAnswer( + invocation -> { + throw exception; + }) + .when(messageCallProcessor) + .process(any(), any()); + + final TraceEndTxTracer tracer = new TraceEndTxTracer(); + var transactionProcessor = createTransactionProcessor(true); + try { + transactionProcessor.processTransaction( + blockchain, + worldState, + blockHeader, + transaction, + coinbaseAddress, + blockHashLookup, + false, + ImmutableTransactionValidationParams.builder().build(), + tracer, + Wei.ZERO); + } catch (final MerkleTrieException e) { + // the MerkleTrieException is thrown again in MainnetTransactionProcessor, we ignore it here + } + + assertThat(tracer.traceEndTxCalled).isTrue(); + } + + // those two exceptions can be thrown while processing a transaction + private static Stream provideExceptionsForTransactionProcessing() { + return Stream.of( + Arguments.of(new MerkleTrieException("")), Arguments.of(new RuntimeException())); + } + + static class TraceEndTxTracer implements OperationTracer { + boolean traceEndTxCalled = false; + + @Override + public void traceEndTransaction( + final WorldView worldView, + final org.hyperledger.besu.datatypes.Transaction tx, + final boolean status, + final Bytes output, + final List logs, + final long gasUsed, + final long timeNs) { + this.traceEndTxCalled = true; + } + } + @Test void shouldCallTransactionValidatorWithExpectedTransactionValidationParams() { final ArgumentCaptor txValidationParamCaptor = diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java index b6357954f53..e9e4bf91563 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -48,7 +48,7 @@ public class WorldStateProofProviderTest { Address.fromHexString("0x1234567890123456789012345678901234567890"); private final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); private WorldStateProofProvider worldStateProofProvider; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateRangeProofProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateRangeProofProviderTest.java index bd4d95321a7..2bea39a8e4b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateRangeProofProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateRangeProofProviderTest.java @@ -18,10 +18,10 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.TrieGenerator; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -42,7 +42,7 @@ public class WorldStateRangeProofProviderTest { Hash.fromHexString("0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); private static final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); private static WorldStateProofProvider worldStateProofProvider; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java similarity index 97% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java index 4f40afdb437..a77c51269d8 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.ArgumentMatchers.any; @@ -32,9 +32,6 @@ import org.hyperledger.besu.ethereum.BlockProcessingResult; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -68,6 +65,9 @@ import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiSnapshotIsolationTests.java similarity index 99% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotIsolationTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiSnapshotIsolationTests.java index 03407d2868f..20e34bb0903 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiSnapshotIsolationTests.java @@ -14,7 +14,7 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateArchiveTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateArchiveTest.java similarity index 93% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateArchiveTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateArchiveTest.java index bfe69546295..6afde3c9400 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateArchiveTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiWorldStateArchiveTest.java @@ -13,13 +13,13 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; -import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.BLOCKCHAIN; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; +import static org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; +import static org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.eq; @@ -31,19 +31,19 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedWorldStorageManager; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogFactoryImpl; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogManager; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.storage.StorageProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedWorldStorageManager; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogFactoryImpl; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogLayer; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogManager; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/CachedMerkleTrieLoaderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/CachedMerkleTrieLoaderTest.java similarity index 97% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/CachedMerkleTrieLoaderTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/CachedMerkleTrieLoaderTest.java index dfb247ee29b..758d7088105 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/CachedMerkleTrieLoaderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/CachedMerkleTrieLoaderTest.java @@ -13,21 +13,21 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/LogRollingTests.java similarity index 96% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/LogRollingTests.java index 225930fdb74..f2dad3bc6ea 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/LogRollingTests.java @@ -14,7 +14,7 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -22,11 +22,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogFactoryImpl; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; @@ -34,6 +29,11 @@ import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogFactoryImpl; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogLayer; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.log.LogsBloomFilter; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/RollingImport.java similarity index 91% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/RollingImport.java index 5aa0f68daa0..af230e436ea 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/RollingImport.java @@ -14,7 +14,7 @@ * */ -package org.hyperledger.besu.ethereum.bonsai; +package org.hyperledger.besu.ethereum.trie.bonsai; import static com.google.common.base.Preconditions.checkArgument; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE; @@ -22,14 +22,14 @@ import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogFactoryImpl; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogFactoryImpl; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogLayer; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java similarity index 99% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java index 13dbe22a403..f6bb51197bb 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java @@ -12,11 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.storage; +package org.hyperledger.besu.ethereum.trie.bonsai.storage; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; +import static org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryTests.java similarity index 97% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryTests.java index 78161826acb..c74fc7e1805 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogFactoryTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryTests.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayerTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayerTests.java similarity index 98% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayerTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayerTests.java index cd45bce5d92..d7d49bace04 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogLayerTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogLayerTests.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import org.hyperledger.besu.datatypes.AccountValue; import org.hyperledger.besu.datatypes.Address; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManagerTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManagerTests.java similarity index 85% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManagerTests.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManagerTests.java index f2fb2224be6..a0065e2cb95 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogManagerTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogManagerTests.java @@ -13,19 +13,19 @@ * SPDX-License-Identifier: Apache-2.0 * */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner.noOpTrieLogPruner; +import static org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner.noOpTrieLogPruner; import static org.mockito.Mockito.spy; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.evm.internal.EvmConfiguration; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPrunerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPrunerTest.java similarity index 98% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPrunerTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPrunerTest.java index 8538edda378..af5acbf18cf 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/trielog/TrieLogPrunerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogPrunerTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.bonsai.trielog; +package org.hyperledger.besu.ethereum.trie.bonsai.trielog; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -23,10 +23,10 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import java.util.Optional; import java.util.stream.Stream; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPrunerTest.java similarity index 95% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPrunerTest.java index 28997591f73..dffc26e1933 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/MarkSweepPrunerTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; @@ -29,10 +29,14 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; +import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -63,9 +67,9 @@ class MarkSweepPrunerTest { private final Map> hashValueStore = spy(new HashMap<>()); private final InMemoryKeyValueStorage stateStorage = new TestInMemoryStorage(hashValueStore); private final WorldStateStorage worldStateStorage = - spy(new WorldStateKeyValueStorage(stateStorage)); + spy(new ForestWorldStateKeyValueStorage(stateStorage)); private final WorldStateArchive worldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( worldStateStorage, new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerTest.java similarity index 99% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerTest.java index 8f1b34bccac..804c805624e 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/pruner/PrunerTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.pruner; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyLong; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageWorldStateStorageTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestKeyValueStorageWorldStateStorageTest.java similarity index 82% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageWorldStateStorageTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestKeyValueStorageWorldStateStorageTest.java index 758866fd6ff..fa57209a00f 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageWorldStateStorageTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/storage/ForestKeyValueStorageWorldStateStorageTest.java @@ -12,37 +12,37 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.storage.keyvalue; +package org.hyperledger.besu.ethereum.trie.forest.storage; import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage.Updater; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage.Updater; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.Test; -public class KeyValueStorageWorldStateStorageTest { +public class ForestKeyValueStorageWorldStateStorageTest { @Test public void getCode_returnsEmpty() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); assertThat(storage.getCode(Hash.EMPTY, null)).contains(Bytes.EMPTY); } @Test public void getAccountStateTrieNode_returnsEmptyNode() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); assertThat(storage.getAccountStateTrieNode(Bytes.EMPTY, MerkleTrie.EMPTY_TRIE_NODE_HASH)) .contains(MerkleTrie.EMPTY_TRIE_NODE); } @Test public void getAccountStorageTrieNode_returnsEmptyNode() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); assertThat( storage.getAccountStorageTrieNode(null, Bytes.EMPTY, MerkleTrie.EMPTY_TRIE_NODE_HASH)) .contains(MerkleTrie.EMPTY_TRIE_NODE); @@ -50,20 +50,20 @@ public void getAccountStorageTrieNode_returnsEmptyNode() { @Test public void getNodeData_returnsEmptyValue() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); assertThat(storage.getNodeData(null, Hash.EMPTY)).contains(Bytes.EMPTY); } @Test public void getNodeData_returnsEmptyNode() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); assertThat(storage.getNodeData(Bytes.EMPTY, MerkleTrie.EMPTY_TRIE_NODE_HASH)) .contains(MerkleTrie.EMPTY_TRIE_NODE); } @Test public void getCode_saveAndGetSpecialValues() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage.updater().putCode(null, MerkleTrie.EMPTY_TRIE_NODE).putCode(null, Bytes.EMPTY).commit(); assertThat(storage.getCode(MerkleTrie.EMPTY_TRIE_NODE_HASH, null)) @@ -74,7 +74,7 @@ public void getCode_saveAndGetSpecialValues() { @Test public void getCode_saveAndGetRegularValue() { final Bytes bytes = Bytes.fromHexString("0x123456"); - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage.updater().putCode(null, bytes).commit(); assertThat(storage.getCode(Hash.hash(bytes), null)).contains(bytes); @@ -82,7 +82,7 @@ public void getCode_saveAndGetRegularValue() { @Test public void getAccountStateTrieNode_saveAndGetSpecialValues() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage .updater() .putAccountStateTrieNode( @@ -98,7 +98,7 @@ public void getAccountStateTrieNode_saveAndGetSpecialValues() { @Test public void getAccountStateTrieNode_saveAndGetRegularValue() { final Bytes bytes = Bytes.fromHexString("0x123456"); - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage.updater().putAccountStateTrieNode(null, Hash.hash(bytes), bytes).commit(); assertThat(storage.getAccountStateTrieNode(Bytes.EMPTY, Hash.hash(bytes))).contains(bytes); @@ -106,7 +106,7 @@ public void getAccountStateTrieNode_saveAndGetRegularValue() { @Test public void getAccountStorageTrieNode_saveAndGetSpecialValues() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage .updater() .putAccountStorageTrieNode( @@ -124,7 +124,7 @@ public void getAccountStorageTrieNode_saveAndGetSpecialValues() { @Test public void getAccountStorageTrieNode_saveAndGetRegularValue() { final Bytes bytes = Bytes.fromHexString("0x123456"); - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage.updater().putAccountStorageTrieNode(null, null, Hash.hash(bytes), bytes).commit(); assertThat(storage.getAccountStateTrieNode(Bytes.EMPTY, Hash.hash(bytes))).contains(bytes); @@ -132,7 +132,7 @@ public void getAccountStorageTrieNode_saveAndGetRegularValue() { @Test public void getNodeData_saveAndGetSpecialValues() { - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage .updater() .putAccountStorageTrieNode( @@ -148,7 +148,7 @@ public void getNodeData_saveAndGetSpecialValues() { @Test public void getNodeData_saveAndGetRegularValue() { final Bytes bytes = Bytes.fromHexString("0x123456"); - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); storage.updater().putAccountStorageTrieNode(null, null, Hash.hash(bytes), bytes).commit(); assertThat(storage.getNodeData(null, Hash.hash(bytes))).contains(bytes); @@ -160,7 +160,7 @@ public void reconcilesNonConflictingUpdaters() { final Bytes bytesB = Bytes.fromHexString("0x1234"); final Bytes bytesC = Bytes.fromHexString("0x123456"); - final WorldStateKeyValueStorage storage = emptyStorage(); + final ForestWorldStateKeyValueStorage storage = emptyStorage(); final Updater updaterA = storage.updater(); final Updater updaterB = storage.updater(); @@ -187,7 +187,7 @@ public void isWorldStateAvailable_emptyTrieStateAlwaysAvailable() { assertThat(emptyStorage().isWorldStateAvailable(Hash.EMPTY_TRIE_HASH, null)).isTrue(); } - private WorldStateKeyValueStorage emptyStorage() { - return new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + private ForestWorldStateKeyValueStorage emptyStorage() { + return new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldStateTest.java similarity index 97% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldStateTest.java index 4e423563416..dec41cd8d60 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldStateTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.forest.worldview; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldState; @@ -21,9 +21,9 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -47,17 +47,17 @@ // TODO: make that an abstract mutable world state test, and create sub-class for all world state // implementations. -class DefaultMutableWorldStateTest { +class ForestMutableWorldStateTest { // The following test cases are loosely derived from the testTransactionToItself // GeneralStateReferenceTest. private static final Address ADDRESS = Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"); - private static MutableWorldState createEmpty(final WorldStateKeyValueStorage storage) { + private static MutableWorldState createEmpty(final ForestWorldStateKeyValueStorage storage) { final WorldStatePreimageKeyValueStorage preimageStorage = new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()); - return new DefaultMutableWorldState(storage, preimageStorage, EvmConfiguration.DEFAULT); + return new ForestMutableWorldState(storage, preimageStorage, EvmConfiguration.DEFAULT); } private static MutableWorldState createEmpty() { @@ -243,7 +243,8 @@ void streamAccounts_multipleAccounts() { @Test void commitAndPersist() { final KeyValueStorage storage = new InMemoryKeyValueStorage(); - final WorldStateKeyValueStorage kvWorldStateStorage = new WorldStateKeyValueStorage(storage); + final ForestWorldStateKeyValueStorage kvWorldStateStorage = + new ForestWorldStateKeyValueStorage(storage); final MutableWorldState worldState = createEmpty(kvWorldStateStorage); final WorldUpdater updater = worldState.updater(); final Wei newBalance = Wei.of(100000); @@ -274,9 +275,9 @@ void commitAndPersist() { // Create new world state and check that it can access modified address final MutableWorldState newWorldState = - new DefaultMutableWorldState( + new ForestMutableWorldState( expectedRootHash, - new WorldStateKeyValueStorage(storage), + new ForestWorldStateKeyValueStorage(storage), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); assertThat(newWorldState.rootHash()).isEqualTo(expectedRootHash); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java index a5af86551bb..1c7da3fd2b6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java @@ -37,7 +37,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutionException; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -67,6 +66,7 @@ public class EthPeers { Comparator.comparing(EthPeer::outstandingRequests) .thenComparing(EthPeer::getLastRequestTimestamp); public static final int NODE_ID_LENGTH = 64; + public static final int USEFULL_PEER_SCORE_THRESHOLD = 102; private final Map completeConnections = new ConcurrentHashMap<>(); @@ -182,9 +182,8 @@ private List getIncompleteConnections(final Bytes id) { } public boolean registerDisconnect(final PeerConnection connection) { - final Bytes id = connection.getPeer().getId(); - final EthPeer peer = completeConnections.get(id); - return registerDisconnect(id, peer, connection); + final EthPeer peer = peer(connection); + return registerDisconnect(peer.getId(), peer, connection); } private boolean registerDisconnect( @@ -197,8 +196,11 @@ private boolean registerDisconnect( disconnectCallbacks.forEach(callback -> callback.onDisconnect(peer)); peer.handleDisconnect(); abortPendingRequestsAssignedToDisconnectedPeers(); - LOG.debug("Disconnected EthPeer {}", peer.getShortNodeId()); - LOG.trace("Disconnected EthPeer {}", peer); + if (peer.getReputation().getScore() > USEFULL_PEER_SCORE_THRESHOLD) { + LOG.debug("Disonnected USEFULL peer {}", peer); + } else { + LOG.debug("Disconnected EthPeer {}", peer.getShortNodeId()); + } } } reattemptPendingPeerRequests(); @@ -220,16 +222,8 @@ private void abortPendingRequestsAssignedToDisconnectedPeers() { } public EthPeer peer(final PeerConnection connection) { - try { - return incompleteConnections.get( - connection, () -> completeConnections.get(connection.getPeer().getId())); - } catch (final ExecutionException e) { - throw new RuntimeException(e); - } - } - - public EthPeer peer(final Bytes peerId) { - return completeConnections.get(peerId); + final EthPeer ethPeer = incompleteConnections.getIfPresent(connection); + return ethPeer != null ? ethPeer : completeConnections.get(connection.getPeer().getId()); } public PendingPeerRequest executePeerRequest( @@ -321,7 +315,9 @@ public Stream streamAvailablePeers() { } public Stream streamBestPeers() { - return streamAvailablePeers().sorted(getBestChainComparator().reversed()); + return streamAvailablePeers() + .filter(EthPeer::isFullyValidated) + .sorted(getBestChainComparator().reversed()); } public Optional bestPeer() { @@ -365,10 +361,10 @@ public Stream getAllConnections() { } public boolean shouldConnect(final Peer peer, final boolean inbound) { - if (peerCount() >= peerUpperBound) { + final Bytes id = peer.getId(); + if (peerCount() >= peerUpperBound && !canExceedPeerLimits(id)) { return false; } - final Bytes id = peer.getId(); final EthPeer ethPeer = completeConnections.get(id); if (ethPeer != null && !ethPeer.isDisconnected()) { return false; @@ -428,8 +424,8 @@ private void ethPeerStatusExchanged(final EthPeer peer) { private int comparePeerPriorities(final EthPeer p1, final EthPeer p2) { final PeerConnection a = p1.getConnection(); final PeerConnection b = p2.getConnection(); - final boolean aCanExceedPeerLimits = canExceedPeerLimits(a); - final boolean bCanExceedPeerLimits = canExceedPeerLimits(b); + final boolean aCanExceedPeerLimits = canExceedPeerLimits(a.getPeer().getId()); + final boolean bCanExceedPeerLimits = canExceedPeerLimits(b.getPeer().getId()); if (aCanExceedPeerLimits && !bCanExceedPeerLimits) { return -1; } else if (bCanExceedPeerLimits && !aCanExceedPeerLimits) { @@ -441,11 +437,11 @@ private int comparePeerPriorities(final EthPeer p1, final EthPeer p2) { } } - private boolean canExceedPeerLimits(final PeerConnection a) { + private boolean canExceedPeerLimits(final Bytes peerId) { if (rlpxAgent == null) { - return true; + return false; } - return rlpxAgent.canExceedConnectionLimits(a.getPeer()); + return rlpxAgent.canExceedConnectionLimits(peerId); } private int compareConnectionInitiationTimes(final PeerConnection a, final PeerConnection b) { @@ -464,7 +460,7 @@ private void enforceRemoteConnectionLimits() { getActivePrioritizedPeers() .filter(p -> p.getConnection().inboundInitiated()) - .filter(p -> !canExceedPeerLimits(p.getConnection())) + .filter(p -> !canExceedPeerLimits(p.getId())) .skip(maxRemotelyInitiatedConnections) .forEach( conn -> { @@ -488,10 +484,9 @@ private void enforceConnectionLimits() { return; } getActivePrioritizedPeers() - .filter(p -> !p.isDisconnected()) .skip(peerUpperBound) .map(EthPeer::getConnection) - .filter(c -> !canExceedPeerLimits(c)) + .filter(c -> !canExceedPeerLimits(c.getPeer().getId())) .forEach( conn -> { LOG.trace( @@ -516,7 +511,7 @@ private long countUntrustedRemotelyInitiatedConnections() { .map(ep -> ep.getConnection()) .filter(c -> c.inboundInitiated()) .filter(c -> !c.isDisconnected()) - .filter(conn -> !canExceedPeerLimits(conn)) + .filter(conn -> !canExceedPeerLimits(conn.getPeer().getId())) .count(); } @@ -542,7 +537,7 @@ private boolean addPeerToEthPeers(final EthPeer peer) { final Bytes id = peer.getId(); if (!randomPeerPriority) { // Disconnect if too many peers - if (!canExceedPeerLimits(connection) && peerCount() >= peerUpperBound) { + if (!canExceedPeerLimits(id) && peerCount() >= peerUpperBound) { LOG.trace( "Too many peers. Disconnect connection: {}, max connections {}", connection, @@ -552,7 +547,7 @@ private boolean addPeerToEthPeers(final EthPeer peer) { } // Disconnect if too many remotely-initiated connections if (connection.inboundInitiated() - && !canExceedPeerLimits(connection) + && !canExceedPeerLimits(id) && remoteConnectionLimitReached()) { LOG.trace( "Too many remotely-initiated connections. Disconnect incoming connection: {}, maxRemote={}", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractRetryingSwitchingPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractRetryingSwitchingPeerTask.java index f9400a6dac6..06c92c76204 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractRetryingSwitchingPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractRetryingSwitchingPeerTask.java @@ -140,7 +140,7 @@ private void refreshPeers() { failedPeers.stream() .filter(peer -> !peer.isDisconnected()) .findAny() - .or(() -> peers.streamAvailablePeers().sorted(peers.getBestChainComparator()).findFirst()) + .or(() -> peers.streamAvailablePeers().min(peers.getBestChainComparator())) .ifPresent( peer -> { LOG.atDebug() diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 2f98c1a8314..46595f6bd0a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -20,7 +20,6 @@ import org.hyperledger.besu.consensus.merge.UnverifiedForkchoiceListener; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.sync.checkpointsync.CheckpointDownloaderFactory; @@ -35,7 +34,8 @@ import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.storage.StorageProvider; -import org.hyperledger.besu.ethereum.worldstate.Pruner; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider; +import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.data.SyncStatus; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiter.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiter.java index 3804f1507ba..8f51cc2d084 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiter.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiter.java @@ -64,7 +64,17 @@ public void enforceTrailingPeerLimit() { while (!trailingPeers.isEmpty() && trailingPeers.size() > maxTrailingPeers) { final EthPeer peerToDisconnect = trailingPeers.remove(0); - LOG.debug("Enforcing trailing peers limit by disconnecting {}", peerToDisconnect); + LOG.atDebug() + .setMessage( + "Enforcing trailing peers limit (min height {}, max trailing peers {}) by disconnecting {}... with height {}") + .addArgument(minimumHeightToBeUpToDate) + .addArgument(maxTrailingPeers) + .addArgument(peerToDisconnect::getShortNodeId) + .addArgument( + peerToDisconnect.chainState() == null + ? "(no chain state)" + : peerToDisconnect.chainState().getEstimatedHeight()) + .log(); peerToDisconnect.disconnect(DisconnectReason.USELESS_PEER); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java index 90aa59c045a..78af77054de 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java @@ -15,11 +15,11 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPOutput; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java index 467dc0a53d0..da520d88b55 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; @@ -29,6 +28,7 @@ import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/StorageTrieNodeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/StorageTrieNodeDataRequest.java index a46faa06a67..1a78eede605 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/StorageTrieNodeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/StorageTrieNodeDataRequest.java @@ -15,9 +15,9 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.rlp.RLPOutput; import org.hyperledger.besu.ethereum.trie.CompactEncoding; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStep.java index df3696ccdf7..9b72d056046 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStep.java @@ -18,9 +18,9 @@ import static org.hyperledger.besu.ethereum.eth.sync.StorageExceptionManager.errorCountAtThreshold; import static org.hyperledger.besu.ethereum.eth.sync.StorageExceptionManager.getRetryableErrorCounter; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.heal.TrieNodeHealingRequest; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.services.tasks.Task; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldStateDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldStateDownloader.java index 91bdd83a0f3..313d5a3770f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldStateDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldStateDownloader.java @@ -19,7 +19,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions; @@ -28,6 +27,7 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.BesuMetricCategory; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java index 06181fd09f1..ea5c25ec0de 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java @@ -22,7 +22,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.StackTrie.FlatDatabaseUpdater.noop; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncProcessState; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState; @@ -31,6 +30,7 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.NodeUpdater; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java index 14839f0ad6f..9829b4ba90b 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java @@ -22,7 +22,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.StackTrie.FlatDatabaseUpdater.noop; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RangeManager; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncProcessState; @@ -31,6 +30,7 @@ import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.NodeUpdater; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java index a40a4fb11a3..7de77607450 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java @@ -19,7 +19,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapsyncMetricsManager.Step.HEAL_FLAT; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RangeManager; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RequestType; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; @@ -32,6 +31,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java index d9297217146..56598c91190 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java @@ -17,7 +17,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest.createAccountTrieNodeDataRequest; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncProcessState; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState; @@ -25,6 +24,7 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequest.java index a94424f023f..ccc3f4453ec 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequest.java @@ -18,7 +18,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.RequestType.STORAGE_RANGE; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RangeManager; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncProcessState; @@ -28,6 +27,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequest.java index ffcdb3e77b7..e6650072a29 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequest.java @@ -15,12 +15,12 @@ package org.hyperledger.besu.ethereum.eth.sync.snapsync.request.heal; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncProcessState; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.trie.CompactEncoding; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java index e30d24c158f..f6ef30667e6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java @@ -50,8 +50,9 @@ default int getTxMessageKeepAliveSeconds() { } enum Implementation { - LEGACY, - LAYERED; + LEGACY, // Remove in future version + LAYERED, + SEQUENCED; // Synonym for LEGACY } String DEFAULT_SAVE_FILE_NAME = "txpool.dump"; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java index 1781428531a..4ebdcb69d4b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java @@ -71,7 +71,7 @@ public void validatePeer_requestBlockFromPeerBeingTested() { final PeerValidator validator = createValidator(blockNumber, 0); - final int peerCount = 1000; + final int peerCount = 24; final List otherPeers = Stream.generate( () -> EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockNumber)) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldDownloadStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldDownloadStateTest.java index b8531288276..91c770d47be 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldDownloadStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldDownloadStateTest.java @@ -20,14 +20,14 @@ import static org.mockito.Mockito.verify; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.eth.manager.task.EthTask; import org.hyperledger.besu.ethereum.eth.sync.worldstate.StalledDownloadException; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloadProcess; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -82,7 +82,7 @@ public void setUp(final DataStorageFormat storageFormat) { new BonsaiWorldStateKeyValueStorage( new InMemoryKeyValueStorageProvider(), new NoOpMetricsSystem()); } else { - worldStateStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + worldStateStorage = new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); } downloadState = new FastWorldDownloadState( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index 6d352abb7a8..8fbe881cfaa 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java @@ -48,13 +48,13 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.Node; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.TrieNodeDecoder; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; @@ -179,7 +179,7 @@ void downloadEmptyWorldState() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateDownloader downloader = createDownloader(ethProtocolManager.ethContext(), localStorage, taskCollection); @@ -196,7 +196,7 @@ void downloadEmptyWorldState() { @Timeout(value = 60) void downloadAlreadyAvailableWorldState() { // Setup existing state - final DefaultWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); + final ForestWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final MutableWorldState worldState = worldStateArchive.getMutable(); // Generate accounts and save corresponding state root @@ -264,7 +264,7 @@ void canRecoverFromTimeouts() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateDownloader downloader = createDownloader(ethProtocolManager.ethContext(), localStorage, taskCollection); @@ -282,7 +282,7 @@ void canRecoverFromTimeouts() { // Check that all expected account data was downloaded final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get(); assertThat(result).isDone(); @@ -319,7 +319,7 @@ void doesNotRequestKnownCodeFromNetwork() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); // Seed local storage with some contract values final Map knownCode = new HashMap<>(); @@ -356,7 +356,7 @@ void doesNotRequestKnownCodeFromNetwork() { // Check that all expected account data was downloaded final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get(); assertThat(result).isDone(); @@ -404,7 +404,7 @@ private void testCancellation(final boolean shouldCancelFuture) { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateDownloader downloader = createDownloader(ethProtocolManager.ethContext(), localStorage, taskCollection); @@ -458,9 +458,9 @@ private void testCancellation(final boolean shouldCancelFuture) { void doesNotRequestKnownAccountTrieNodesFromNetwork() { // Setup "remote" state final WorldStateStorage remoteStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive remoteWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( remoteStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable(); @@ -481,7 +481,7 @@ void doesNotRequestKnownAccountTrieNodesFromNetwork() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); // Seed local storage with some trie node values final Map allNodes = @@ -533,7 +533,7 @@ void doesNotRequestKnownAccountTrieNodesFromNetwork() { // Check that all expected account data was downloaded final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get(); assertThat(result).isDone(); @@ -545,9 +545,9 @@ void doesNotRequestKnownAccountTrieNodesFromNetwork() { void doesNotRequestKnownStorageTrieNodesFromNetwork() { // Setup "remote" state final WorldStateStorage remoteStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive remoteWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( remoteStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable(); @@ -568,7 +568,7 @@ void doesNotRequestKnownStorageTrieNodesFromNetwork() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); // Seed local storage with some trie node values final List storageRootHashes = @@ -638,7 +638,7 @@ void doesNotRequestKnownStorageTrieNodesFromNetwork() { // Check that all expected account data was downloaded final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get(); assertThat(result).isDone(); @@ -653,9 +653,9 @@ void stalledDownloader() { // Setup "remote" state final WorldStateStorage remoteStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive remoteWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( remoteStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable(); @@ -669,7 +669,7 @@ void stalledDownloader() { final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().worldStateMaxRequestsWithoutProgress(10).build(); final WorldStateDownloader downloader = @@ -715,9 +715,9 @@ void stalledDownloader() { void resumesFromNonEmptyQueue() { // Setup "remote" state final WorldStateStorage remoteStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive remoteWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( remoteStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable(); @@ -743,7 +743,7 @@ void resumesFromNonEmptyQueue() { } final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().worldStateMaxRequestsWithoutProgress(10).build(); final WorldStateDownloader downloader = @@ -782,7 +782,7 @@ void resumesFromNonEmptyQueue() { // Check that all expected account data was downloaded assertThat(result).isDone(); final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get(); assertAccountsMatch(localWorldState, accounts); @@ -854,9 +854,9 @@ private void downloadAvailableWorldStateFromPeers( // Setup "remote" state final WorldStateStorage remoteStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive remoteWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( remoteStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable(); @@ -879,9 +879,9 @@ private void downloadAvailableWorldStateFromPeers( final InMemoryTasksPriorityQueues taskCollection = new InMemoryTasksPriorityQueues<>(); final WorldStateStorage localStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateArchive localWorldStateArchive = - new DefaultWorldStateArchive( + new ForestWorldStateArchive( localStorage, createPreimageStorage(), EvmConfiguration.DEFAULT); final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java index ca39d0c86fe..ead7a1ca61e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; @@ -32,6 +31,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredNodeFactory; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/RangeManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/RangeManagerTest.java index 003db79a7e2..d4295f55850 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/RangeManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/RangeManagerTest.java @@ -19,10 +19,10 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -118,7 +118,7 @@ public void testGenerateRangesWithSize3() { public void testFindNewBeginElement() { final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, 15); @@ -157,7 +157,7 @@ public void testFindNewBeginElement() { public void testFindNewBeginElementWhenNothingIsMissing() { final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, 15); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java index 22c2b73765d..a8dc4a9b083 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java @@ -25,7 +25,6 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.chain.BlockAddedEvent; import org.hyperledger.besu.ethereum.chain.BlockAddedObserver; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -39,7 +38,8 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.BytecodeRequest; import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloadProcess; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -110,7 +110,7 @@ public void setUp(final DataStorageFormat storageFormat) { new BonsaiWorldStateKeyValueStorage( new InMemoryKeyValueStorageProvider(), new NoOpMetricsSystem()); } else { - worldStateStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + worldStateStorage = new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); } downloadState = new SnapWorldDownloadState( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/StackTrieTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/StackTrieTest.java index 10a0cf3f84c..a9790b56660 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/StackTrieTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/StackTrieTest.java @@ -17,10 +17,10 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -42,10 +42,10 @@ public void shouldNotSaveTheRootWhenIncomplete() { final int nbAccounts = 15; final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateStorage recreatedWorldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, nbAccounts); @@ -94,10 +94,10 @@ public void shouldSaveTheRootWhenComplete() { final int nbAccounts = 15; final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateStorage recreatedWorldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, nbAccounts); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequestTest.java index a95d4c34114..a61b5c8ea11 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequestTest.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.eth.sync.snapsync.request.heal; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RangeManager; @@ -26,11 +25,12 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; import org.hyperledger.besu.ethereum.storage.StorageProvider; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -73,7 +73,7 @@ public void setup() { @Test public void shouldReturnChildRequests() { final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateProofProvider proofProvider = new WorldStateProofProvider(worldStateStorage); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, 15); @@ -138,7 +138,7 @@ public void shouldReturnChildRequests() { @Test public void shouldNotReturnChildRequestsWhenNoMoreAccounts() { final WorldStateStorage worldStateStorage = - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); final WorldStateProofProvider proofProvider = new WorldStateProofProvider(worldStateStorage); final MerkleTrie accountStateTrie = TrieGenerator.generateTrie(worldStateStorage, 15); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java index a281385dd5b..7fe3862573c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.eth.sync.snapsync.RangeManager; @@ -32,6 +31,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java index 447b37d14ce..5295f4e3b5e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java @@ -16,14 +16,14 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.StorageProvider; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; @@ -70,7 +70,7 @@ public Stream provideArguments(final ExtensionContext conte public void setup(final DataStorageFormat storageFormat) { if (storageFormat.equals(DataStorageFormat.FOREST)) { - worldStateStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()); + worldStateStorage = new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); } else { final StorageProvider storageProvider = new InMemoryKeyValueStorageProvider(); worldStateStorage = diff --git a/ethereum/evmtool/build.gradle b/ethereum/evmtool/build.gradle index 3ed5dbaba72..4bb7c8e985c 100644 --- a/ethereum/evmtool/build.gradle +++ b/ethereum/evmtool/build.gradle @@ -66,7 +66,7 @@ dependencies { testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - // No logging in grallvm EvmTool + // No logging in graalvm EvmTool nativeImageClasspath 'org.slf4j:slf4j-nop' } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BlockchainModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BlockchainModule.java index 0109d6c819a..86f9b5e2cc7 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BlockchainModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BlockchainModule.java @@ -23,9 +23,9 @@ import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -64,12 +64,12 @@ MutableWorldState getMutableWorldState( final EvmConfiguration evmConfiguration) { if ("memory".equals(keyValueStorageName)) { final MutableWorldState mutableWorldState = - new DefaultMutableWorldState( + new ForestMutableWorldState( worldStateStorage, worldStatePreimageStorage, evmConfiguration); genesisState.writeStateTo(mutableWorldState); return mutableWorldState; } else { - return new DefaultMutableWorldState( + return new ForestMutableWorldState( stateRoot, worldStateStorage, worldStatePreimageStorage, evmConfiguration); } } @@ -78,7 +78,7 @@ MutableWorldState getMutableWorldState( @Singleton WorldStateStorage provideWorldStateStorage( @Named("worldState") final KeyValueStorage keyValueStorage) { - return new WorldStateKeyValueStorage(keyValueStorage); + return new ForestWorldStateKeyValueStorage(keyValueStorage); } @Provides diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/DefaultPeerPrivileges.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/DefaultPeerPrivileges.java index 535a49f2ac6..c52b24f61cb 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/DefaultPeerPrivileges.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/DefaultPeerPrivileges.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.p2p.peers; +import org.apache.tuweni.bytes.Bytes; + public class DefaultPeerPrivileges implements PeerPrivileges { private final MaintainedPeers maintainedPeers; @@ -22,7 +24,7 @@ public DefaultPeerPrivileges(final MaintainedPeers maintainedPeers) { } @Override - public boolean canExceedConnectionLimits(final Peer peer) { - return maintainedPeers.contains(peer); + public boolean canExceedConnectionLimits(final Bytes peerId) { + return maintainedPeers.streamPeers().anyMatch(p -> p.getId().equals(peerId)); } } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java index 747a06efdf6..55ca94a1ac3 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java @@ -83,7 +83,9 @@ public static EnodeURL fromString( String message = ""; if (enodeDnsConfiguration.dnsEnabled() && !enodeDnsConfiguration.updateEnabled()) { message = - "Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false."; + String.format( + "Invalid IP address '%s' (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.", + value); } else { message = String.format( diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/PeerPrivileges.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/PeerPrivileges.java index e99b1a39729..6447522e287 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/PeerPrivileges.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/PeerPrivileges.java @@ -14,14 +14,16 @@ */ package org.hyperledger.besu.ethereum.p2p.peers; +import org.apache.tuweni.bytes.Bytes; + public interface PeerPrivileges { /** * If true, the given peer can connect or remain connected even if the max connection limit or the * maximum remote connection limit has been reached or exceeded. * - * @param peer The peer to be checked. + * @param peerId The peer id to be checked. * @return {@code true} if the peer should be allowed to connect regardless of connection limits. */ - boolean canExceedConnectionLimits(final Peer peer); + boolean canExceedConnectionLimits(final Bytes peerId); } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java index 6cf250d715b..98a1f60df37 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java @@ -310,8 +310,8 @@ private CompletableFuture initiateOutboundConnection(final Peer }); } - public boolean canExceedConnectionLimits(final Peer peer) { - return peerPrivileges.canExceedConnectionLimits(peer); + public boolean canExceedConnectionLimits(final Bytes peerId) { + return peerPrivileges.canExceedConnectionLimits(peerId); } private void handleIncomingConnection(final PeerConnection peerConnection) { diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/AbstractPeerConnection.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/AbstractPeerConnection.java index 066f9122cbc..a05d03c7b54 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/AbstractPeerConnection.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/AbstractPeerConnection.java @@ -51,6 +51,7 @@ public abstract class AbstractPeerConnection implements PeerConnection { private final Set agreedCapabilities; private final Map protocolToCapability = new HashMap<>(); private final AtomicBoolean disconnected = new AtomicBoolean(false); + private final AtomicBoolean terminatedImmediately = new AtomicBoolean(false); protected final PeerConnectionEventDispatcher connectionEventDispatcher; private final LabelledMetric outboundMessagesCounter; private final long initiatedAt; @@ -162,17 +163,19 @@ public Set getAgreedCapabilities() { @Override public void terminateConnection(final DisconnectReason reason, final boolean peerInitiated) { - if (disconnected.compareAndSet(false, true)) { - connectionEventDispatcher.dispatchDisconnect(this, reason, peerInitiated); + if (terminatedImmediately.compareAndSet(false, true)) { + if (disconnected.compareAndSet(false, true)) { + connectionEventDispatcher.dispatchDisconnect(this, reason, peerInitiated); + } + // Always ensure the context gets closed immediately even if we previously sent a disconnect + // message and are waiting to close. + closeConnectionImmediately(); + LOG.atTrace() + .setMessage("Terminating connection {}, reason {}") + .addArgument(this) + .addArgument(reason) + .log(); } - // Always ensure the context gets closed immediately even if we previously sent a disconnect - // message and are waiting to close. - closeConnectionImmediately(); - LOG.atTrace() - .setMessage("Terminating connection {}, reason {}") - .addArgument(this) - .addArgument(reason) - .log(); } protected abstract void closeConnectionImmediately(); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestUpdateAccumulator.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestUpdateAccumulator.java index e346b5abf6d..b56053f54af 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestUpdateAccumulator.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestUpdateAccumulator.java @@ -16,11 +16,11 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; -import org.hyperledger.besu.ethereum.bonsai.BonsaiAccount; -import org.hyperledger.besu.ethereum.bonsai.BonsaiValue; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiPreImageProxy; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldView; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiAccount; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiValue; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiPreImageProxy; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldView; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.apache.tuweni.bytes.Bytes; diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldState.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldState.java index e56d5c858f8..26fd811bfae 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldState.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldState.java @@ -16,17 +16,17 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader; -import org.hyperledger.besu.ethereum.bonsai.cache.CachedWorldStorageManager; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiPreImageProxy; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogAddedEvent; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogManager; -import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader; +import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedWorldStorageManager; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiPreImageProxy; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogAddedEvent; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogManager; +import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.metrics.ObservableMetricsSystem; diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldStateStorage.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldStateStorage.java index b998bf7d25b..68057523a08 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldStateStorage.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BonsaiReferenceTestWorldStateStorage.java @@ -16,11 +16,11 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.bonsai.BonsaiAccount; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiPreImageProxy; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateLayerStorage; -import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldView; +import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiAccount; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiPreImageProxy; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateLayerStorage; +import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldView; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.evm.worldstate.WorldState; diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/DefaultReferenceTestWorldState.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/DefaultReferenceTestWorldState.java index 45771578e14..d9ed8626760 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/DefaultReferenceTestWorldState.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/DefaultReferenceTestWorldState.java @@ -15,9 +15,9 @@ package org.hyperledger.besu.ethereum.referencetests; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; +import org.hyperledger.besu.ethereum.trie.forest.worldview.ForestMutableWorldState; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.evm.worldstate.WorldUpdater; @@ -27,12 +27,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; -public class DefaultReferenceTestWorldState extends DefaultMutableWorldState +public class DefaultReferenceTestWorldState extends ForestMutableWorldState implements ReferenceTestWorldState { DefaultReferenceTestWorldState() { super( - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); } diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestBlockchain.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestBlockchain.java index 7e84ccbaf87..cfe577bf7af 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestBlockchain.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestBlockchain.java @@ -191,7 +191,7 @@ public static class NonDeterministicOperationException extends RuntimeException public Comparator getBlockChoiceRule() { return (a, b) -> { throw new NonDeterministicOperationException( - "ReferenceTestBlockchian for VMTest Chains do not support fork choice rules"); + "ReferenceTestBlockchain for VMTest Chains do not support fork choice rules"); }; } diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java index d36a0b6a87d..b2dd41bbfa5 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator; +import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; import org.hyperledger.besu.evm.gascalculator.GasCalculator; @@ -33,6 +34,7 @@ import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; import org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator; +import org.hyperledger.besu.evm.gascalculator.ShanghaiGasCalculator; import org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator; import org.hyperledger.besu.evm.gascalculator.TangerineWhistleGasCalculator; import org.hyperledger.besu.testutil.JsonTestParameters; @@ -54,7 +56,8 @@ private static TransactionValidator transactionValidator(final String name) { return REFERENCE_TEST_PROTOCOL_SCHEDULES .getByName(name) .getByBlockHeader(BlockHeaderBuilder.createDefault().buildBlockHeader()) - .getTransactionValidatorFactory().get(); + .getTransactionValidatorFactory() + .get(); } private static final String TEST_CONFIG_FILE_DIR_PATH = "TransactionTests/"; @@ -62,7 +65,9 @@ private static TransactionValidator transactionValidator(final String name) { public static Stream getTestParametersForConfig() { return JsonTestParameters.create(TransactionTestCaseSpec.class) .generator((name, fullPath, spec, collector) -> collector.add(name, fullPath, spec, true)) - .generate(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> Arguments.of(params[0], params[1])); + .generate(TEST_CONFIG_FILE_DIR_PATH) + .stream() + .map(params -> Arguments.of(params[0], params[1])); } @ParameterizedTest(name = "Name: {0}") @@ -125,8 +130,30 @@ public void london(final String name, final TransactionTestCaseSpec spec) { milestone(spec, name, "London", new LondonGasCalculator(), Optional.of(Wei.of(0))); } + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void merge(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Merge", new LondonGasCalculator(), Optional.of(Wei.of(0))); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void shanghai(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Shanghai", new ShanghaiGasCalculator(), Optional.of(Wei.of(0))); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void cancun(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Cancun", new CancunGasCalculator(), Optional.of(Wei.of(0))); + } + public void milestone( - final TransactionTestCaseSpec spec, final String name, final String milestone, final GasCalculator gasCalculator, final Optional baseFee) { + final TransactionTestCaseSpec spec, + final String name, + final String milestone, + final GasCalculator gasCalculator, + final Optional baseFee) { final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone); diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java index 7f9c3cb7c63..7ce7384e1ab 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Assumptions; /** A Transaction test case specification. */ @JsonIgnoreProperties({"_info"}) @@ -109,9 +110,7 @@ public Bytes getRlp() { public Expectation expectation(final String milestone) { final Expectation expectation = expectations.get(milestone); - if (expectation == null) { - throw new IllegalStateException("Expectation for milestone " + milestone + " not found"); - } + Assumptions.assumeFalse(expectation == null, () -> "No expectation for milestone " + milestone); return expectation; } diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java index a4eff43c98d..b6d01dae83f 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java @@ -16,12 +16,13 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; -import org.assertj.core.api.Assertions; import org.hyperledger.besu.ethereum.rlp.util.RLPTestUtil; import org.hyperledger.besu.testutil.JsonTestParameters; import java.util.stream.Stream; +import org.apache.tuweni.bytes.Bytes; +import org.assertj.core.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -29,23 +30,45 @@ /** The Ethereum reference RLP tests. */ public class RLPRefTest { - private static final String TEST_CONFIG_FILES = "RLPTests/rlptest.json"; + private static final String[] TEST_CONFIG_FILES = { + "RLPTests/rlptest.json", "RLPTests/invalidRLPTest.json" + }; + + private static final Bytes INVALID = Bytes.fromHexString("0x494e56414c4944"); public static Stream getTestParametersForConfig() { - return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream().map(params -> Arguments.of(params[0], params[1], params[2])); + return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream() + .map(params -> Arguments.of(params[0], params[1], params[2])); } @ParameterizedTest(name = "Name: {0}") @MethodSource("getTestParametersForConfig") public void encode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { assumeTrue(runTest, "Test was blacklisted"); - Assertions.assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); + if (!spec.getIn().equals(INVALID)) { + Assertions.assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); + } } @ParameterizedTest(name = "Name: {0}") @MethodSource("getTestParametersForConfig") public void decode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { assumeTrue(runTest, "Test was blacklisted"); - Assertions.assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); + if (spec.getIn().equals(INVALID)) { + Assertions.assertThatThrownBy(() -> RLPTestUtil.decode(spec.getOut())) + .isInstanceOf(RLPException.class); + Assertions.assertThatThrownBy(() -> decode2(RLP.input(spec.getOut()))) + .isInstanceOf(RLPException.class); + } else { + Assertions.assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); + } + } + + private static Object decode2(final RLPInput in) { + if (in.nextIsList()) { + return in.readList(RLPRefTest::decode2); + } else { + return in.readBytes(); + } } } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index 2286fe67cfe..044f61b3b7d 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -59,9 +59,9 @@ import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; +import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -166,8 +166,8 @@ private boolean buildContext( mixHash = Optional.ofNullable(genesisState.getBlock().getHeader().getMixHashOrPrevRandao()); final WorldStateArchive worldStateArchive = - new DefaultWorldStateArchive( - new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), + new ForestWorldStateArchive( + new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), EvmConfiguration.DEFAULT); final MutableWorldState worldState = worldStateArchive.getMutable(); diff --git a/evm/build.gradle b/evm/build.gradle index ed1f65f6e74..9028a3c8d02 100644 --- a/evm/build.gradle +++ b/evm/build.gradle @@ -54,8 +54,6 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } publishing { diff --git a/gradle.properties b/gradle.properties index 3012caabd9d..4cb4c57da2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,5 +17,7 @@ org.gradle.jvmargs=-Xmx4g \ --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \ --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \ --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +# Could be moved to sonar properties after https://sonarsource.atlassian.net/browse/SONARGRADL-134 +systemProp.sonar.gradle.skipCompile=true besu.run.args="--network=linea" \ No newline at end of file diff --git a/gradle/allowed-licenses.json b/gradle/allowed-licenses.json new file mode 100644 index 00000000000..a5d4048b224 --- /dev/null +++ b/gradle/allowed-licenses.json @@ -0,0 +1,65 @@ +{ + "allowedLicenses": [ + { + "moduleLicense": "Apache License, Version 2.0", + "moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0" + }, + { + "moduleLicense": "BSD Zero Clause License", + "moduleLicenseUrl": "https://opensource.org/licenses/0BSD" + }, + { + "moduleLicense" : "The 2-Clause BSD License", + "moduleLicenseUrl" : "https://opensource.org/licenses/BSD-2-Clause" + }, + { + "moduleLicense": "The 3-Clause BSD License", + "moduleLicenseUrl": "https://opensource.org/licenses/BSD-3-Clause" + }, + { + "moduleLicense": "Bouncy Castle Licence", + "moduleLicenseUrl": "https://www.bouncycastle.org/licence.html" + }, + { + "moduleLicense": "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0", + "moduleLicenseUrl": "https://oss.oracle.com/licenses/CDDL" + }, + { + "moduleLicense" : "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.1", + "moduleLicenseUrl" : "https://oss.oracle.com/licenses/CDDL-1.1" + }, + { + "moduleLicense": "Eclipse Distribution License - v 1.0", + "moduleLicenseUrl": "http://www.eclipse.org/legal/epl-v10.html" + }, + { + "moduleLicense": "Eclipse Public License - v 2.0", + "moduleLicenseUrl": "https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt" + }, + { + "moduleLicense": "MIT License", + "moduleLicenseUrl": "https://opensource.org/licenses/MIT" + }, + { + "moduleLicense": "CC0-1.0", + "moduleLicenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/legalcode" + }, + { + "moduleLicense": "Public-Domain" + }, + { + "moduleLicense": "Unicode/ICU License", + "moduleLicenseUrl": "https://raw.githubusercontent.com/unicode-org/icu/main/icu4c/LICENSE" + }, + { + "moduleLicense": "Creative Commons Legal Code", + "moduleVersion": "1.0.3", + "moduleName": "org.reactivestreams:reactive-streams" + }, + { + "moduleLicense": "Eclipse Public License - v 1.0", + "moduleVersion": "4.13.2", + "moduleName": "junit:junit" + } + ] +} \ No newline at end of file diff --git a/gradle/check-licenses.gradle b/gradle/check-licenses.gradle deleted file mode 100644 index 3939c191166..00000000000 --- a/gradle/check-licenses.gradle +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * Check that the licenses of our 3rd parties are in our acceptedLicenses list. - * - * run it with "gradle checkLicenses" - * - * To add new accepted licenses you need to update this script. - * Some products may be available with multiple licenses. In this case you must update - * this script to add it in the downloadLicenses#licenses. - */ - -// Some parts of this code comes from Zipkin/https://github.com/openzipkin/zipkin/pull/852 -// Zipkin itself is under Apache License. - -/** - * The lists of the license we accept. - */ -ext.acceptedLicenses = [ - 'Apache License, Version 2.0', - 'BSD 3-Clause', - 'BSD License', - 'Bouncy Castle Licence', - 'CC0 1.0 Universal License', - 'Common Development and Distribution License 1.0', - 'Eclipse Public License 1.0', - 'Eclipse Public License - v 2.0', - 'MIT License', - 'Mozilla Public License 1.0', - 'Mozilla Public License Version 1.1', - 'Mozilla Public License Version 2.0', - 'Oracle Free Use Terms and Conditions (FUTC)', - 'Public Domain (CC0) License 1.0', - 'Public Domain', - 'Unicode/ICU License', - 'New BSD License' -]*.toLowerCase() - -/** - * This is the configuration we need for our licenses plugin: 'com.github.hierynomus.license' - * This plugin generates a list of dependencies. - */ -downloadLicenses { - includeProjectDependencies = false - reportByDependency = false - reportByLicenseType = true - dependencyConfiguration = 'runtimeClasspath' - excludeDependencies = [ - // only used for static analysis, not actually shipped - 'com.google.code.findbugs:jFormatString:3.0.0', - 'com.google.errorprone:javac:.*', - 'org.checkerframework:dataflow-shaded:.*', - 'org.checkerframework:dataflow-errorprone:.*', - ] - - ext.apache = license('Apache License, Version 2.0', 'http://opensource.org/licenses/Apache-2.0') - ext.bsd = license('BSD License', 'http://www.opensource.org/licenses/bsd-license.php') - ext.bsd3Clause = license('BSD 3-Clause', 'http://opensource.org/licenses/BSD-3-Clause') - ext.cc0 = license('Public Domain (CC0) License 1.0', 'https://creativecommons.org/publicdomain/zero/1.0') - ext.cddl = license('Common Development and Distribution License 1.0', 'http://opensource.org/licenses/CDDL-1.0') - ext.epl1 = license('Eclipse Public License 1.0', 'https://www.eclipse.org/legal/epl-v10.html') - ext.epl2 = license('Eclipse Public License - v 2.0', 'https://www.eclipse.org/legal/epl-v20.html') - ext.mit = license('MIT License', 'http://www.opensource.org/licenses/mit-license.php') - aliases = [ - (apache) : [ - 'Apache 2', - 'Apache 2.0', - 'Apache License 2.0', - 'Apache Software License - Version 2.0', - 'Apache Software License 2.0', - 'Apache v2', - 'Apache-2.0', - 'The Apache License, Version 2.0', - 'The Apache Software License, Version 2.0', - 'The Apache Software License, version 2.0', - license('', 'http://www.apache.org/licenses/LICENSE-2.0.txt') - ], - (bsd) : [ - 'BSD', - 'BSD-2-Clause', - 'BSD licence', - 'The BSD License', - ], - (bsd3Clause) : [ - '3-Clause BSD License', - 'BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)', - 'BSD 3-Clause', - 'BSD Licence 3', - 'BSD License 3', - 'BSD-3-Clause', - 'Eclipse Distribution License - v 1.0', - 'Eclipse Distribution License (New BSD License)', - 'EDL 1.0', - 'New BSD License', - 'The BSD 3-Clause License', - license('', 'http://asm.ow2.org/license.html'), - license('BSD 3-Clause', 'http://www.scala-lang.org/license.html'), - license('BSD 3-clause', 'http://opensource.org/licenses/BSD-3-Clause'), - ], - (cc0) : [ - 'CC0' - ], - (cddl) : [ - 'CDDL 1.0', - 'CDDL 1.1', - 'Common Development and Distribution License (CDDL) v1.0', - 'CDDL + GPLv2 with classpath exception', - ], - (epl1) : [ - 'Eclipse Public License - Version 1.0', - 'Eclipse Public License - v 1.0', - 'Eclipse Public License 1.0 ', - ], - (epl2) : [ - 'Eclipse Public License - v 2.0', - 'Eclipse Public License version 2.0', - 'Eclipse Public License v2.0' - ], - (mit) : [ - 'MIT', - 'The MIT License', - 'The MIT License (MIT)', - 'SPDX-License-Identifier: MIT', - ], - ] - licenses = [ - (group('besu')) : apache, - (group('besu.ethereum.api')) : apache, - (group('besu.consensus')) : apache, - (group('besu.ethereum')) : apache, - (group('besu.metrics')) : apache, - (group('besu.plugins')) : apache, - (group('besu.services')) : apache, - - // JNA is dual licensed under Apache v2.0 or LGPL 2 licenses - // Explicitly declare that we are using the Apache v2.0 license - (group('net.java.dev.jna')) : apache, - - // RocksDB is dual licensed under Apache v2.0 or GPL 2 licenses - // Explicitly declare that we are using the Apache v2.0 license - (group('org.rocksdb')) : apache, - - // Logback is dual licensed under EPL v1.0 or LGPL v2.1 - // Explicitly declare that we are using the EPL v1.0 license - (group('ch.qos.logback')) : epl1, - - // JavaMail, JAXB, Glassfish and Java Servlet are dual licensed under CDDL 1.1 or GPL 2 w/ Classpath Exception - // Explicitly declare that we are using the CDDL 1.1 license - (group('com.sun.mail')) : cddl, - (group('javax.servlet')) : cddl, - (group('javax.xml.bind')) : cddl, - (group('org.glassfish')) : cddl, - - // javax.persistence is dual licensed under EPL 1.0 and EDL 1.0. - // Explicitly declare that we are using the EPL 1.0 license - (group('javax.persistence')) : epl1, - - // jnr-posix is released under a tri EPL v2.0/GPL/LGPL license - 'com.github.jnr:jnr-posix:3.1.15' : epl2, - - // io.netty:netty-tcnative-boringssl-static license markings are not machine readable. - // io.netty:netty-tcnative-classes license markings are not machine readable. - // Explicitly state Apache 2 License for license scanning. - 'io.netty:netty-tcnative-boringssl-static:2.0.46.Final' : apache, - 'io.netty:netty-tcnative-classes:2.0.46.Final' : apache, - - // ANTLR license markings are not all machine readable. - // Explicitly state BSD License for license scanning. - 'org.antlr:antlr-runtime:3.5.2': bsd, - 'org.antlr:ST4:4.3.1': bsd, - ] -} - -task lazyDownloadLicenses() { - if (gradle.startParameter.taskNames.contains('clean') || !file("$rootProject.buildDir/reports/license/license-dependency.xml").exists()) { - dependsOn ':downloadLicenses' - } -} - -task checkLicenses { - description "Verify that all dependencies use accepted licenses." - dependsOn ':lazyDownloadLicenses' - - def bads = "" - doLast { - def xml = new XmlParser().parse("${rootProject.buildDir}/reports/license/license-dependency.xml") - xml.each { license -> - if (!acceptedLicenses.contains((license.@name).toLowerCase())) { - def depStrings = [] - license.dependency.each { depStrings << it.text() } - bads = bads + depStrings + " => ${license.@name} \n" - } - } - if (bads != "") { - throw new GradleException("Some 3rd parties are using licenses not in our accepted licenses list:\n" + - bads + - "If it's a license acceptable for us, add it in the file check-licenses.gradle\n" + - "Be careful, some 3rd parties may accept multiple licenses.\n" + - "In this case, select the one you want to use by changing downloadLicenses.licenses\n" - ) - } - } -} diff --git a/gradle/license-normalizer-bundle.json b/gradle/license-normalizer-bundle.json new file mode 100644 index 00000000000..341b7ab5f62 --- /dev/null +++ b/gradle/license-normalizer-bundle.json @@ -0,0 +1,106 @@ +/** + * Copyright 2018 Evgeny Naumenko + * Copyright Hyperledger Besu contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "bundles" : [ + { "bundleName" : "Apache-1.1", "licenseName" : "Apache Software License, Version 1.1", "licenseUrl" : "https://www.apache.org/licenses/LICENSE-1.1" }, + { "bundleName" : "Apache-2.0", "licenseName" : "Apache License, Version 2.0", "licenseUrl" : "https://www.apache.org/licenses/LICENSE-2.0" }, + { "bundleName" : "0BSD", "licenseName" : "BSD Zero Clause License", "licenseUrl" : "https://opensource.org/licenses/0BSD" }, + { "bundleName" : "BSD-2-Clause", "licenseName" : "The 2-Clause BSD License", "licenseUrl" : "https://opensource.org/licenses/BSD-2-Clause" }, + { "bundleName" : "BSD-3-Clause", "licenseName" : "The 3-Clause BSD License", "licenseUrl" : "https://opensource.org/licenses/BSD-3-Clause" }, + { "bundleName" : "CC0-1.0", "licenseName" : "Creative Commons Legal Code", "licenseUrl" : "https://creativecommons.org/publicdomain/zero/1.0/legalcode" }, + { "bundleName" : "CDDL-1.0", "licenseName" : "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0", "licenseUrl" : "https://oss.oracle.com/licenses/CDDL" }, + { "bundleName" : "CDDL-1.1", "licenseName" : "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.1", "licenseUrl" : "https://oss.oracle.com/licenses/CDDL-1.1" }, + { "bundleName" : "CPL-1.0", "licenseName" : "Common Public License - v 1.0", "licenseUrl" : "https://www.eclipse.org/legal/cpl-v10.html" }, + { "bundleName" : "EPL-1.0", "licenseName" : "Eclipse Public License - v 1.0", "licenseUrl" : "http://www.eclipse.org/legal/epl-v10.html" }, + { "bundleName" : "EPL-2.0", "licenseName" : "Eclipse Public License - v 2.0", "licenseUrl" : "https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt" }, + { "bundleName" : "EDL-1.0", "licenseName" : "Eclipse Distribution License - v 1.0", "licenseUrl" : "https://www.eclipse.org/org/documents/edl-v10.html" }, + { "bundleName" : "GPL-1.0", "licenseName" : "GNU GENERAL PUBLIC LICENSE, Version 1", "licenseUrl" : "https://www.gnu.org/licenses/gpl-1.0" }, + { "bundleName" : "GPL-2.0-only", "licenseName" : "GNU GENERAL PUBLIC LICENSE, Version 2", "licenseUrl" : "https://www.gnu.org/licenses/gpl-2.0" }, + { "bundleName" : "GPL-3.0-only", "licenseName" : "GNU GENERAL PUBLIC LICENSE, Version 3", "licenseUrl" : "https://www.gnu.org/licenses/gpl-3.0" }, + { "bundleName" : "GPL-2.0 WITH Classpath-exception-2.0", "licenseName" : "GNU GENERAL PUBLIC LICENSE, Version 2 + Classpath Exception", "licenseUrl" : "https://openjdk.java.net/legal/gplv2+ce.html" }, + { "bundleName" : "LGPL-2.1-only", "licenseName" : "GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1", "licenseUrl" : "https://www.gnu.org/licenses/lgpl-2.1" }, + { "bundleName" : "LGPL-3.0-only", "licenseName" : "GNU LESSER GENERAL PUBLIC LICENSE, Version 3", "licenseUrl" : "https://www.gnu.org/licenses/lgpl-3.0" }, + { "bundleName" : "MIT", "licenseName" : "MIT License", "licenseUrl" : "https://opensource.org/licenses/MIT" }, + { "bundleName" : "MPL-1.1", "licenseName" : "Mozilla Public License Version 1.1", "licenseUrl" : "https://www.mozilla.org/en-US/MPL/1.1" }, + { "bundleName" : "MPL-2.0", "licenseName" : "Mozilla Public License, Version 2.0", "licenseUrl" : "https://www.mozilla.org/en-US/MPL/2.0" }, + { "bundleName" : "Public-Domain", "licenseName" : "PUBLIC DOMAIN", "licenseUrl" : "" } + ], + "transformationRules" : [ + { "bundleName" : "0BSD", "licenseNamePattern" : "BSD Zero Clause License" }, + { "bundleName" : "0BSD", "licenseNamePattern" : "BSD$" }, + { "bundleName" : "0BSD", "licenseNamePattern" : "BSD( |-)clause.*" }, + { "bundleName" : "0BSD", "licenseNamePattern" : "(The )?BSD( |-)(l|L)icen(s|c)e.*" }, + { "bundleName" : "Apache-2.0", "licenseNamePattern" : ".*The Apache Software License, Version 2\\.0.*" }, + { "bundleName" : "Apache-2.0", "licenseNamePattern" : ".*?Apache( |-|_)2.*" }, + { "bundleName" : "Apache-2.0", "licenseNamePattern" : "ASL 2\\.0" }, + { "bundleName" : "Apache-2.0", "licenseNamePattern" : ".*Apache License,?( Version)? 2.*" }, + { "bundleName" : "Apache-2.0", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/Apache-2\\.0.*" }, + { "bundleName" : "Apache-2.0", "licenseUrlPattern" : ".*www\\.apache\\.org/licenses/LICENSE-2\\.0.*" }, + { "bundleName" : "LGPL-2.1-only", "licenseUrlPattern" : ".*www\\.gnu\\.org/licenses/old-licenses/lgpl-2\\.1\\.html" }, + { "bundleName" : "Apache-2.0", "licenseFileContentPattern" : ".*Apache License,?( Version)? 2.*" }, + { "bundleName" : "Apache-1.1", "licenseFileContentPattern" : ".*Apache Software License, Version 1\\.1.*" }, + { "bundleName" : "CC0-1.0", "licenseNamePattern" : "CC0(( |-)1(\\.0)?)?" }, + { "bundleName" : "CC0-1.0", "licenseUrlPattern" : ".*(www\\.)?creativecommons\\.org/publicdomain/zero/1\\.0/" }, + { "bundleName" : "CDDL-1.0", "licenseFileContentPattern" : ".*CDDL.*1\\.0" }, + { "bundleName" : "CDDL-1.0", "licenseUrlPattern" : ".*CDDL.*.?1\\.0" }, + { "bundleName" : "CDDL-1.1", "licenseUrlPattern" : ".*CDDL.*.?1\\.1" }, + { "bundleName" : "CDDL-1.0", "licenseNamePattern" : "Common Development and Distribution License( \\(CDDL\\),?)? (version )?(.?\\s?)?1\\.0" }, + { "bundleName" : "CDDL-1.1", "licenseNamePattern" : "Common Development and Distribution License( \\(CDDL\\),?)? (version )?(.?\\s?)?1\\.1" }, + { "bundleName" : "BSD-3-Clause", "licenseNamePattern" : ".*BSD( |-)3-clause.*" }, + { "bundleName" : "BSD-3-Clause", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/BSD-3-Clause" }, + { "bundleName" : "BSD-3-Clause", "licenseNamePattern" : ".*?(The )New BSD License.*" }, + { "bundleName" : "BSD-3-Clause", "licenseNamePattern" : ".*?Modified BSD License.*" }, + { "bundleName" : "BSD-2-Clause", "licenseNamePattern" : "BSD( |-)2-clause.*" }, + { "bundleName" : "BSD-2-Clause", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/BSD-2-Clause" }, + { "bundleName" : "BSD-2-Clause", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/bsd-license(\\.php)?" }, + { "bundleName" : "CDDL-1.0", "licenseNamePattern" : "Common Development and Distribution( License)?" }, + { "bundleName" : "CDDL-1.0", "licenseNamePattern" : "CDDL 1(\\.0)" }, + { "bundleName" : "CDDL-1.1", "licenseNamePattern" : "CDDL 1\\.1" }, + { "bundleName" : "CDDL-1.1", "licenseUrlPattern" : ".*(www\\.).opensource\\.org/licenses/CDDL-1\\.0" }, + { "bundleName" : "EPL-1.0", "licenseNamePattern" : "Eclipse Publish License.*(v|version)\\.?\\s?1(\\.?0)?" }, + { "bundleName" : "EPL-1.0", "licenseNamePattern" : "Eclipse Public License.*(v|version)\\.?\\s?1(\\.?0)?" }, + { "bundleName" : "EPL-2.0", "licenseNamePattern" : "Eclipse Public License.*(v|version)\\.?\\s?2(\\.?0)?" }, + { "bundleName" : "EPL-2.0", "licenseUrlPattern" : ".*(www\\.).opensource\\.org/licenses/EPL-2\\.0" }, + { "bundleName" : "EPL-2.0", "licenseUrlPattern" : ".*http.?://www\\.eclipse\\.org/legal/epl-.?2\\.?0.*" }, + { "bundleName" : "EPL-2.0", "licenseUrlPattern" : ".*http.?://www\\.eclipse\\.org/org.*/epl-.?2\\.?0.*" }, + { "bundleName" : "EPL-2.0", "licenseUrlPattern" : ".*http.?://projects\\.eclipse\\.org/.*/epl-.?2\\.?0.*" }, + { "bundleName" : "EDL-1.0", "licenseNamePattern" : "Eclipse Distribution License.*(v|version)\\.?\\s?1(\\.0)?" }, + { "bundleName" : "EDL-1.0", "licenseNamePattern" : "Eclipse Distribution License \\(New BSD License\\)" }, + { "bundleName" : "EDL-1.0", "licenseUrlPattern" : ".*http.?://(www\\.)?eclipse\\.org/org.*/edl-.?1\\.?0.*" }, + { "bundleName" : "GPL-2.0-only", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/GPL-2\\.0" }, + { "bundleName" : "GPL-2.0 WITH Classpath-exception-2.0", "licenseNamePattern" : "GNU General Public License, version 2.*classpath exception" }, + { "bundleName" : "GPL-2.0 WITH Classpath-exception-2.0", "licenseNamePattern" : "GNU General Public License, version 2.*cp?e" }, + { "bundleName" : "GPL-2.0 WITH Classpath-exception-2.0", "licenseNamePattern" : "GNU General Public License, version 2.*, with the classpath exception" }, + { "bundleName" : "GPL-2.0 WITH Classpath-exception-2.0", "licenseNamePattern" : "GPL2 w/ CPE" }, + { "bundleName" : "GPL-3.0-only", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/GPL-3\\.0" }, + { "bundleName" : "LGPL-2.1-only", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/LGPL-2\\.1" }, + { "bundleName" : "LGPL-2.1-only", "licenseUrlPattern" : ".*(www\\.)?gnu\\.org/licenses(/old-licenses)?/lgpl-2\\.1(\\.(html|txt))?" }, + { "bundleName" : "LGPL-2.1-only", "licenseNamePattern" : "LGPL 2\\.1" }, + { "bundleName" : "LGPL-2.1-only", "licenseNamePattern" : "LGPL.*(v|version)\\.?\\s?2\\.1" }, + { "bundleName" : "LGPL-2.1-only", "licenseUrlPattern" : ".*(www\\.)?repository.jboss.org/licenses/lgpl-2.1\\.txt" }, + { "bundleName" : "LGPL-3.0-only", "licenseUrlPattern" : ".*(www\\.).opensource\\.org/licenses/LGPL-3\\.0" }, + { "bundleName" : "LGPL-3.0-only", "licenseNamePattern" : "lgplv?3" }, + { "bundleName" : "LGPL-3.0-only", "licenseUrlPattern" : ".*(www\\.)?gnu\\.org/licenses(/old-licenses)?/lgpl(-3)?(\\.(html|txt))?" }, + { "bundleName" : "MIT", "licenseNamePattern" : "(The\\s)?MIT(\\slicen(c|s)e)?(\\s\\(MIT\\))?" }, + { "bundleName" : "MIT", "licenseUrlPattern" : ".*(www\\.)?opensource\\.org/licenses/MIT(\\.php)?" }, + { "bundleName" : "MPL-1.1", "licenseNamePattern" : "MPL 1\\.1" }, + { "bundleName" : "MPL-2.0", "licenseUrlPattern" : ".*(www\\.).opensource\\.org/licenses/MPL-2\\.0" }, + { "bundleName" : "Public-Domain", "licenseNamePattern" : "((public)\\s(domain)).*", "transformUrl" : false }, + { "bundleName" : "Public-Domain", "licenseFileContentPattern" : ".*(Creative)\\s(Commons).*", "transformUrl" : false }, + { "bundleName" : "Public-Domain", "licenseFileContentPattern" : ".*((Public)\\s(Domain)).*", "transformUrl" : false } + ] +} \ No newline at end of file diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 01ea0e02269..8265a2810c4 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -33,60 +33,54 @@ - - - + + + - - - - - - - - - - + + - - - + + + - - + + - - + + + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + @@ -99,9 +93,14 @@ - - - + + + + + + + + @@ -124,14 +123,19 @@ + + + + + - - - + + + @@ -169,9 +173,19 @@ - - - + + + + + + + + + + + + + @@ -184,12 +198,19 @@ - - - + + + - - + + + + + + + + + @@ -213,6 +234,14 @@ + + + + + + + + @@ -220,17 +249,6 @@ - - - - - - - - - - - @@ -255,8 +273,13 @@ - - + + + + + + + @@ -266,17 +289,6 @@ - - - - - - - - - - - @@ -299,6 +311,14 @@ + + + + + + + + @@ -306,8 +326,13 @@ - - + + + + + + + @@ -317,8 +342,13 @@ - - + + + + + + + @@ -326,6 +356,11 @@ + + + + + @@ -337,17 +372,30 @@ + + + + + + + + - - - + + + - - + + + + + + + @@ -361,9 +409,9 @@ - - - + + + @@ -395,9 +443,17 @@ - - - + + + + + + + + + + + @@ -536,20 +592,27 @@ + + + + + - - - + + + - - + + + + - - + + @@ -563,6 +626,11 @@ + + + + + @@ -571,6 +639,11 @@ + + + + + @@ -640,11 +713,21 @@ + + + + + + + + + + @@ -692,11 +775,6 @@ - - - - - @@ -736,6 +814,11 @@ + + + + + @@ -744,6 +827,11 @@ + + + + + @@ -767,9 +855,6 @@ - - - @@ -779,6 +864,11 @@ + + + + + @@ -811,14 +901,6 @@ - - - - - - - - @@ -827,6 +909,11 @@ + + + + + @@ -835,6 +922,11 @@ + + + + + @@ -855,9 +947,9 @@ - - - + + + @@ -868,6 +960,11 @@ + + + + + @@ -876,6 +973,14 @@ + + + + + + + + @@ -900,6 +1005,14 @@ + + + + + + + + @@ -918,6 +1031,11 @@ + + + + + @@ -931,14 +1049,6 @@ - - - - - - - - @@ -947,21 +1057,45 @@ + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + @@ -1139,12 +1273,12 @@ - - - + + + - - + + @@ -1155,6 +1289,14 @@ + + + + + + + + @@ -1166,14 +1308,6 @@ - - - - - - - - @@ -1190,9 +1324,9 @@ - - - + + + @@ -1237,6 +1371,11 @@ + + + + + @@ -1260,9 +1399,6 @@ - - - @@ -1272,6 +1408,22 @@ + + + + + + + + + + + + + + + + @@ -1305,6 +1457,14 @@ + + + + + + + + @@ -1313,6 +1473,19 @@ + + + + + + + + + + + + + @@ -1325,8 +1498,10 @@ - - + + + + @@ -1340,35 +1515,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - + + @@ -1379,6 +1531,14 @@ + + + + + + + + @@ -1395,17 +1555,9 @@ - - - - - - - - - - - + + + @@ -1424,6 +1576,14 @@ + + + + + + + + @@ -1432,6 +1592,11 @@ + + + + + @@ -1453,6 +1618,11 @@ + + + + + @@ -1461,6 +1631,11 @@ + + + + + @@ -1474,19 +1649,6 @@ - - - - - - - - - - - - - @@ -1495,6 +1657,11 @@ + + + + + @@ -1543,6 +1710,11 @@ + + + + + @@ -1567,6 +1739,11 @@ + + + + + @@ -1639,6 +1816,11 @@ + + + + + @@ -1679,6 +1861,11 @@ + + + + + @@ -1692,6 +1879,11 @@ + + + + + @@ -1708,6 +1900,16 @@ + + + + + + + + + + @@ -1935,6 +2137,11 @@ + + + + + @@ -1945,6 +2152,11 @@ + + + + + @@ -2057,6 +2269,11 @@ + + + + + @@ -2071,6 +2288,11 @@ + + + + + @@ -2079,6 +2301,11 @@ + + + + + @@ -2138,6 +2365,14 @@ + + + + + + + + @@ -2193,6 +2428,14 @@ + + + + + + + + @@ -2215,6 +2458,14 @@ + + + + + + + + @@ -2226,6 +2477,14 @@ + + + + + + + + @@ -2248,6 +2507,14 @@ + + + + + + + + @@ -2281,6 +2548,14 @@ + + + + + + + + @@ -2292,6 +2567,14 @@ + + + + + + + + @@ -2303,6 +2586,14 @@ + + + + + + + + @@ -2310,9 +2601,6 @@ - - - @@ -2321,9 +2609,6 @@ - - - @@ -2332,8 +2617,13 @@ - - + + + + + + + @@ -2343,8 +2633,13 @@ - - + + + + + + + @@ -2455,6 +2750,11 @@ + + + + + @@ -2463,6 +2763,11 @@ + + + + + @@ -2479,6 +2784,11 @@ + + + + + @@ -2495,6 +2805,11 @@ + + + + + @@ -2519,17 +2834,19 @@ - - - + + + + + - - - + + + - - + + @@ -2686,6 +3003,16 @@ + + + + + + + + + + @@ -2702,6 +3029,11 @@ + + + + + @@ -2710,6 +3042,11 @@ + + + + + @@ -2720,6 +3057,11 @@ + + + + + @@ -2738,6 +3080,11 @@ + + + + + @@ -2772,6 +3119,11 @@ + + + + + @@ -2788,6 +3140,11 @@ + + + + + @@ -2796,6 +3153,11 @@ + + + + + @@ -2809,6 +3171,11 @@ + + + + + @@ -2880,17 +3247,17 @@ - - - + + + - - + + - - - + + + @@ -2945,6 +3312,11 @@ + + + + + @@ -2966,25 +3338,22 @@ - - - - - - + + + - - - + + + - - - + + + - - + + @@ -3077,6 +3446,11 @@ + + + + + @@ -3085,6 +3459,11 @@ + + + + + @@ -3095,6 +3474,11 @@ + + + + + @@ -3120,9 +3504,14 @@ - - - + + + + + + + + @@ -3143,14 +3532,6 @@ - - - - - - - - @@ -3159,6 +3540,19 @@ + + + + + + + + + + + + + @@ -3175,9 +3569,9 @@ - - - + + + @@ -3188,8 +3582,16 @@ - - + + + + + + + + + + @@ -3208,6 +3610,11 @@ + + + + + @@ -3218,11 +3625,6 @@ - - - - - @@ -3238,6 +3640,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -3254,6 +3676,19 @@ + + + + + + + + + + + + + @@ -3262,14 +3697,22 @@ + + + + + + + + - - - + + + @@ -3277,9 +3720,9 @@ - - - + + + @@ -3292,14 +3735,6 @@ - - - - - - - - @@ -3308,14 +3743,12 @@ - - - + + + - - - - + + @@ -3352,12 +3785,12 @@ - - - + + + - - + + @@ -3365,11 +3798,21 @@ + + + + + + + + + + @@ -3378,11 +3821,21 @@ + + + + + + + + + + @@ -3391,6 +3844,11 @@ + + + + + @@ -3399,6 +3857,11 @@ + + + + + @@ -3407,6 +3870,11 @@ + + + + + @@ -3536,6 +4004,11 @@ + + + + + @@ -3560,6 +4033,11 @@ + + + + + @@ -3592,6 +4070,14 @@ + + + + + + + + @@ -3603,14 +4089,6 @@ - - - - - - - - @@ -3619,27 +4097,11 @@ - - - - - - - - - - - - - - - - @@ -3741,6 +4203,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3950,12 +4468,12 @@ - - - + + + - - + + @@ -3963,9 +4481,25 @@ - - - + + + + + + + + + + + + + + + + + + + @@ -3984,14 +4518,44 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + @@ -4026,6 +4590,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4034,6 +4806,14 @@ + + + + + + + + @@ -4042,6 +4822,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4058,6 +4902,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -4066,6 +4934,22 @@ + + + + + + + + + + + + + + + + @@ -4074,6 +4958,22 @@ + + + + + + + + + + + + + + + + @@ -4082,14 +4982,108 @@ - - - + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4100,6 +5094,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4113,6 +5203,11 @@ + + + + + @@ -4141,8 +5236,13 @@ - - + + + + + + + @@ -4166,6 +5266,11 @@ + + + + + @@ -4277,11 +5382,21 @@ + + + + + + + + + + @@ -4290,6 +5405,11 @@ + + + + + @@ -4361,6 +5481,11 @@ + + + + + @@ -4398,6 +5523,14 @@ + + + + + + + + @@ -4414,6 +5547,22 @@ + + + + + + + + + + + + + + + + @@ -4440,6 +5589,14 @@ + + + + + + + + @@ -4534,9 +5691,6 @@ - - - @@ -4576,44 +5730,60 @@ - - - + + + + + + + + + + + + + + + + + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + @@ -4672,6 +5842,22 @@ + + + + + + + + + + + + + + + + @@ -4683,6 +5869,14 @@ + + + + + + + + @@ -4702,6 +5896,14 @@ + + + + + + + + @@ -4721,6 +5923,14 @@ + + + + + + + + @@ -4758,23 +5968,12 @@ - - - - - - - - - - - @@ -4782,9 +5981,6 @@ - - - @@ -4812,9 +6008,6 @@ - - - @@ -4829,14 +6022,6 @@ - - - - - - - - @@ -4844,23 +6029,12 @@ - - - - - - - - - - - @@ -4868,8 +6042,13 @@ - - + + + + + + + @@ -4887,15 +6066,17 @@ - - - + + + + + @@ -4904,6 +6085,11 @@ + + + + + @@ -4912,11 +6098,21 @@ + + + + + + + + + + @@ -4930,6 +6126,11 @@ + + + + + @@ -4938,6 +6139,11 @@ + + + + + @@ -4959,6 +6165,14 @@ + + + + + + + + @@ -4967,6 +6181,11 @@ + + + + + @@ -4983,6 +6202,11 @@ + + + + + @@ -4996,6 +6220,11 @@ + + + + + @@ -5144,6 +6373,11 @@ + + + + + @@ -5152,6 +6386,14 @@ + + + + + + + + @@ -5160,6 +6402,16 @@ + + + + + + + + + + @@ -5168,19 +6420,34 @@ + + + + + + + + + + - - - + + + + + + + + @@ -5201,12 +6468,12 @@ - - - + + + - - + + @@ -5274,6 +6541,14 @@ + + + + + + + + @@ -5290,6 +6565,14 @@ + + + + + + + + @@ -5298,11 +6581,24 @@ + + + + + + + + + + + + + @@ -5319,6 +6615,11 @@ + + + + + @@ -5327,6 +6628,11 @@ + + + + + @@ -5359,6 +6665,11 @@ + + + + + @@ -5375,6 +6686,11 @@ + + + + + @@ -5383,6 +6699,11 @@ + + + + + @@ -5465,6 +6786,11 @@ + + + + + @@ -5473,6 +6799,11 @@ + + + + + @@ -5529,6 +6860,14 @@ + + + + + + + + @@ -5540,13 +6879,5 @@ - - - - - - - - diff --git a/nat/build.gradle b/nat/build.gradle index f6c814ad113..ec2fd3a3f09 100644 --- a/nat/build.gradle +++ b/nat/build.gradle @@ -45,6 +45,4 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/pki/build.gradle b/pki/build.gradle index 8e2f52a4735..cb6aaf8b861 100644 --- a/pki/build.gradle +++ b/pki/build.gradle @@ -37,8 +37,6 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } configurations { testArtifacts } diff --git a/settings.gradle b/settings.gradle index 3a1c245a7f6..15a0f8617d6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,18 +16,6 @@ pluginManagement { repositories { - /* - * Temporary repository to host the improved version of the - * com.github.hierynomus.license plugin. Can be removed when an - * official version with the fix is release upstream - */ - maven { - url = uri('https://raw.githubusercontent.com/ConsenSys/license-gradle-plugin-fix-artifacts/main/') - content { - includeGroup('com.github.hierynomus.license') - includeGroup('com.hierynomus.gradle.plugins') - } - } gradlePluginPortal() } } diff --git a/util/build.gradle b/util/build.gradle index 844d5f835f3..d9bca73449e 100644 --- a/util/build.gradle +++ b/util/build.gradle @@ -42,6 +42,4 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' }