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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations