Search in sources :

Example 1 with MainnetBlockHeaderFunctions

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");
}
Also used : RollingFileReader(org.hyperledger.besu.util.io.RollingFileReader) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ArrayList(java.util.ArrayList) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)

Example 2 with MainnetBlockHeaderFunctions

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()));
}
Also used : BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) Before(org.junit.Before)

Example 3 with 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);
}
Also used : MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) Test(org.junit.Test)

Example 4 with MainnetBlockHeaderFunctions

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);
}
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 5 with MainnetBlockHeaderFunctions

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);
}
Also used : Duration(java.time.Duration) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) Before(org.junit.Before)

Aggregations

MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)39 Test (org.junit.Test)16 Block (org.hyperledger.besu.ethereum.core.Block)13 InMemoryKeyValueStorage (org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage)13 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)12 Before (org.junit.Before)12 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)9 KeyValueStoragePrefixedKeyBlockchainStorage (org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage)9 ArrayList (java.util.ArrayList)8 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)7 Bytes (org.apache.tuweni.bytes.Bytes)5 Hash (org.hyperledger.besu.datatypes.Hash)5 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)5 RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)5 ByteBuffer (java.nio.ByteBuffer)4 Address (org.hyperledger.besu.datatypes.Address)4 BlockchainStorage (org.hyperledger.besu.ethereum.chain.BlockchainStorage)4 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)4 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)4 RawMessage (org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage)4