Search in sources :

Example 1 with KeyValueStoragePrefixedKeyBlockchainStorage

use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage in project besu by hyperledger.

the class QbftBesuControllerBuilderTest method setup.

@Before
public void setup() {
    // besu controller setup
    when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString());
    when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString());
    when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString());
    when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString());
    when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1));
    when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions);
    when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions);
    when(storageProvider.createBlockchainStorage(any())).thenReturn(new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()));
    when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)).thenReturn(worldStateStorage);
    when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true);
    when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class));
    when(worldStatePreimageStorage.updater()).thenReturn(mock(WorldStatePreimageStorage.Updater.class));
    when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage);
    when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1);
    when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1);
    when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1);
    when(observableMetricsSystem.createLabelledCounter(any(), anyString(), anyString(), anyString())).thenReturn(labels -> null);
    when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L));
    // qbft prepForBuild setup
    when(genesisConfigOptions.getQbftConfigOptions()).thenReturn(new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT));
    when(genesisConfigOptions.getTransitions()).thenReturn(mock(TransitionsConfigOptions.class));
    when(genesisConfigFile.getExtraData()).thenReturn(QbftExtraDataCodec.createGenesisExtraDataString(List.of(Address.fromHexString("1"))));
    qbftBesuControllerBuilder = new QbftBesuControllerBuilder().genesisConfigFile(genesisConfigFile).synchronizerConfiguration(synchronizerConfiguration).ethProtocolConfiguration(ethProtocolConfiguration).networkId(networkId).miningParameters(miningParameters).metricsSystem(observableMetricsSystem).privacyParameters(privacyParameters).dataDirectory(tempDirRule.getRoot().toPath()).clock(clock).transactionPoolConfiguration(poolConfiguration).nodeKey(nodeKey).storageProvider(storageProvider).gasLimitCalculator(gasLimitCalculator).evmConfiguration(EvmConfiguration.DEFAULT);
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) TransitionsConfigOptions(org.hyperledger.besu.config.TransitionsConfigOptions) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) Before(org.junit.Before)

Example 2 with KeyValueStoragePrefixedKeyBlockchainStorage

use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage in project besu by hyperledger.

the class PrunerTest method shouldCleanUpPruningStrategyOnShutdown.

@Test
public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException {
    final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions());
    final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0);
    final Pruner pruner = new Pruner(markSweepPruner, blockchain, new PrunerConfiguration(0, 1), mockExecutorService);
    pruner.start();
    pruner.stop();
    verify(markSweepPruner).cleanup();
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockchainStorage(org.hyperledger.besu.ethereum.chain.BlockchainStorage) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) Test(org.junit.Test)

Example 3 with KeyValueStoragePrefixedKeyBlockchainStorage

use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage in project besu by hyperledger.

the class PrunerTest method abortsPruningWhenFullyMarkedBlockNoLongerOnCanonicalChain.

@Test
public void abortsPruningWhenFullyMarkedBlockNoLongerOnCanonicalChain() {
    final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions());
    final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0);
    // start pruner so it can start handling block added events
    final Pruner pruner = new Pruner(markSweepPruner, blockchain, new PrunerConfiguration(0, 1), mockExecutorService);
    pruner.start();
    /*
     Set up pre-marking state:
      O <---- marking of this block's parent will begin when this block is added
      |
      |  O <- this is a fork as of now (non-canonical)
      O  | <- this is the initially canonical block that will be marked
       \/
       O <--- the common ancestor when the reorg happens
    */
    final Block initiallyCanonicalBlock = appendBlockWithParent(blockchain, genesisBlock);
    appendBlockWithParent(blockchain, initiallyCanonicalBlock);
    final Block forkBlock = appendBlockWithParent(blockchain, genesisBlock);
    /*
      Cause reorg:
     Set up pre-marking state:
      O
      |  O <---- this block causes a reorg; this branch becomes canonical
      |  O <---- which means that state here is referring to nodes from the common ancestor block,
      O  | <- because this was block at which marking began
       \/
       O
    */
    appendBlockWithParent(blockchain, forkBlock);
    verify(markSweepPruner).mark(initiallyCanonicalBlock.getHeader().getStateRoot());
    verify(markSweepPruner, never()).sweepBefore(anyLong());
    pruner.stop();
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockchainStorage(org.hyperledger.besu.ethereum.chain.BlockchainStorage) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) Test(org.junit.Test)

Example 4 with KeyValueStoragePrefixedKeyBlockchainStorage

use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage in project besu by hyperledger.

the class PrunerTest method shouldMarkCorrectBlockAndSweep.

@Test
public void shouldMarkCorrectBlockAndSweep() throws ExecutionException, InterruptedException {
    final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions());
    final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0);
    final Pruner pruner = new Pruner(markSweepPruner, blockchain, new PrunerConfiguration(0, 1), mockExecutorService);
    pruner.start();
    final Block block1 = appendBlockWithParent(blockchain, genesisBlock);
    appendBlockWithParent(blockchain, block1);
    appendBlockWithParent(blockchain, blockchain.getChainHeadBlock());
    verify(markSweepPruner).mark(block1.getHeader().getStateRoot());
    verify(markSweepPruner).sweepBefore(1);
    pruner.stop();
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockchainStorage(org.hyperledger.besu.ethereum.chain.BlockchainStorage) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) Test(org.junit.Test)

Example 5 with KeyValueStoragePrefixedKeyBlockchainStorage

use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage in project besu by hyperledger.

the class PrunerTest method shouldOnlySweepAfterBlockConfirmationPeriodAndRetentionPeriodEnds.

@Test
public void shouldOnlySweepAfterBlockConfirmationPeriodAndRetentionPeriodEnds() {
    final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions());
    final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0);
    final Pruner pruner = new Pruner(markSweepPruner, blockchain, new PrunerConfiguration(1, 2), mockExecutorService);
    pruner.start();
    final Hash markBlockStateRootHash = appendBlockWithParent(blockchain, genesisBlock).getHeader().getStateRoot();
    verify(markSweepPruner, never()).mark(markBlockStateRootHash);
    verify(markSweepPruner, never()).sweepBefore(anyLong());
    appendBlockWithParent(blockchain, blockchain.getChainHeadBlock());
    verify(markSweepPruner).mark(markBlockStateRootHash);
    verify(markSweepPruner, never()).sweepBefore(anyLong());
    appendBlockWithParent(blockchain, blockchain.getChainHeadBlock());
    verify(markSweepPruner).sweepBefore(1);
    pruner.stop();
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockchainStorage(org.hyperledger.besu.ethereum.chain.BlockchainStorage) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) Hash(org.hyperledger.besu.datatypes.Hash) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) Test(org.junit.Test)

Aggregations

MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)9 KeyValueStoragePrefixedKeyBlockchainStorage (org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage)9 InMemoryKeyValueStorage (org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage)9 Before (org.junit.Before)5 BlockchainStorage (org.hyperledger.besu.ethereum.chain.BlockchainStorage)4 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)4 Test (org.junit.Test)4 Block (org.hyperledger.besu.ethereum.core.Block)2 Optional (java.util.Optional)1 TransitionsConfigOptions (org.hyperledger.besu.config.TransitionsConfigOptions)1 MutableQbftConfigOptions (org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)1 Hash (org.hyperledger.besu.datatypes.Hash)1 BlockBroadcaster (org.hyperledger.besu.ethereum.eth.sync.BlockBroadcaster)1 SyncState (org.hyperledger.besu.ethereum.eth.sync.state.SyncState)1 ImmutableTransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration)1 TransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1