Inject StorageProvider into PantheonController instances (#259)

Adrian Sutton 6 years ago committed by GitHub
parent ec1a8be558
commit 4d95c60eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/NodeCanProduceNextBlockTest.java
  2. 4
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/VoteTallyCacheTest.java
  3. 4
      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/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java
  6. 2
      ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/vm/EntriesFromIntegrationTest.java
  7. 2
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/GenesisState.java
  8. 26
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/storage/StorageProvider.java
  9. 3
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java
  10. 47
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/storage/keyvalue/KeyValueStorageProvider.java
  11. 3
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/storage/keyvalue/KeyValueStorageWorldStateStorage.java
  12. 29
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/storage/keyvalue/RocksDbStorageProvider.java
  13. 1
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DebuggableMutableWorldState.java
  14. 4
      ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java
  15. 25
      ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryStorageProvider.java
  16. 2
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java
  17. 1
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/DefaultMutableBlockchainTest.java
  18. 1
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/db/GenesisBlockMismatchTest.java
  19. 2
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/testutil/BlockDataGenerator.java
  20. 6
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/util/BlockchainUtilParameterizedTest.java
  21. 4
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/BlockchainReferenceTestCaseSpec.java
  22. 2
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ExtCodeHashOperationTest.java
  23. 1
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutableWorldStateTest.java
  24. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java
  25. 2
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java
  26. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java
  27. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/DownloaderTest.java
  28. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java
  29. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  30. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/ImportBlocksTaskTest.java
  31. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/PipelinedImportChainSegmentTaskTest.java
  32. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java
  33. 8
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  34. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  35. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/queries/BlockchainQueriesTest.java
  36. 13
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java
  37. 41
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  38. 41
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  39. 54
      pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java
  40. 28
      pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java
  41. 21
      pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java
  42. 20
      pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java

@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.consensus.clique.headervalidationrules.SignerRateLimitValidationRule; import tech.pegasys.pantheon.consensus.clique.headervalidationrules.SignerRateLimitValidationRule;
import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.consensus.common.VoteProposer;
@ -31,7 +32,6 @@ import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Hash; 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.core.Util;
import java.util.List; import java.util.List;
@ -70,7 +70,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(proposerKeyPair); genesisBlock = createEmptyBlock(proposerKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -95,7 +95,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(otherNodeKeyPair); genesisBlock = createEmptyBlock(otherNodeKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -129,7 +129,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(proposerKeyPair); genesisBlock = createEmptyBlock(proposerKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -159,7 +159,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(proposerKeyPair); genesisBlock = createEmptyBlock(proposerKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -204,7 +204,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(proposerKeyPair); genesisBlock = createEmptyBlock(proposerKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -233,7 +233,7 @@ public class NodeCanProduceNextBlockTest {
genesisBlock = createEmptyBlock(proposerKeyPair); genesisBlock = createEmptyBlock(proposerKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));
@ -257,7 +257,7 @@ public class NodeCanProduceNextBlockTest {
public void nonValidatorIsNotAllowedToCreateABlock() { public void nonValidatorIsNotAllowedToCreateABlock() {
genesisBlock = createEmptyBlock(otherNodeKeyPair); genesisBlock = createEmptyBlock(otherNodeKeyPair);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class);
when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList)); when(voteTallyCache.getVoteTallyAtBlock(any())).thenReturn(new VoteTally(validatorList));

@ -20,6 +20,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.consensus.common.EpochManager; import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteTallyUpdater; import tech.pegasys.pantheon.consensus.common.VoteTallyUpdater;
@ -31,7 +32,6 @@ import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.math.BigInteger; import java.math.BigInteger;
@ -69,7 +69,7 @@ public class VoteTallyCacheTest {
genesisBlock = createEmptyBlock(0, Hash.ZERO); genesisBlock = createEmptyBlock(0, Hash.ZERO);
blockChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); blockChain = createInMemoryBlockchain(genesisBlock);
block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash()); block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash());
block_2 = createEmptyBlock(1, block_1.getHeader().getHash()); block_2 = createEmptyBlock(1, block_1.getHeader().getHash());

@ -16,8 +16,8 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.consensus.clique.CliqueContext; import tech.pegasys.pantheon.consensus.clique.CliqueContext;

@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.consensus.common.VoteProposer;

@ -42,9 +42,9 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.TransactionProcessor; import tech.pegasys.pantheon.ethereum.mainnet.TransactionProcessor;
import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.vm.TestBlockchain; import tech.pegasys.pantheon.ethereum.vm.TestBlockchain;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState; import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256; import tech.pegasys.pantheon.util.uint.UInt256;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.ethereum.vm; package tech.pegasys.pantheon.ethereum.vm;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;

@ -25,8 +25,8 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.core.WorldUpdater; import tech.pegasys.pantheon.ethereum.core.WorldUpdater;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState; import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;

@ -0,0 +1,26 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.storage;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import java.io.Closeable;
public interface StorageProvider extends Closeable {
BlockchainStorage createBlockchainStorage(ProtocolSchedule<?> protocolSchedule);
WorldStateStorage createWorldStateStorage();
}

@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.ethereum.db; package tech.pegasys.pantheon.ethereum.storage.keyvalue;
import tech.pegasys.pantheon.ethereum.chain.TransactionLocation; import tech.pegasys.pantheon.ethereum.chain.TransactionLocation;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
@ -18,6 +18,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.rlp.RLP; import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.Bytes32;

@ -0,0 +1,47 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.storage.keyvalue;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import java.io.IOException;
public class KeyValueStorageProvider implements StorageProvider {
private final KeyValueStorage keyValueStorage;
public KeyValueStorageProvider(final KeyValueStorage keyValueStorage) {
this.keyValueStorage = keyValueStorage;
}
@Override
public BlockchainStorage createBlockchainStorage(final ProtocolSchedule<?> protocolSchedule) {
return new KeyValueStoragePrefixedKeyBlockchainStorage(
keyValueStorage, ScheduleBasedBlockHashFunction.create(protocolSchedule));
}
@Override
public WorldStateStorage createWorldStateStorage() {
return new KeyValueStorageWorldStateStorage(keyValueStorage);
}
@Override
public void close() throws IOException {
keyValueStorage.close();
}
}

@ -10,9 +10,10 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.ethereum.worldstate; package tech.pegasys.pantheon.ethereum.storage.keyvalue;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;

@ -0,0 +1,29 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.storage.keyvalue;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class RocksDbStorageProvider {
public static StorageProvider create(final Path databaseDir) throws IOException {
final KeyValueStorage kv = RocksDbKeyValueStorage.create(Files.createDirectories(databaseDir));
return new KeyValueStorageProvider(kv);
}
}

@ -18,6 +18,7 @@ import tech.pegasys.pantheon.ethereum.core.MutableAccount;
import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.core.WorldState; import tech.pegasys.pantheon.ethereum.core.WorldState;
import tech.pegasys.pantheon.ethereum.core.WorldUpdater; import tech.pegasys.pantheon.ethereum.core.WorldUpdater;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import java.util.Collection; import java.util.Collection;

@ -18,13 +18,13 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.GenesisState;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; 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.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState; import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;

@ -13,14 +13,19 @@
package tech.pegasys.pantheon.ethereum.core; package tech.pegasys.pantheon.ethereum.core;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; 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.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
public class InMemoryTestFixture { public class InMemoryStorageProvider implements StorageProvider {
public static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { public static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) {
return createInMemoryBlockchain(genesisBlock, MainnetBlockHashFunction::createHash); return createInMemoryBlockchain(genesisBlock, MainnetBlockHashFunction::createHash);
@ -38,4 +43,18 @@ public class InMemoryTestFixture {
return new WorldStateArchive( return new WorldStateArchive(
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage())); new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage()));
} }
@Override
public BlockchainStorage createBlockchainStorage(final ProtocolSchedule<?> protocolSchedule) {
return new KeyValueStoragePrefixedKeyBlockchainStorage(
new InMemoryKeyValueStorage(), ScheduleBasedBlockHashFunction.create(protocolSchedule));
}
@Override
public WorldStateStorage createWorldStateStorage() {
return new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
}
@Override
public void close() {}
} }

@ -20,8 +20,8 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput; import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState; import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;

@ -22,6 +22,7 @@ import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator;
import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator.BlockOptions; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator.BlockOptions;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;

@ -23,6 +23,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.LogsBloomFilter; import tech.pegasys.pantheon.ethereum.core.LogsBloomFilter;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import tech.pegasys.pantheon.ethereum.util.InvalidConfigurationException; import tech.pegasys.pantheon.ethereum.util.InvalidConfigurationException;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.ethereum.testutil; package tech.pegasys.pantheon.ethereum.testutil;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;

@ -13,12 +13,12 @@
package tech.pegasys.pantheon.ethereum.util; package tech.pegasys.pantheon.ethereum.util;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; 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.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.testutil.BlockDataGenerator;
import tech.pegasys.pantheon.util.uint.UInt256; import tech.pegasys.pantheon.util.uint.UInt256;
@ -58,7 +58,7 @@ public class BlockchainUtilParameterizedTest {
@BeforeClass @BeforeClass
public static void setupClass() { public static void setupClass() {
genesisBlock = blockDataGenerator.genesisBlock(); genesisBlock = blockDataGenerator.genesisBlock();
localBlockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); localBlockchain = createInMemoryBlockchain(genesisBlock);
// Setup local chain. // Setup local chain.
for (int i = 1; i <= chainHeight; i++) { for (int i = 1; i <= chainHeight; i++) {
final BlockDataGenerator.BlockOptions options = final BlockDataGenerator.BlockOptions options =
@ -73,7 +73,7 @@ public class BlockchainUtilParameterizedTest {
@Before @Before
public void setup() { public void setup() {
remoteBlockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); remoteBlockchain = createInMemoryBlockchain(genesisBlock);
commonHeader = genesisBlock.getHeader(); commonHeader = genesisBlock.getHeader();
for (long i = 1; i <= commonAncestorHeight; i++) { for (long i = 1; i <= commonAncestorHeight; i++) {

@ -12,8 +12,8 @@
*/ */
package tech.pegasys.pantheon.ethereum.vm; package tech.pegasys.pantheon.ethereum.vm;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import static tech.pegasys.pantheon.ethereum.vm.WorldStateMock.insertAccount; import static tech.pegasys.pantheon.ethereum.vm.WorldStateMock.insertAccount;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;

@ -27,9 +27,9 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.core.WorldUpdater; import tech.pegasys.pantheon.ethereum.core.WorldUpdater;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.ConstantinopleGasCalculator; import tech.pegasys.pantheon.ethereum.mainnet.ConstantinopleGasCalculator;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame; import tech.pegasys.pantheon.ethereum.vm.MessageFrame;
import tech.pegasys.pantheon.ethereum.vm.Words; import tech.pegasys.pantheon.ethereum.vm.Words;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;

@ -25,6 +25,7 @@ import tech.pegasys.pantheon.ethereum.core.MutableWorldState;
import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.core.WorldState; import tech.pegasys.pantheon.ethereum.core.WorldState;
import tech.pegasys.pantheon.ethereum.core.WorldUpdater; import tech.pegasys.pantheon.ethereum.core.WorldUpdater;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.trie.MerklePatriciaTrie; import tech.pegasys.pantheon.ethereum.trie.MerklePatriciaTrie;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;

@ -17,6 +17,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
@ -24,7 +25,6 @@ import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.Hash; 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.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol.EthVersion; import tech.pegasys.pantheon.ethereum.eth.EthProtocol.EthVersion;
@ -694,7 +694,7 @@ public final class EthProtocolManagerTest {
public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero() public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero()
throws ExecutionException, InterruptedException { throws ExecutionException, InterruptedException {
final Block genesisBlock = gen.genesisBlock(); final Block genesisBlock = gen.genesisBlock();
final MutableBlockchain blockchain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisBlock);
final BlockDataGenerator.BlockOptions options = final BlockDataGenerator.BlockOptions options =
new BlockDataGenerator.BlockOptions() new BlockDataGenerator.BlockOptions()

@ -12,7 +12,7 @@
*/ */
package tech.pegasys.pantheon.ethereum.eth.manager; package tech.pegasys.pantheon.ethereum.eth.manager;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;

@ -13,8 +13,8 @@
package tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils; package tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils;
import static org.assertj.core.util.Preconditions.checkArgument; import static org.assertj.core.util.Preconditions.checkArgument;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;

@ -18,6 +18,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times; import static org.mockito.internal.verification.VerificationModeFactory.times;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;
@ -25,7 +26,6 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; 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.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
@ -617,7 +617,7 @@ public class DownloaderTest {
blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get();
final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get();
final Block genesisBlock = new Block(genesisHeader, genesisBody); final Block genesisBlock = new Block(genesisHeader, genesisBody);
final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final MutableBlockchain shortChain = createInMemoryBlockchain(genesisBlock);
long nextBlock = genesisHeader.getNumber() + 1; long nextBlock = genesisHeader.getNumber() + 1;
while (nextBlock <= truncateAtBlockNumber) { while (nextBlock <= truncateAtBlockNumber) {
final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); final BlockHeader header = blockchain.getBlockHeader(nextBlock).get();

@ -13,8 +13,8 @@
package tech.pegasys.pantheon.ethereum.eth.sync.tasks; package tech.pegasys.pantheon.ethereum.eth.sync.tasks;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;

@ -20,8 +20,8 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;

@ -13,13 +13,13 @@
package tech.pegasys.pantheon.ethereum.eth.sync.tasks; package tech.pegasys.pantheon.ethereum.eth.sync.tasks;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; 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.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.eth.manager.AbstractPeerTask.PeerTaskResult; import tech.pegasys.pantheon.ethereum.eth.manager.AbstractPeerTask.PeerTaskResult;
import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer;
@ -165,7 +165,7 @@ public class ImportBlocksTaskTest
blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get();
final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get();
final Block genesisBlock = new Block(genesisHeader, genesisBody); final Block genesisBlock = new Block(genesisHeader, genesisBody);
final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final MutableBlockchain shortChain = createInMemoryBlockchain(genesisBlock);
long nextBlock = genesisHeader.getNumber() + 1; long nextBlock = genesisHeader.getNumber() + 1;
while (nextBlock <= truncateAtBlockNumber) { while (nextBlock <= truncateAtBlockNumber) {
final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); final BlockHeader header = blockchain.getBlockHeader(nextBlock).get();

@ -13,13 +13,13 @@
package tech.pegasys.pantheon.ethereum.eth.sync.tasks; package tech.pegasys.pantheon.ethereum.eth.sync.tasks;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; 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.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil;
@ -371,7 +371,7 @@ public class PipelinedImportChainSegmentTaskTest
blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get();
final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get();
final Block genesisBlock = new Block(genesisHeader, genesisBody); final Block genesisBlock = new Block(genesisHeader, genesisBody);
final MutableBlockchain shortChain = InMemoryTestFixture.createInMemoryBlockchain(genesisBlock); final MutableBlockchain shortChain = createInMemoryBlockchain(genesisBlock);
long nextBlock = genesisHeader.getNumber() + 1; long nextBlock = genesisHeader.getNumber() + 1;
while (nextBlock <= lastBlockToInclude) { while (nextBlock <= lastBlockToInclude) {
final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); final BlockHeader header = blockchain.getBlockHeader(nextBlock).get();

@ -14,8 +14,8 @@ package tech.pegasys.pantheon.ethereum.eth.transactions;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.assertj.core.util.Preconditions.checkNotNull; import static org.assertj.core.util.Preconditions.checkNotNull;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;

@ -13,6 +13,8 @@
package tech.pegasys.pantheon.ethereum.jsonrpc; package tech.pegasys.pantheon.ethereum.jsonrpc;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator; import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
@ -20,7 +22,6 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockImporter; import tech.pegasys.pantheon.ethereum.core.BlockImporter;
import tech.pegasys.pantheon.ethereum.core.Hash; 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.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive; import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
@ -50,12 +51,11 @@ public class JsonRpcTestMethodsFactory {
} }
public Map<String, JsonRpcMethod> methods() { public Map<String, JsonRpcMethod> methods() {
final WorldStateArchive stateArchive = InMemoryTestFixture.createInMemoryWorldStateArchive(); final WorldStateArchive stateArchive = createInMemoryWorldStateArchive();
importer.getGenesisState().writeStateTo(stateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); importer.getGenesisState().writeStateTo(stateArchive.getMutable(Hash.EMPTY_TRIE_HASH));
final MutableBlockchain blockchain = final MutableBlockchain blockchain = createInMemoryBlockchain(importer.getGenesisBlock());
InMemoryTestFixture.createInMemoryBlockchain(importer.getGenesisBlock());
final ProtocolContext<Void> context = new ProtocolContext<>(blockchain, stateArchive, null); final ProtocolContext<Void> context = new ProtocolContext<>(blockchain, stateArchive, null);
for (final Block block : importer.getBlocks()) { for (final Block block : importer.getBlocks()) {

@ -16,8 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator; import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;

@ -17,8 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryBlockchain; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryTestFixture.createInMemoryWorldStateArchive; import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Account; import tech.pegasys.pantheon.ethereum.core.Account;

@ -14,6 +14,7 @@ package tech.pegasys.pantheon.cli;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static tech.pegasys.pantheon.controller.KeyPairUtil.loadKeyPair; import static tech.pegasys.pantheon.controller.KeyPairUtil.loadKeyPair;
import static tech.pegasys.pantheon.controller.PantheonController.DATABASE_PATH;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.controller.MainnetPantheonController; import tech.pegasys.pantheon.controller.MainnetPantheonController;
@ -22,6 +23,8 @@ import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.development.DevelopmentProtocolSchedule; import tech.pegasys.pantheon.ethereum.development.DevelopmentProtocolSchedule;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -43,10 +46,13 @@ public class PantheonControllerBuilder {
// instantiate a controller with mainnet config if no genesis file is defined // instantiate a controller with mainnet config if no genesis file is defined
// otherwise use the indicated genesis file // otherwise use the indicated genesis file
final KeyPair nodeKeys = loadKeyPair(nodePrivateKeyFile); final KeyPair nodeKeys = loadKeyPair(nodePrivateKeyFile);
final StorageProvider storageProvider =
RocksDbStorageProvider.create(homePath.resolve(DATABASE_PATH));
if (isDevMode) { if (isDevMode) {
final GenesisConfigFile genesisConfig = GenesisConfigFile.development(); final GenesisConfigFile genesisConfig = GenesisConfigFile.development();
return MainnetPantheonController.init( return MainnetPantheonController.init(
homePath, storageProvider,
genesisConfig, genesisConfig,
DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions()), DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions()),
synchronizerConfiguration, synchronizerConfiguration,
@ -55,10 +61,11 @@ public class PantheonControllerBuilder {
} else { } else {
final String genesisConfig = final String genesisConfig =
Resources.toString(ethNetworkConfig.getGenesisConfig().toURL(), UTF_8); Resources.toString(ethNetworkConfig.getGenesisConfig().toURL(), UTF_8);
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig);
return PantheonController.fromConfig( return PantheonController.fromConfig(
genesisConfigFile,
synchronizerConfiguration, synchronizerConfiguration,
genesisConfig, storageProvider,
homePath,
syncWithOttoman, syncWithOttoman,
ethNetworkConfig.getNetworkId(), ethNetworkConfig.getNetworkId(),
miningParameters, miningParameters,

@ -16,7 +16,6 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import tech.pegasys.pantheon.config.CliqueConfigOptions; import tech.pegasys.pantheon.config.CliqueConfigOptions;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.consensus.clique.CliqueContext; import tech.pegasys.pantheon.consensus.clique.CliqueContext;
import tech.pegasys.pantheon.consensus.clique.CliqueProtocolSchedule; import tech.pegasys.pantheon.consensus.clique.CliqueProtocolSchedule;
import tech.pegasys.pantheon.consensus.clique.CliqueVotingBlockInterface; import tech.pegasys.pantheon.consensus.clique.CliqueVotingBlockInterface;
@ -32,14 +31,13 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator; import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.GenesisState;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; 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.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
@ -49,16 +47,12 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager; import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Clock; import java.time.Clock;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -69,7 +63,6 @@ import org.apache.logging.log4j.Logger;
public class CliquePantheonController implements PantheonController<CliqueContext> { public class CliquePantheonController implements PantheonController<CliqueContext> {
private static final Logger LOG = getLogger(); private static final Logger LOG = getLogger();
private final GenesisConfigOptions genesisConfigOptions;
private final ProtocolSchedule<CliqueContext> protocolSchedule; private final ProtocolSchedule<CliqueContext> protocolSchedule;
private final ProtocolContext<CliqueContext> context; private final ProtocolContext<CliqueContext> context;
private final Synchronizer synchronizer; private final Synchronizer synchronizer;
@ -81,7 +74,6 @@ public class CliquePantheonController implements PantheonController<CliqueContex
private final MiningCoordinator miningCoordinator; private final MiningCoordinator miningCoordinator;
CliquePantheonController( CliquePantheonController(
final GenesisConfigOptions genesisConfigOptions,
final ProtocolSchedule<CliqueContext> protocolSchedule, final ProtocolSchedule<CliqueContext> protocolSchedule,
final ProtocolContext<CliqueContext> context, final ProtocolContext<CliqueContext> context,
final ProtocolManager ethProtocolManager, final ProtocolManager ethProtocolManager,
@ -91,7 +83,6 @@ public class CliquePantheonController implements PantheonController<CliqueContex
final MiningCoordinator miningCoordinator, final MiningCoordinator miningCoordinator,
final Runnable closer) { final Runnable closer) {
this.genesisConfigOptions = genesisConfigOptions;
this.protocolSchedule = protocolSchedule; this.protocolSchedule = protocolSchedule;
this.context = context; this.context = context;
this.ethProtocolManager = ethProtocolManager; this.ethProtocolManager = ethProtocolManager;
@ -103,33 +94,27 @@ public class CliquePantheonController implements PantheonController<CliqueContex
} }
public static PantheonController<CliqueContext> init( public static PantheonController<CliqueContext> init(
final Path home, final StorageProvider storageProvider,
final GenesisConfigFile genesisConfig, final GenesisConfigFile genesisConfig,
final SynchronizerConfiguration taintedSyncConfig, final SynchronizerConfiguration taintedSyncConfig,
final MiningParameters miningParams, final MiningParameters miningParams,
final int networkId, final int networkId,
final KeyPair nodeKeys) final KeyPair nodeKeys) {
throws IOException {
final CliqueConfigOptions cliqueConfig = final CliqueConfigOptions cliqueConfig =
genesisConfig.getConfigOptions().getCliqueConfigOptions(); genesisConfig.getConfigOptions().getCliqueConfigOptions();
final long blocksPerEpoch = cliqueConfig.getEpochLength(); final long blocksPerEpoch = cliqueConfig.getEpochLength();
final long secondsBetweenBlocks = cliqueConfig.getBlockPeriodSeconds(); final long secondsBetweenBlocks = cliqueConfig.getBlockPeriodSeconds();
final EpochManager epochManger = new EpochManager(blocksPerEpoch); final EpochManager epochManger = new EpochManager(blocksPerEpoch);
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<CliqueContext> protocolSchedule = final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(genesisConfig.getConfigOptions(), nodeKeys); CliqueProtocolSchedule.create(genesisConfig.getConfigOptions(), nodeKeys);
final BlockHashFunction blockHashFunction =
ScheduleBasedBlockHashFunction.create(protocolSchedule);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule); final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage = final BlockchainStorage blockchainStorage =
new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction); storageProvider.createBlockchainStorage(protocolSchedule);
final MutableBlockchain blockchain = final MutableBlockchain blockchain =
new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage); new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage);
final KeyValueStorageWorldStateStorage worldStateStorage = final WorldStateStorage worldStateStorage = storageProvider.createWorldStateStorage();
new KeyValueStorageWorldStateStorage(kv);
final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage); final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage);
genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH));
@ -191,7 +176,6 @@ public class CliquePantheonController implements PantheonController<CliqueContex
miningCoordinator.enable(); miningCoordinator.enable();
return new CliquePantheonController( return new CliquePantheonController(
genesisConfig.getConfigOptions(),
protocolSchedule, protocolSchedule,
protocolContext, protocolContext,
ethProtocolManager, ethProtocolManager,
@ -208,9 +192,9 @@ public class CliquePantheonController implements PantheonController<CliqueContex
LOG.error("Failed to shutdown miner executor"); LOG.error("Failed to shutdown miner executor");
} }
try { try {
kv.close(); storageProvider.close();
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Failed to close key value storage", e); LOG.error("Failed to close storage provider", e);
} }
}); });
} }
@ -225,11 +209,6 @@ public class CliquePantheonController implements PantheonController<CliqueContex
return protocolSchedule; return protocolSchedule;
} }
@Override
public GenesisConfigOptions getGenesisConfigOptions() {
return genesisConfigOptions;
}
@Override @Override
public Synchronizer getSynchronizer() { public Synchronizer getSynchronizer() {
return synchronizer; return synchronizer;

@ -15,7 +15,6 @@ package tech.pegasys.pantheon.controller;
import static org.apache.logging.log4j.LogManager.getLogger; import static org.apache.logging.log4j.LogManager.getLogger;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.config.IbftConfigOptions; import tech.pegasys.pantheon.config.IbftConfigOptions;
import tech.pegasys.pantheon.consensus.common.EpochManager; import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteProposer; import tech.pegasys.pantheon.consensus.common.VoteProposer;
@ -38,12 +37,11 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator; import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.GenesisState;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; 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.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
@ -53,17 +51,13 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager; import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -73,7 +67,6 @@ import org.apache.logging.log4j.Logger;
public class IbftPantheonController implements PantheonController<IbftContext> { public class IbftPantheonController implements PantheonController<IbftContext> {
private static final Logger LOG = getLogger(); private static final Logger LOG = getLogger();
private final GenesisConfigOptions genesisConfig;
private final ProtocolSchedule<IbftContext> protocolSchedule; private final ProtocolSchedule<IbftContext> protocolSchedule;
private final ProtocolContext<IbftContext> context; private final ProtocolContext<IbftContext> context;
private final Synchronizer synchronizer; private final Synchronizer synchronizer;
@ -86,7 +79,6 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
private final Runnable closer; private final Runnable closer;
IbftPantheonController( IbftPantheonController(
final GenesisConfigOptions genesisConfig,
final ProtocolSchedule<IbftContext> protocolSchedule, final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> context, final ProtocolContext<IbftContext> context,
final SubProtocol ethSubProtocol, final SubProtocol ethSubProtocol,
@ -98,7 +90,6 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
final IbftProcessor ibftProcessor, final IbftProcessor ibftProcessor,
final Runnable closer) { final Runnable closer) {
this.genesisConfig = genesisConfig;
this.protocolSchedule = protocolSchedule; this.protocolSchedule = protocolSchedule;
this.context = context; this.context = context;
this.ethSubProtocol = ethSubProtocol; this.ethSubProtocol = ethSubProtocol;
@ -112,27 +103,21 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
} }
public static PantheonController<IbftContext> init( public static PantheonController<IbftContext> init(
final Path home, final StorageProvider storageProvider,
final GenesisConfigFile genesisConfig, final GenesisConfigFile genesisConfig,
final SynchronizerConfiguration taintedSyncConfig, final SynchronizerConfiguration taintedSyncConfig,
final boolean ottomanTestnetOperation, final boolean ottomanTestnetOperation,
final int networkId, final int networkId,
final KeyPair nodeKeys) final KeyPair nodeKeys) {
throws IOException {
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<IbftContext> protocolSchedule = final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions()); IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
final BlockHashFunction blockHashFunction =
ScheduleBasedBlockHashFunction.create(protocolSchedule);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule); final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage = final BlockchainStorage blockchainStorage =
new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction); storageProvider.createBlockchainStorage(protocolSchedule);
final MutableBlockchain blockchain = final MutableBlockchain blockchain =
new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage); new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage);
final KeyValueStorageWorldStateStorage worldStateStorage = final WorldStateStorage worldStateStorage = storageProvider.createWorldStateStorage();
new KeyValueStorageWorldStateStorage(kv);
final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage); final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage);
genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH));
@ -202,9 +187,9 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
LOG.error("Failed to shutdown ibft processor executor"); LOG.error("Failed to shutdown ibft processor executor");
} }
try { try {
kv.close(); storageProvider.close();
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Failed to close key value storage", e); LOG.error("Failed to close storage provider", e);
} }
}; };
@ -216,7 +201,6 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
new IbftNetworkPeers(protocolContext.getConsensusState().getVoteTally()); new IbftNetworkPeers(protocolContext.getConsensusState().getVoteTally());
return new IbftPantheonController( return new IbftPantheonController(
genesisConfig.getConfigOptions(),
protocolSchedule, protocolSchedule,
protocolContext, protocolContext,
ethSubProtocol, ethSubProtocol,
@ -239,11 +223,6 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
return protocolSchedule; return protocolSchedule;
} }
@Override
public GenesisConfigOptions getGenesisConfigOptions() {
return genesisConfig;
}
@Override @Override
public Synchronizer getSynchronizer() { public Synchronizer getSynchronizer() {
return synchronizer; return synchronizer;

@ -12,10 +12,7 @@
*/ */
package tech.pegasys.pantheon.controller; package tech.pegasys.pantheon.controller;
import static tech.pegasys.pantheon.controller.KeyPairUtil.loadKeyPair;
import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.DefaultBlockScheduler; import tech.pegasys.pantheon.ethereum.blockcreation.DefaultBlockScheduler;
@ -24,13 +21,12 @@ import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator; import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.GenesisState;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain; 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.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
@ -42,16 +38,11 @@ import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHeaderValidator; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager; import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage; import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Clock; import java.time.Clock;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -64,7 +55,6 @@ public class MainnetPantheonController implements PantheonController<Void> {
private static final Logger LOG = LogManager.getLogger(); private static final Logger LOG = LogManager.getLogger();
private final GenesisConfigFile genesisConfig;
private final ProtocolSchedule<Void> protocolSchedule; private final ProtocolSchedule<Void> protocolSchedule;
private final ProtocolContext<Void> protocolContext; private final ProtocolContext<Void> protocolContext;
private final ProtocolManager ethProtocolManager; private final ProtocolManager ethProtocolManager;
@ -76,7 +66,6 @@ public class MainnetPantheonController implements PantheonController<Void> {
private final Runnable close; private final Runnable close;
public MainnetPantheonController( public MainnetPantheonController(
final GenesisConfigFile genesisConfig,
final ProtocolSchedule<Void> protocolSchedule, final ProtocolSchedule<Void> protocolSchedule,
final ProtocolContext<Void> protocolContext, final ProtocolContext<Void> protocolContext,
final ProtocolManager ethProtocolManager, final ProtocolManager ethProtocolManager,
@ -85,7 +74,6 @@ public class MainnetPantheonController implements PantheonController<Void> {
final TransactionPool transactionPool, final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator, final MiningCoordinator miningCoordinator,
final Runnable close) { final Runnable close) {
this.genesisConfig = genesisConfig;
this.protocolSchedule = protocolSchedule; this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext; this.protocolContext = protocolContext;
this.ethProtocolManager = ethProtocolManager; this.ethProtocolManager = ethProtocolManager;
@ -96,40 +84,22 @@ public class MainnetPantheonController implements PantheonController<Void> {
this.close = close; this.close = close;
} }
public static PantheonController<Void> mainnet(final Path home) throws IOException {
final MiningParameters miningParams = new MiningParameters(null, null, null, false);
final KeyPair nodeKeys = loadKeyPair(home);
final GenesisConfigFile genesisConfig = GenesisConfigFile.mainnet();
return init(
home,
genesisConfig,
MainnetProtocolSchedule.fromConfig(genesisConfig.getConfigOptions()),
SynchronizerConfiguration.builder().build(),
miningParams,
nodeKeys);
}
public static PantheonController<Void> init( public static PantheonController<Void> init(
final Path home, final StorageProvider storageProvider,
final GenesisConfigFile genesisConfig, final GenesisConfigFile genesisConfig,
final ProtocolSchedule<Void> protocolSchedule, final ProtocolSchedule<Void> protocolSchedule,
final SynchronizerConfiguration taintedSyncConfig, final SynchronizerConfiguration taintedSyncConfig,
final MiningParameters miningParams, final MiningParameters miningParams,
final KeyPair nodeKeys) final KeyPair nodeKeys) {
throws IOException {
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule); final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final KeyValueStorage kv = final BlockchainStorage blockchainStorage =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH))); storageProvider.createBlockchainStorage(protocolSchedule);
final BlockHashFunction blockHashFunction =
ScheduleBasedBlockHashFunction.create(protocolSchedule);
final KeyValueStoragePrefixedKeyBlockchainStorage blockchainStorage =
new KeyValueStoragePrefixedKeyBlockchainStorage(kv, blockHashFunction);
final MutableBlockchain blockchain = final MutableBlockchain blockchain =
new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage); new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage);
final WorldStateArchive worldStateArchive = final WorldStateArchive worldStateArchive =
new WorldStateArchive(new KeyValueStorageWorldStateStorage(kv)); new WorldStateArchive(storageProvider.createWorldStateStorage());
genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); genesisState.writeStateTo(worldStateArchive.getMutable(Hash.EMPTY_TRIE_HASH));
final ProtocolContext<Void> protocolContext = final ProtocolContext<Void> protocolContext =
@ -182,7 +152,6 @@ public class MainnetPantheonController implements PantheonController<Void> {
} }
return new MainnetPantheonController( return new MainnetPantheonController(
genesisConfig,
protocolSchedule, protocolSchedule,
protocolContext, protocolContext,
ethProtocolManager, ethProtocolManager,
@ -199,9 +168,9 @@ public class MainnetPantheonController implements PantheonController<Void> {
LOG.error("Failed to shutdown miner executor"); LOG.error("Failed to shutdown miner executor");
} }
try { try {
kv.close(); storageProvider.close();
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Failed to close key value storage", e); LOG.error("Failed to close storage provider", e);
} }
}); });
} }
@ -216,11 +185,6 @@ public class MainnetPantheonController implements PantheonController<Void> {
return protocolSchedule; return protocolSchedule;
} }
@Override
public GenesisConfigOptions getGenesisConfigOptions() {
return genesisConfig.getConfigOptions();
}
@Override @Override
public Synchronizer getSynchronizer() { public Synchronizer getSynchronizer() {
return synchronizer; return synchronizer;

@ -24,42 +24,44 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Path;
public interface PantheonController<C> extends Closeable { public interface PantheonController<C> extends Closeable {
String DATABASE_PATH = "database"; String DATABASE_PATH = "database";
static PantheonController<?> fromConfig( static PantheonController<?> fromConfig(
final GenesisConfigFile genesisConfigFile,
final SynchronizerConfiguration syncConfig, final SynchronizerConfiguration syncConfig,
final String configContents, final StorageProvider storageProvider,
final Path pantheonHome,
final boolean ottomanTestnetOperation, final boolean ottomanTestnetOperation,
final int networkId, final int networkId,
final MiningParameters miningParameters, final MiningParameters miningParameters,
final KeyPair nodeKeys) final KeyPair nodeKeys) {
throws IOException {
final GenesisConfigFile config = GenesisConfigFile.fromConfig(configContents); final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
final GenesisConfigOptions configOptions = config.getConfigOptions();
if (configOptions.isEthHash()) { if (configOptions.isEthHash()) {
return MainnetPantheonController.init( return MainnetPantheonController.init(
pantheonHome, storageProvider,
config, genesisConfigFile,
MainnetProtocolSchedule.fromConfig(configOptions), MainnetProtocolSchedule.fromConfig(configOptions),
syncConfig, syncConfig,
miningParameters, miningParameters,
nodeKeys); nodeKeys);
} else if (configOptions.isIbft()) { } else if (configOptions.isIbft()) {
return IbftPantheonController.init( return IbftPantheonController.init(
pantheonHome, config, syncConfig, ottomanTestnetOperation, networkId, nodeKeys); storageProvider,
genesisConfigFile,
syncConfig,
ottomanTestnetOperation,
networkId,
nodeKeys);
} else if (configOptions.isClique()) { } else if (configOptions.isClique()) {
return CliquePantheonController.init( return CliquePantheonController.init(
pantheonHome, config, syncConfig, miningParameters, networkId, nodeKeys); storageProvider, genesisConfigFile, syncConfig, miningParameters, networkId, nodeKeys);
} else { } else {
throw new IllegalArgumentException("Unknown consensus mechanism defined"); throw new IllegalArgumentException("Unknown consensus mechanism defined");
} }
@ -69,8 +71,6 @@ public interface PantheonController<C> extends Closeable {
ProtocolSchedule<C> getProtocolSchedule(); ProtocolSchedule<C> getProtocolSchedule();
GenesisConfigOptions getGenesisConfigOptions();
Synchronizer getSynchronizer(); Synchronizer getSynchronizer();
SubProtocolConfiguration subProtocolConfiguration(); SubProtocolConfiguration subProtocolConfiguration();

@ -23,6 +23,7 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockImporter; import tech.pegasys.pantheon.ethereum.core.BlockImporter;
import tech.pegasys.pantheon.ethereum.core.BlockSyncTestUtils; import tech.pegasys.pantheon.ethereum.core.BlockSyncTestUtils;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
@ -33,8 +34,11 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider;
import tech.pegasys.pantheon.util.uint.UInt256; import tech.pegasys.pantheon.util.uint.UInt256;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
@ -64,7 +68,6 @@ import org.junit.rules.TemporaryFolder;
/** Tests for {@link Runner}. */ /** Tests for {@link Runner}. */
public final class RunnerTest { public final class RunnerTest {
private static final int NETWORK_ID = 10;
@Rule public final TemporaryFolder temp = new TemporaryFolder(); @Rule public final TemporaryFolder temp = new TemporaryFolder();
@Test @Test
@ -93,7 +96,7 @@ public final class RunnerTest {
// Setup state with block data // Setup state with block data
try (final PantheonController<Void> controller = try (final PantheonController<Void> controller =
MainnetPantheonController.init( MainnetPantheonController.init(
dbAhead, createKeyValueStorageProvider(dbAhead),
GenesisConfigFile.mainnet(), GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(), MainnetProtocolSchedule.create(),
fastSyncConfig, fastSyncConfig,
@ -105,7 +108,7 @@ public final class RunnerTest {
// Setup Runner with blocks // Setup Runner with blocks
final PantheonController<Void> controllerAhead = final PantheonController<Void> controllerAhead =
MainnetPantheonController.init( MainnetPantheonController.init(
dbAhead, createKeyValueStorageProvider(dbAhead),
GenesisConfigFile.mainnet(), GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(), MainnetProtocolSchedule.create(),
fastSyncConfig, fastSyncConfig,
@ -136,16 +139,14 @@ public final class RunnerTest {
final WebSocketConfiguration behindWebSocketConfiguration = wsRpcConfiguration(); final WebSocketConfiguration behindWebSocketConfiguration = wsRpcConfiguration();
// Setup runner with no block data // Setup runner with no block data
final Path dbBehind = temp.newFolder().toPath();
final KeyPair behindDbNodeKeys = loadKeyPair(dbBehind.resolve("key").toFile());
final PantheonController<Void> controllerBehind = final PantheonController<Void> controllerBehind =
MainnetPantheonController.init( MainnetPantheonController.init(
temp.newFolder().toPath(), new InMemoryStorageProvider(),
GenesisConfigFile.mainnet(), GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(), MainnetProtocolSchedule.create(),
fastSyncConfig, fastSyncConfig,
new MiningParametersTestBuilder().enabled(false).build(), new MiningParametersTestBuilder().enabled(false).build(),
behindDbNodeKeys); KeyPair.generate());
final Runner runnerBehind = final Runner runnerBehind =
runnerBuilder.build( runnerBuilder.build(
Vertx.vertx(), Vertx.vertx(),
@ -162,7 +163,7 @@ public final class RunnerTest {
3, 3,
behindJsonRpcConfiguration, behindJsonRpcConfiguration,
behindWebSocketConfiguration, behindWebSocketConfiguration,
dbBehind, temp.newFolder().toPath(),
Collections.emptySet()); Collections.emptySet());
executorService.submit(runnerBehind::execute); executorService.submit(runnerBehind::execute);
@ -233,6 +234,10 @@ public final class RunnerTest {
} }
} }
private StorageProvider createKeyValueStorageProvider(final Path dbAhead) throws IOException {
return RocksDbStorageProvider.create(dbAhead);
}
private JsonRpcConfiguration jsonRpcConfiguration() { private JsonRpcConfiguration jsonRpcConfiguration() {
final JsonRpcConfiguration configuration = JsonRpcConfiguration.createDefault(); final JsonRpcConfiguration configuration = JsonRpcConfiguration.createDefault();
configuration.setPort(0); configuration.setPort(0);

@ -15,9 +15,10 @@ package tech.pegasys.pantheon.util;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.controller.MainnetPantheonController; import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.testutil.BlockTestUtil; import tech.pegasys.pantheon.testutil.BlockTestUtil;
@ -43,10 +44,18 @@ public final class BlockImporterTest {
@Test @Test
public void blockImport() throws IOException { public void blockImport() throws IOException {
final Path source = folder.newFile().toPath(); final Path source = folder.newFile().toPath();
final Path target = folder.newFolder().toPath();
BlockTestUtil.write1000Blocks(source); BlockTestUtil.write1000Blocks(source);
final PantheonController<?> targetController =
PantheonController.fromConfig(
GenesisConfigFile.mainnet(),
SynchronizerConfiguration.builder().build(),
new InMemoryStorageProvider(),
false,
1,
new MiningParametersTestBuilder().enabled(false).build(),
KeyPair.generate());
final BlockImporter.ImportResult result = final BlockImporter.ImportResult result =
blockImporter.importBlockchain(source, MainnetPantheonController.mainnet(target)); blockImporter.importBlockchain(source, targetController);
assertThat(result.count).isEqualTo(1000); assertThat(result.count).isEqualTo(1000);
assertThat(result.td).isEqualTo(UInt256.of(21991996248790L)); assertThat(result.td).isEqualTo(UInt256.of(21991996248790L));
} }
@ -54,7 +63,6 @@ public final class BlockImporterTest {
@Test @Test
public void ibftImport() throws IOException { public void ibftImport() throws IOException {
final Path source = folder.newFile().toPath(); final Path source = folder.newFile().toPath();
final Path target = folder.newFolder().toPath();
final String config = Resources.toString(Resources.getResource("ibft_genesis.json"), UTF_8); final String config = Resources.toString(Resources.getResource("ibft_genesis.json"), UTF_8);
try { try {
@ -69,9 +77,9 @@ public final class BlockImporterTest {
final PantheonController<?> controller = final PantheonController<?> controller =
PantheonController.fromConfig( PantheonController.fromConfig(
GenesisConfigFile.fromConfig(config),
SynchronizerConfiguration.builder().build(), SynchronizerConfiguration.builder().build(),
config, new InMemoryStorageProvider(),
target,
false, false,
10, 10,
new MiningParametersTestBuilder().enabled(false).build(), new MiningParametersTestBuilder().enabled(false).build(),

Loading…
Cancel
Save