use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions in project besu by hyperledger.
the class RestoreState method restoreBlocks.
private void restoreBlocks() throws IOException {
try (final RollingFileReader headerReader = new RollingFileReader(this::headerFileName, compressed);
final RollingFileReader bodyReader = new RollingFileReader(this::bodyFileName, compressed);
final RollingFileReader receiptReader = new RollingFileReader(this::receiptFileName, compressed)) {
final MutableBlockchain blockchain = besuController.getProtocolContext().getBlockchain();
// target block is "including" the target block, so LE test not LT.
for (long i = 0; i <= targetBlock; i++) {
if (i % 100000 == 0) {
LOG.info("Loading chain data {} / {}", i, targetBlock);
}
final byte[] headerEntry = headerReader.readBytes();
final byte[] bodyEntry = bodyReader.readBytes();
final byte[] receiptEntry = receiptReader.readBytes();
final BlockHeaderFunctions functions = new MainnetBlockHeaderFunctions();
final BlockHeader header = BlockHeader.readFrom(new BytesValueRLPInput(Bytes.wrap(headerEntry), false, true), functions);
final BlockBody body = BlockBody.readFrom(new BytesValueRLPInput(Bytes.wrap(bodyEntry), false, true), functions);
final RLPInput receiptsRlp = new BytesValueRLPInput(Bytes.wrap(receiptEntry), false, true);
final int receiptsCount = receiptsRlp.enterList();
final List<TransactionReceipt> receipts = new ArrayList<>(receiptsCount);
for (int j = 0; j < receiptsCount; j++) {
receipts.add(TransactionReceipt.readFrom(receiptsRlp, true));
}
receiptsRlp.leaveList();
blockchain.appendBlock(new Block(header, body), receipts);
}
}
LOG.info("Chain data loaded");
}
use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions in project besu by hyperledger.
the class MainnetBlockValidatorTest method setup.
@Before
public void setup() {
when(protocolContext.getBlockchain()).thenReturn(blockchain);
when(protocolContext.getWorldStateArchive()).thenReturn(worldStateArchive);
mainnetBlockValidator = new MainnetBlockValidator(blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager);
badBlock = new BlockDataGenerator().block(BlockDataGenerator.BlockOptions.create().setBlockNumber(2).hasTransactions(false).setBlockHeaderFunctions(new MainnetBlockHeaderFunctions()));
}
use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions in project besu by hyperledger.
the class FastSyncStateStorageTest method shouldRoundTripHeader.
@Test
public void shouldRoundTripHeader() {
storage.storeState(syncStateWithHeader);
assertThat(storage.loadState(new MainnetBlockHeaderFunctions())).isEqualTo(syncStateWithHeader);
final FastSyncStateStorage newStorage = new FastSyncStateStorage(tempDir.toPath());
assertThat(newStorage.loadState(new MainnetBlockHeaderFunctions())).isEqualTo(syncStateWithHeader);
}
use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions 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.mainnet.MainnetBlockHeaderFunctions in project besu by hyperledger.
the class TransactionLogBloomCacherTest method setup.
@SuppressWarnings({ "unchecked", "ReturnValueIgnored" })
@Before
public void setup() throws IOException {
final BlockHeader fakeHeader = new BlockHeader(Hash.EMPTY, Hash.EMPTY, Address.ZERO, Hash.EMPTY, Hash.EMPTY, Hash.EMPTY, testLogsBloomFilter, Difficulty.ZERO, 0, 0, 0, 0, Bytes.EMPTY, null, Hash.EMPTY, 0, new MainnetBlockHeaderFunctions());
testHash = fakeHeader.getHash();
when(blockchain.getBlockHeader(anyLong())).thenReturn(Optional.of(fakeHeader));
when(scheduler.scheduleFutureTask(any(Runnable.class), any(Duration.class))).thenAnswer(invocation -> {
invocation.getArgument(0, Runnable.class).run();
return null;
});
transactionLogBloomCacher = new TransactionLogBloomCacher(blockchain, cacheDir.getRoot().toPath(), scheduler);
}
Aggregations