From 42d69d89cec9888ae1f8cd34adc21247b28a450a Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 31 Oct 2018 10:05:52 +1000 Subject: [PATCH] Decouple DefaultMutableBlockchain from KeyValueStorage (#211) * Introduce createInMemoryBlockchain test utility and use it everywhere appropriate. * Inject BlockchainStorage into DefaultMutableBlockchain. --- .../clique/NodeCanProduceNextBlockTest.java | 43 +++--------- .../consensus/clique/VoteTallyCacheTest.java | 13 ++-- .../blockcreation/CliqueBlockCreatorTest.java | 14 ++-- .../blockcreation/IbftBlockCreatorTest.java | 2 +- .../vm/EntriesFromIntegrationTest.java | 2 +- .../vm/TraceTransactionIntegrationTest.java | 15 ++--- .../ethereum/db/DefaultMutableBlockchain.java | 11 +--- .../core/ExecutionContextTestFixture.java | 5 +- ...rldState.java => InMemoryTestFixture.java} | 18 ++++- .../ethereum/core/TransactionPoolTest.java | 12 +--- .../db/DefaultMutableBlockchainTest.java | 66 ++++++++----------- .../ethereum/db/GenesisBlockMismatchTest.java | 5 +- .../ethereum/testutil/BlockDataGenerator.java | 2 +- .../util/BlockchainUtilParameterizedTest.java | 22 ++----- .../vm/BlockchainReferenceTestCaseSpec.java | 8 +-- .../eth/manager/EthProtocolManagerTest.java | 10 +-- .../manager/EthProtocolManagerTestUtil.java | 12 +--- .../ethtaskutils/BlockchainSetupUtil.java | 27 ++------ .../ethereum/eth/sync/DownloaderTest.java | 10 +-- ...neCommonAncestorTaskParameterizedTest.java | 23 ++----- .../DetermineCommonAncestorTaskTest.java | 35 +++------- .../eth/sync/tasks/ImportBlocksTaskTest.java | 10 +-- .../PipelinedImportChainSegmentTaskTest.java | 10 +-- .../ethereum/eth/transactions/TestNode.java | 9 +-- .../jsonrpc/JsonRpcTestMethodsFactory.java | 13 +--- .../EthGetFilterChangesIntegrationTest.java | 13 +--- .../AbstractEthJsonRpcHttpServiceTest.java | 11 +--- .../queries/BlockchainQueriesTest.java | 11 +--- .../controller/CliquePantheonController.java | 8 ++- .../controller/IbftPantheonController.java | 7 +- .../controller/MainnetPantheonController.java | 7 +- 31 files changed, 159 insertions(+), 295 deletions(-) rename ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/{InMemoryWorldState.java => InMemoryTestFixture.java} (53%) diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java index b296d00ff0..e560f8b0ec 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java @@ -23,6 +23,7 @@ import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.consensus.common.VoteTally; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.ProtocolContext; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.AddressHelpers; import tech.pegasys.pantheon.ethereum.core.Block; @@ -30,11 +31,8 @@ import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.Util; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import java.util.List; @@ -51,7 +49,7 @@ public class NodeCanProduceNextBlockTest { private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); private ProtocolContext cliqueProtocolContext; - DefaultMutableBlockchain blockChain; + MutableBlockchain blockChain; private Block genesisBlock; private Block createEmptyBlock(final KeyPair blockSigner) { @@ -72,10 +70,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(proposerKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -100,10 +95,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(otherNodeKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -137,10 +129,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(proposerKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -170,10 +159,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(proposerKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -218,10 +204,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(proposerKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -250,10 +233,7 @@ public class NodeCanProduceNextBlockTest { genesisBlock = createEmptyBlock(proposerKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); @@ -277,10 +257,7 @@ public class NodeCanProduceNextBlockTest { public void nonValidatorIsNotAllowedToCreateABlock() { genesisBlock = createEmptyBlock(otherNodeKeyPair); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java index 1d93e27612..cee3be4686 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java @@ -23,16 +23,14 @@ import static org.mockito.Mockito.verifyZeroInteractions; import tech.pegasys.pantheon.consensus.common.EpochManager; import tech.pegasys.pantheon.crypto.SECP256K1.Signature; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.AddressHelpers; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.math.BigInteger; @@ -54,7 +52,7 @@ public class VoteTallyCacheTest { headerBuilder.buildHeader(), new BlockBody(Lists.emptyList(), Lists.emptyList())); } - DefaultMutableBlockchain blockChain; + MutableBlockchain blockChain; private Block genesisBlock; private Block block_1; private Block block_2; @@ -69,11 +67,8 @@ public class VoteTallyCacheTest { .encode()); genesisBlock = createEmptyBlock(0, Hash.ZERO); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockChain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash()); block_2 = createEmptyBlock(1, block_1.getHeader().getHash()); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index 82e1afedcc..a9c8314830 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -16,6 +16,8 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.consensus.clique.CliqueContext; import tech.pegasys.pantheon.consensus.clique.CliqueExtraData; @@ -39,13 +41,8 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.PendingTransactions; import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Wei; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MutableProtocolSchedule; -import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.List; @@ -62,11 +59,8 @@ public class CliqueBlockCreatorTest { private final List
validatorList = Lists.newArrayList(); private final Block genesis = GenesisConfig.mainnet().getBlock(); - private final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - private final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesis, keyValueStorage, MainnetBlockHashFunction::createHash); - private final WorldStateArchive stateArchive = - new WorldStateArchive(new KeyValueStorageWorldStateStorage(keyValueStorage)); + private final MutableBlockchain blockchain = createInMemoryBlockchain(genesis); + private final WorldStateArchive stateArchive = createInMemoryWorldStateArchive(); private ProtocolContext protocolContext; private final MutableProtocolSchedule protocolSchedule = diff --git a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java index c8a5ab34d5..924f8902cf 100644 --- a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.consensus.common.VoteTally; diff --git a/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java b/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java index 179c9c0496..ff9f8220f2 100644 --- a/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java +++ b/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java @@ -13,7 +13,7 @@ package tech.pegasys.pantheon.ethereum.vm; import static org.assertj.core.api.Assertions.assertThat; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; diff --git a/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/TraceTransactionIntegrationTest.java b/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/TraceTransactionIntegrationTest.java index 756738d19d..7a8b818fd3 100644 --- a/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/TraceTransactionIntegrationTest.java +++ b/ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/TraceTransactionIntegrationTest.java @@ -14,6 +14,8 @@ package tech.pegasys.pantheon.ethereum.vm; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.chain.GenesisConfig; @@ -26,18 +28,13 @@ import tech.pegasys.pantheon.ethereum.core.MutableWorldState; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.WorldUpdater; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.debug.TraceFrame; import tech.pegasys.pantheon.ethereum.debug.TraceOptions; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.TransactionProcessor; import tech.pegasys.pantheon.ethereum.mainnet.TransactionProcessor.Result; import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPInput; -import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; @@ -68,12 +65,8 @@ public class TraceTransactionIntegrationTest { public void setUp() { final GenesisConfig genesisConfig = GenesisConfig.development(); genesisBlock = genesisConfig.getBlock(); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockchain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); - worldStateArchive = - new WorldStateArchive(new KeyValueStorageWorldStateStorage(keyValueStorage)); + blockchain = createInMemoryBlockchain(genesisBlock); + worldStateArchive = createInMemoryWorldStateArchive(); final ProtocolSchedule protocolSchedule = genesisConfig.getProtocolSchedule(); genesisConfig.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); transactionProcessor = protocolSchedule.getByBlockNumber(0).getTransactionProcessor(); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchain.java index 5cad3d740f..b54574b720 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchain.java @@ -24,13 +24,11 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.TransactionLocation; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; -import tech.pegasys.pantheon.ethereum.core.BlockHashFunction; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.ethereum.util.InvalidConfigurationException; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.uint.UInt256; @@ -53,12 +51,9 @@ public class DefaultMutableBlockchain implements MutableBlockchain { private final Subscribers blockAddedObservers = new Subscribers<>(); public DefaultMutableBlockchain( - final Block genesisBlock, - final KeyValueStorage keyValueStorage, - final BlockHashFunction blockHashFunction) { - checkArgument(genesisBlock != null, "Missing required KeyValueStorage"); - this.blockchainStorage = - new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHashFunction); + final Block genesisBlock, final BlockchainStorage blockchainStorage) { + checkNotNull(genesisBlock); + this.blockchainStorage = blockchainStorage; this.setGenesis(genesisBlock); } diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java index 28ca603e35..9927433114 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java @@ -16,6 +16,7 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.chain.GenesisConfig; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.KeyValueStoragePrefixedKeyBlockchainStorage; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; @@ -42,7 +43,9 @@ public class ExecutionContextTestFixture { this.keyValueStorage = keyValueStorage; this.blockchain = new DefaultMutableBlockchain( - genesis, keyValueStorage, MainnetBlockHashFunction::createHash); + genesis, + new KeyValueStoragePrefixedKeyBlockchainStorage( + keyValueStorage, MainnetBlockHashFunction::createHash)); this.stateArchive = new WorldStateArchive(new KeyValueStorageWorldStateStorage(keyValueStorage)); this.protocolSchedule = protocolSchedule; diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryWorldState.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryTestFixture.java similarity index 53% rename from ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryWorldState.java rename to ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryTestFixture.java index b9df0d7fdd..b3f621294c 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryWorldState.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryTestFixture.java @@ -12,11 +12,27 @@ */ package tech.pegasys.pantheon.ethereum.core; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.KeyValueStoragePrefixedKeyBlockchainStorage; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; +import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -public class InMemoryWorldState { +public class InMemoryTestFixture { + + public static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { + return createInMemoryBlockchain(genesisBlock, MainnetBlockHashFunction::createHash); + } + + public static MutableBlockchain createInMemoryBlockchain( + final Block genesisBlock, final BlockHashFunction blockHashFunction) { + final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); + return new DefaultMutableBlockchain( + genesisBlock, + new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHashFunction)); + } public static WorldStateArchive createInMemoryWorldStateArchive() { return new WorldStateArchive( diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java index 03998d8019..ff9aa88cc5 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java @@ -28,7 +28,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason.EXCEEDS_BLOCK_GAS_LIMIT; import static tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason.NONCE_TOO_LOW; import static tech.pegasys.pantheon.ethereum.mainnet.ValidationResult.valid; @@ -38,15 +39,11 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.chain.GenesisConfig; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.TransactionPool.TransactionBatchAddedListener; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator; import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.List; @@ -82,10 +79,7 @@ public class TransactionPoolTest { public void setUp() { final GenesisConfig genesisConfig = GenesisConfig.development(); final Block genesisBlock = genesisConfig.getBlock(); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockchain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockchain = createInMemoryBlockchain(genesisBlock); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final ProtocolContext protocolContext = new ProtocolContext<>(blockchain, worldStateArchive, null); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java index 68d6e0a944..dbc9973177 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java @@ -46,8 +46,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); assertBlockIsHead(blockchain, genesisBlock); @@ -62,12 +61,10 @@ public class DefaultMutableBlockchainTest { // Write to kv store final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + createBlockchain(kvStore, genesisBlock); // Initialize a new blockchain store with kvStore that already contains data - blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); assertBlockIsHead(blockchain, genesisBlock); @@ -82,10 +79,10 @@ public class DefaultMutableBlockchainTest { // Write to kv store final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + createBlockchain(kvStore, genesisBlock); // Initialize a new blockchain store with same kvStore, but different genesis block - new DefaultMutableBlockchain(gen.genesisBlock(), kvStore, MainnetBlockHashFunction::createHash); + createBlockchain(kvStore, gen.genesisBlock()); } @Test @@ -94,8 +91,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -114,8 +110,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(Hash.ZERO); final Block newBlock = gen.block(options); @@ -129,8 +124,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -148,8 +142,7 @@ public class DefaultMutableBlockchainTest { chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -174,8 +167,7 @@ public class DefaultMutableBlockchainTest { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -232,8 +224,7 @@ public class DefaultMutableBlockchainTest { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -331,8 +322,7 @@ public class DefaultMutableBlockchainTest { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -421,8 +411,7 @@ public class DefaultMutableBlockchainTest { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -475,8 +464,7 @@ public class DefaultMutableBlockchainTest { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -553,8 +541,7 @@ public class DefaultMutableBlockchainTest { final BlockDataGenerator gen = new BlockDataGenerator(); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); assertThat(blockchain.removeObserver(7)).isFalse(); } @@ -565,8 +552,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final long observerId = blockchain.observeBlockAdded((block, chain) -> {}); assertThat(blockchain.observerCount()).isEqualTo(1); @@ -581,8 +567,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); blockchain.observeBlockAdded(null); } @@ -593,8 +578,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final long observerId1 = blockchain.observeBlockAdded((block, chain) -> {}); assertThat(blockchain.observerCount()).isEqualTo(1); @@ -621,8 +605,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -646,8 +629,7 @@ public class DefaultMutableBlockchainTest { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -724,4 +706,12 @@ public class DefaultMutableBlockchainTest { // Check reported chainhead td assertEquals(td, blockchain.getChainHead().getTotalDifficulty()); } + + private DefaultMutableBlockchain createBlockchain( + final KeyValueStorage kvStore, final Block genesisBlock) { + return new DefaultMutableBlockchain( + genesisBlock, + new KeyValueStoragePrefixedKeyBlockchainStorage( + kvStore, MainnetBlockHashFunction::createHash)); + } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java index b36ca47889..77f89fef85 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java @@ -61,7 +61,10 @@ public class GenesisBlockMismatchTest { final BlockBody genesisBody00 = new BlockBody(Collections.emptyList(), Collections.emptyList()); final Block genesisBlock00 = new Block(genesisHeader00, genesisBody00); final DefaultMutableBlockchain blockchain00 = - new DefaultMutableBlockchain(genesisBlock00, kvStore, MainnetBlockHashFunction::createHash); + new DefaultMutableBlockchain( + genesisBlock00, + new KeyValueStoragePrefixedKeyBlockchainStorage( + kvStore, MainnetBlockHashFunction::createHash)); final BlockHeader genesisHeader01 = BlockHeaderBuilder.create() diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java index 04b64ff12d..6ce404dbae 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java @@ -13,7 +13,7 @@ package tech.pegasys.pantheon.ethereum.testutil; import static com.google.common.base.Preconditions.checkArgument; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.core.Address; diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java index e5939a5df1..246d027512 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java @@ -14,15 +14,13 @@ package tech.pegasys.pantheon.ethereum.util; import static org.assertj.core.api.Assertions.assertThat; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.ArrayList; @@ -46,11 +44,9 @@ public class BlockchainUtilParameterizedTest { private static final int chainHeight = 89; private final int commonAncestorHeight; private static Block genesisBlock; - private static KeyValueStorage localKvStore; - private static DefaultMutableBlockchain localBlockchain; + private static MutableBlockchain localBlockchain; - private KeyValueStorage remoteKvStore; - private DefaultMutableBlockchain remoteBlockchain; + private MutableBlockchain remoteBlockchain; private BlockHeader commonHeader; private List headers; @@ -62,10 +58,7 @@ public class BlockchainUtilParameterizedTest { @BeforeClass public static void setupClass() { genesisBlock = blockDataGenerator.genesisBlock(); - localKvStore = new InMemoryKeyValueStorage(); - localBlockchain = - new DefaultMutableBlockchain( - genesisBlock, localKvStore, MainnetBlockHashFunction::createHash); + localBlockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); // Setup local chain. for (int i = 1; i <= chainHeight; i++) { final BlockDataGenerator.BlockOptions options = @@ -80,10 +73,7 @@ public class BlockchainUtilParameterizedTest { @Before public void setup() { - remoteKvStore = new InMemoryKeyValueStorage(); - remoteBlockchain = - new DefaultMutableBlockchain( - genesisBlock, remoteKvStore, MainnetBlockHashFunction::createHash); + remoteBlockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); commonHeader = genesisBlock.getHeader(); for (long i = 1; i <= commonAncestorHeight; i++) { diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java index 176501f01a..63e36e6fdf 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java @@ -12,7 +12,8 @@ */ package tech.pegasys.pantheon.ethereum.vm; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.vm.WorldStateMock.insertAccount; import tech.pegasys.pantheon.ethereum.ProtocolContext; @@ -26,12 +27,10 @@ import tech.pegasys.pantheon.ethereum.core.LogsBloomFilter; import tech.pegasys.pantheon.ethereum.core.MutableWorldState; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.WorldUpdater; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPInput; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; @@ -80,8 +79,7 @@ public class BlockchainReferenceTestCaseSpec { private static MutableBlockchain buildBlockchain(final BlockHeader genesisBlockHeader) { final Block genesisBlock = new Block(genesisBlockHeader, BlockBody.empty()); - return new DefaultMutableBlockchain( - genesisBlock, new InMemoryKeyValueStorage(), MainnetBlockHashFunction::createHash); + return createInMemoryBlockchain(genesisBlock); } @JsonCreator diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java index bd94ae8f3f..8badfb4a62 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java @@ -19,12 +19,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import tech.pegasys.pantheon.ethereum.chain.Blockchain; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol.EthVersion; import tech.pegasys.pantheon.ethereum.eth.manager.MockPeerConnection.PeerSendHandler; @@ -39,7 +40,6 @@ import tech.pegasys.pantheon.ethereum.eth.messages.GetReceiptsMessage; import tech.pegasys.pantheon.ethereum.eth.messages.NewBlockMessage; import tech.pegasys.pantheon.ethereum.eth.messages.ReceiptsMessage; import tech.pegasys.pantheon.ethereum.eth.messages.StatusMessage; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; @@ -47,8 +47,6 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.ArrayList; @@ -710,10 +708,8 @@ public final class EthProtocolManagerTest { @Test public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero() throws ExecutionException, InterruptedException { - final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); + final MutableBlockchain blockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final BlockDataGenerator.BlockOptions options = new BlockDataGenerator.BlockOptions() diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java index 9120e80778..90eac9d982 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java @@ -12,17 +12,15 @@ */ package tech.pegasys.pantheon.ethereum.eth.manager; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; + import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.ChainHead; import tech.pegasys.pantheon.ethereum.chain.GenesisConfig; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.manager.DeterministicEthScheduler.TimeoutPolicy; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; -import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; public class EthProtocolManagerTestUtil { @@ -40,11 +38,7 @@ public class EthProtocolManagerTestUtil { } public static EthProtocolManager create() { - final Blockchain blockchain = - new DefaultMutableBlockchain( - GenesisConfig.mainnet().getBlock(), - new InMemoryKeyValueStorage(), - ScheduleBasedBlockHashFunction.create(MainnetProtocolSchedule.create())); + final Blockchain blockchain = createInMemoryBlockchain(GenesisConfig.mainnet().getBlock()); return create(blockchain); } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java index dfc2f2c941..69876f42e3 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java @@ -13,7 +13,8 @@ package tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils; import static org.assertj.core.util.Preconditions.checkArgument; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.chain.Blockchain; @@ -23,17 +24,13 @@ import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockHashFunction; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockImporter; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.util.RawBlockIterator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import java.io.IOException; import java.net.URL; @@ -50,7 +47,6 @@ import org.junit.rules.TemporaryFolder; public class BlockchainSetupUtil { private final GenesisConfig genesisConfig; - private final KeyValueStorage kvStore; private final MutableBlockchain blockchain; private final ProtocolContext protocolContext; private final ProtocolSchedule protocolSchedule; @@ -60,14 +56,12 @@ public class BlockchainSetupUtil { public BlockchainSetupUtil( final GenesisConfig genesisConfig, - final KeyValueStorage kvStore, final MutableBlockchain blockchain, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final WorldStateArchive worldArchive, final List blocks) { this.genesisConfig = genesisConfig; - this.kvStore = kvStore; this.blockchain = blockchain; this.protocolContext = protocolContext; this.protocolSchedule = protocolSchedule; @@ -106,10 +100,7 @@ public class BlockchainSetupUtil { final GenesisConfig genesisConfig = GenesisConfig.fromJson( Resources.toString(genesisFileUrl, Charsets.UTF_8), protocolSchedule); - final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final MutableBlockchain blockchain = - new DefaultMutableBlockchain( - genesisConfig.getBlock(), kvStore, MainnetBlockHashFunction::createHash); + final MutableBlockchain blockchain = createInMemoryBlockchain(genesisConfig.getBlock()); final WorldStateArchive worldArchive = createInMemoryWorldStateArchive(); genesisConfig.writeStateTo(worldArchive.getMutable()); @@ -127,13 +118,7 @@ public class BlockchainSetupUtil { } } return new BlockchainSetupUtil<>( - genesisConfig, - kvStore, - blockchain, - protocolContext, - protocolSchedule, - worldArchive, - blocks); + genesisConfig, blockchain, protocolContext, protocolSchedule, worldArchive, blocks); } catch (final IOException ex) { throw new IllegalStateException(ex); } finally { @@ -167,10 +152,6 @@ public class BlockchainSetupUtil { return genesisConfig; } - public KeyValueStorage getKvStore() { - return kvStore; - } - public MutableBlockchain getBlockchain() { return blockchain; } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java index d21612a507..2986a33bf5 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java @@ -25,8 +25,8 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; @@ -37,11 +37,9 @@ import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62; import tech.pegasys.pantheon.ethereum.eth.messages.GetBlockHeadersMessage; import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; -import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.ArrayList; @@ -619,11 +617,7 @@ public class DownloaderTest { blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final Block genesisBlock = new Block(genesisHeader, genesisBody); - final MutableBlockchain shortChain = - new DefaultMutableBlockchain( - genesisBlock, - new InMemoryKeyValueStorage(), - ScheduleBasedBlockHashFunction.create(protocolSchedule)); + final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); long nextBlock = genesisHeader.getNumber() + 1; while (nextBlock <= truncateAtBlockNumber) { final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 0620ae2a2c..8f6f29ce94 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -13,14 +13,15 @@ package tech.pegasys.pantheon.ethereum.eth.sync.tasks; import static org.assertj.core.api.Assertions.assertThat; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.ProtocolContext; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; @@ -30,8 +31,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.io.IOException; @@ -55,14 +54,12 @@ public class DetermineCommonAncestorTaskParameterizedTest { private static final BlockDataGenerator blockDataGenerator = new BlockDataGenerator(); private static Block genesisBlock; - private static KeyValueStorage localKvStore; - private static DefaultMutableBlockchain localBlockchain; + private static MutableBlockchain localBlockchain; private static final int chainHeight = 50; private final int headerRequestSize; private final int commonAncestorHeight; - private KeyValueStorage remoteKvStore; - private DefaultMutableBlockchain remoteBlockchain; + private MutableBlockchain remoteBlockchain; public DetermineCommonAncestorTaskParameterizedTest( final int headerRequestSize, final int commonAncestorHeight) { @@ -73,10 +70,7 @@ public class DetermineCommonAncestorTaskParameterizedTest { @BeforeClass public static void setupClass() { genesisBlock = blockDataGenerator.genesisBlock(); - localKvStore = new InMemoryKeyValueStorage(); - localBlockchain = - new DefaultMutableBlockchain( - genesisBlock, localKvStore, MainnetBlockHashFunction::createHash); + localBlockchain = createInMemoryBlockchain(genesisBlock); // Setup local chain for (int i = 1; i <= chainHeight; i++) { @@ -92,10 +86,7 @@ public class DetermineCommonAncestorTaskParameterizedTest { @Before public void setup() { - remoteKvStore = new InMemoryKeyValueStorage(); - remoteBlockchain = - new DefaultMutableBlockchain( - genesisBlock, remoteKvStore, MainnetBlockHashFunction::createHash); + remoteBlockchain = createInMemoryBlockchain(genesisBlock); } @Parameters(name = "requestSize={0}, commonAncestor={1}") diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index 4407260383..9aa3ec1f4a 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -20,13 +20,14 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.ProtocolContext; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; @@ -40,8 +41,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.uint.UInt256; @@ -57,8 +56,7 @@ public class DetermineCommonAncestorTaskTest { private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.create(); private final BlockDataGenerator blockDataGenerator = new BlockDataGenerator(); - private KeyValueStorage localKvStore; - private DefaultMutableBlockchain localBlockchain; + private MutableBlockchain localBlockchain; private final int defaultHeaderRequestSize = 10; Block genesisBlock; private EthProtocolManager ethProtocolManager; @@ -68,10 +66,7 @@ public class DetermineCommonAncestorTaskTest { @Before public void setup() { genesisBlock = blockDataGenerator.genesisBlock(); - localKvStore = new InMemoryKeyValueStorage(); - localBlockchain = - new DefaultMutableBlockchain( - genesisBlock, localKvStore, MainnetBlockHashFunction::createHash); + localBlockchain = createInMemoryBlockchain(genesisBlock); ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain); ethContext = ethProtocolManager.ethContext(); protocolContext = @@ -93,11 +88,7 @@ public class DetermineCommonAncestorTaskTest { // Populate remote chain final Block remoteGenesisBlock = blockDataGenerator.genesisBlock(); - final DefaultMutableBlockchain remoteBlockchain = - new DefaultMutableBlockchain( - remoteGenesisBlock, - new InMemoryKeyValueStorage(), - MainnetBlockHashFunction::createHash); + final MutableBlockchain remoteBlockchain = createInMemoryBlockchain(remoteGenesisBlock); for (long i = 1; i <= 9; i++) { final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() @@ -202,11 +193,7 @@ public class DetermineCommonAncestorTaskTest { // Populate remote chain final Block remoteGenesisBlock = blockDataGenerator.genesisBlock(); - final DefaultMutableBlockchain remoteBlockchain = - new DefaultMutableBlockchain( - remoteGenesisBlock, - new InMemoryKeyValueStorage(), - MainnetBlockHashFunction::createHash); + final MutableBlockchain remoteBlockchain = createInMemoryBlockchain(remoteGenesisBlock); for (long i = 1; i <= 99; i++) { final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() @@ -262,9 +249,7 @@ public class DetermineCommonAncestorTaskTest { } // Populate remote chain - final DefaultMutableBlockchain remoteBlockchain = - new DefaultMutableBlockchain( - genesisBlock, new InMemoryKeyValueStorage(), MainnetBlockHashFunction::createHash); + final MutableBlockchain remoteBlockchain = createInMemoryBlockchain(genesisBlock); for (long i = 1; i <= 100; i++) { final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() @@ -308,9 +293,7 @@ public class DetermineCommonAncestorTaskTest { @Test public void shouldShortCircuitOnHeaderInInitialRequest() { - final DefaultMutableBlockchain remoteBlockchain = - new DefaultMutableBlockchain( - genesisBlock, new InMemoryKeyValueStorage(), MainnetBlockHashFunction::createHash); + final MutableBlockchain remoteBlockchain = createInMemoryBlockchain(genesisBlock); Block commonBlock = null; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java index 7bc8c1ad1e..8963dab433 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.manager.AbstractPeerTask.PeerTaskResult; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; @@ -30,10 +30,8 @@ import tech.pegasys.pantheon.ethereum.eth.manager.RespondingEthPeer.Responder; import tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils.AbstractMessageTaskTest; import tech.pegasys.pantheon.ethereum.eth.messages.BlockHeadersMessage; import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62; -import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import java.util.ArrayList; import java.util.List; @@ -167,11 +165,7 @@ public class ImportBlocksTaskTest blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final Block genesisBlock = new Block(genesisHeader, genesisBody); - final MutableBlockchain shortChain = - new DefaultMutableBlockchain( - genesisBlock, - new InMemoryKeyValueStorage(), - ScheduleBasedBlockHashFunction.create(protocolSchedule)); + final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); long nextBlock = genesisHeader.getNumber() + 1; while (nextBlock <= truncateAtBlockNumber) { final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java index d277f109f7..4f74224e6c 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; import tech.pegasys.pantheon.ethereum.eth.manager.EthTask; @@ -30,12 +30,10 @@ import tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils.AbstractMessageTa import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62; import tech.pegasys.pantheon.ethereum.eth.messages.EthPV63; import tech.pegasys.pantheon.ethereum.eth.sync.tasks.exceptions.InvalidBlockException; -import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator.BlockOptions; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import java.util.ArrayList; import java.util.Collections; @@ -373,11 +371,7 @@ public class PipelinedImportChainSegmentTaskTest blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final Block genesisBlock = new Block(genesisHeader, genesisBody); - final MutableBlockchain shortChain = - new DefaultMutableBlockchain( - genesisBlock, - new InMemoryKeyValueStorage(), - ScheduleBasedBlockHashFunction.create(protocolSchedule)); + final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); long nextBlock = genesisHeader.getNumber() + 1; while (nextBlock <= lastBlockToInclude) { final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index a107e7af65..537bba1dd7 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -14,7 +14,8 @@ package tech.pegasys.pantheon.ethereum.eth.transactions; import static java.util.Collections.singletonList; import static org.assertj.core.util.Preconditions.checkNotNull; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.ProtocolContext; @@ -23,7 +24,6 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.BlockHashFunction; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionPool; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; @@ -42,8 +42,6 @@ import tech.pegasys.pantheon.ethereum.p2p.peers.Endpoint; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.io.Closeable; @@ -90,9 +88,8 @@ public class TestNode implements Closeable { final ProtocolSchedule protocolSchedule = genesisConfig.getProtocolSchedule(); final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); - final KeyValueStorage kv = new InMemoryKeyValueStorage(); final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisConfig.getBlock(), kv, blockHashFunction); + createInMemoryBlockchain(genesisConfig.getBlock(), blockHashFunction); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisConfig.writeStateTo(worldStateArchive.getMutable()); final ProtocolContext protocolContext = diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java index e75dd35095..397978b519 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java @@ -20,9 +20,9 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockImporter; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; @@ -30,14 +30,10 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterRepository; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; -import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import java.util.HashSet; import java.util.Map; @@ -54,15 +50,12 @@ public class JsonRpcTestMethodsFactory { } public Map methods(final String chainId) { - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - final WorldStateArchive stateArchive = - new WorldStateArchive(new KeyValueStorageWorldStateStorage(keyValueStorage)); + final WorldStateArchive stateArchive = InMemoryTestFixture.createInMemoryWorldStateArchive(); importer.getGenesisConfig().writeStateTo(stateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); final MutableBlockchain blockchain = - new DefaultMutableBlockchain( - importer.getGenesisBlock(), keyValueStorage, MainnetBlockHashFunction::createHash); + InMemoryTestFixture.createInMemoryBlockchain(importer.getGenesisBlock()); final ProtocolContext context = new ProtocolContext<>(blockchain, stateArchive, null); for (final Block block : importer.getBlocks()) { diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java index 7ee387ca85..8572ee8b21 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java @@ -26,13 +26,13 @@ import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; +import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture; import tech.pegasys.pantheon.ethereum.core.PendingTransactions; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.TransactionPool.TransactionBatchAddedListener; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.ethereum.core.Wei; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; @@ -45,10 +45,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; -import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; @@ -81,12 +77,9 @@ public class EthGetFilterChangesIntegrationTest { public void setUp() { final GenesisConfig genesisConfig = GenesisConfig.mainnet(); final Block genesisBlock = genesisConfig.getBlock(); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - blockchain = - new DefaultMutableBlockchain( - genesisBlock, keyValueStorage, MainnetBlockHashFunction::createHash); + blockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final WorldStateArchive worldStateArchive = - new WorldStateArchive(new KeyValueStorageWorldStateStorage(keyValueStorage)); + InMemoryTestFixture.createInMemoryWorldStateArchive(); final ProtocolContext protocolContext = new ProtocolContext<>(blockchain, worldStateArchive, null); transactionPool = diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java index 05131eef96..6074be9473 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java @@ -16,7 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator; @@ -30,7 +31,6 @@ import tech.pegasys.pantheon.ethereum.core.PendingTransactions; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionPool; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; @@ -47,8 +47,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.util.RawBlockIterator; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import java.net.URL; import java.nio.file.Paths; @@ -150,13 +148,10 @@ public abstract class AbstractEthJsonRpcHttpServiceTest { .thenReturn(ValidationResult.valid()); final PendingTransactions pendingTransactionsMock = mock(PendingTransactions.class); when(transactionPoolMock.getPendingTransactions()).thenReturn(pendingTransactionsMock); - final KeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); stateArchive = createInMemoryWorldStateArchive(); GENESIS_CONFIG.writeStateTo(stateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); - blockchain = - new DefaultMutableBlockchain( - GENESIS_BLOCK, keyValueStorage, MainnetBlockHashFunction::createHash); + blockchain = createInMemoryBlockchain(GENESIS_BLOCK); context = new ProtocolContext<>(blockchain, stateArchive, null); final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, stateArchive); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java index 02b689da94..ed78ae0360 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java @@ -17,7 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static tech.pegasys.pantheon.ethereum.core.InMemoryWorldState.createInMemoryWorldStateArchive; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; +import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Account; @@ -29,14 +30,10 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.WorldState; -import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.LogsQuery.Builder; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator.BlockOptions; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.ArrayList; @@ -542,9 +539,7 @@ public class BlockchainQueriesTest { } // Setup blockchain - final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final MutableBlockchain blockchain = - new DefaultMutableBlockchain(blocks.get(0), kvStore, MainnetBlockHashFunction::createHash); + final MutableBlockchain blockchain = createInMemoryBlockchain(blocks.get(0)); blockData .subList(1, blockData.size()) .forEach( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java index 6527932560..630a1968d2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java @@ -34,6 +34,7 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.KeyValueStoragePrefixedKeyBlockchainStorage; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; @@ -62,6 +63,7 @@ import io.vertx.core.json.JsonObject; import org.apache.logging.log4j.Logger; public class CliquePantheonController implements PantheonController { + private static final Logger LOG = getLogger(); private final GenesisConfig genesisConfig; private final ProtocolContext context; @@ -112,10 +114,14 @@ public class CliquePantheonController implements PantheonController protocolSchedule = genesisConfig.getProtocolSchedule(); + final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); + final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage = + new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction); final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisConfig.getBlock(), kv, blockHashFunction); + new DefaultMutableBlockchain(genesisConfig.getBlock(), blockchainStorage); + final KeyValueStorageWorldStateStorage worldStateStorage = new KeyValueStorageWorldStateStorage(kv); final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java index 17934c4bdd..f38a3e943f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java @@ -39,6 +39,7 @@ import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.KeyValueStoragePrefixedKeyBlockchainStorage; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; @@ -118,10 +119,14 @@ public class IbftPantheonController implements PantheonController { final KeyValueStorage kv = RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH))); final ProtocolSchedule protocolSchedule = genesisConfig.getProtocolSchedule(); + final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); + final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage = + new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction); final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisConfig.getBlock(), kv, blockHashFunction); + new DefaultMutableBlockchain(genesisConfig.getBlock(), blockchainStorage); + final KeyValueStorageWorldStateStorage worldStateStorage = new KeyValueStorageWorldStateStorage(kv); final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java index 244e0b611b..9fe4722916 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java @@ -28,6 +28,7 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.db.KeyValueStoragePrefixedKeyBlockchainStorage; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; @@ -110,10 +111,14 @@ public class MainnetPantheonController implements PantheonController { final KeyValueStorage kv = RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH))); final ProtocolSchedule protocolSchedule = genesisConfig.getProtocolSchedule(); + final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); + final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage = + new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction); final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisConfig.getBlock(), kv, blockHashFunction); + new DefaultMutableBlockchain(genesisConfig.getBlock(), blockchainStorage); + final WorldStateArchive worldStateArchive = new WorldStateArchive(new KeyValueStorageWorldStateStorage(kv)); genesisConfig.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH));