Decouple DefaultMutableBlockchain from KeyValueStorage (#211)

* Introduce createInMemoryBlockchain test utility and use it everywhere appropriate.

* Inject BlockchainStorage into DefaultMutableBlockchain.
Adrian Sutton 6 years ago committed by GitHub
parent 316ec10423
commit 42d69d89ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java
  2. 13
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java
  3. 14
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  4. 2
      consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java
  5. 2
      ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java
  6. 15
      ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/TraceTransactionIntegrationTest.java
  7. 11
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchain.java
  8. 5
      ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java
  9. 18
      ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryTestFixture.java
  10. 12
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java
  11. 66
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java
  12. 5
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java
  13. 2
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java
  14. 22
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java
  15. 8
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java
  16. 10
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java
  17. 12
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java
  18. 27
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java
  19. 10
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java
  20. 23
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java
  21. 35
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  22. 10
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java
  23. 10
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java
  24. 9
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java
  25. 13
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  26. 13
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java
  27. 11
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  28. 11
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java
  29. 8
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  30. 7
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  31. 7
      pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.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<CliqueContext> 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));

@ -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());

@ -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<Address> 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<CliqueContext> protocolContext;
private final MutableProtocolSchedule<CliqueContext> protocolSchedule =

@ -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;

@ -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;

@ -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<Void> 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<Void> protocolSchedule = genesisConfig.getProtocolSchedule();
genesisConfig.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH));
transactionProcessor = protocolSchedule.getByBlockNumber(0).getTransactionProcessor();

@ -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<BlockAddedObserver> 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);
}

@ -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;

@ -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(

@ -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<Void> 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<Void> protocolContext =
new ProtocolContext<>(blockchain, worldStateArchive, null);

@ -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<List<TransactionReceipt>> 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<List<TransactionReceipt>> 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<List<TransactionReceipt>> 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<List<TransactionReceipt>> 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<List<TransactionReceipt>> 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));
}
}

@ -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()

@ -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;

@ -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<BlockHeader> 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++) {

@ -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

@ -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()

@ -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);
}

@ -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<C> {
private final GenesisConfig<C> genesisConfig;
private final KeyValueStorage kvStore;
private final MutableBlockchain blockchain;
private final ProtocolContext<C> protocolContext;
private final ProtocolSchedule<C> protocolSchedule;
@ -60,14 +56,12 @@ public class BlockchainSetupUtil<C> {
public BlockchainSetupUtil(
final GenesisConfig<C> genesisConfig,
final KeyValueStorage kvStore,
final MutableBlockchain blockchain,
final ProtocolContext<C> protocolContext,
final ProtocolSchedule<C> protocolSchedule,
final WorldStateArchive worldArchive,
final List<Block> blocks) {
this.genesisConfig = genesisConfig;
this.kvStore = kvStore;
this.blockchain = blockchain;
this.protocolContext = protocolContext;
this.protocolSchedule = protocolSchedule;
@ -106,10 +100,7 @@ public class BlockchainSetupUtil<C> {
final GenesisConfig<Void> 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<C> {
}
}
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<C> {
return genesisConfig;
}
public KeyValueStorage getKvStore() {
return kvStore;
}
public MutableBlockchain getBlockchain() {
return blockchain;
}

@ -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();

@ -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}")

@ -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<Void> 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;

@ -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();

@ -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();

@ -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<Void> 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<Void> protocolContext =

@ -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<String, JsonRpcMethod> 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<Void> context = new ProtocolContext<>(blockchain, stateArchive, null);
for (final Block block : importer.getBlocks()) {

@ -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<Void> 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<Void> protocolContext =
new ProtocolContext<>(blockchain, worldStateArchive, null);
transactionPool =

@ -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);

@ -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(

@ -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<CliqueContext> {
private static final Logger LOG = getLogger();
private final GenesisConfig<CliqueContext> genesisConfig;
private final ProtocolContext<CliqueContext> context;
@ -112,10 +114,14 @@ public class CliquePantheonController implements PantheonController<CliqueContex
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<CliqueContext> 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);

@ -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<IbftContext> {
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<IbftContext> 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);

@ -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<Void> {
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<Void> 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));

Loading…
Cancel
Save