use of org.hyperledger.besu.ethereum.core.BlockBody 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.core.BlockBody in project besu by hyperledger.
the class PkiQbftBlockCreatorTest method createBlockBeingProposed.
private Block createBlockBeingProposed() {
final BftExtraData originalExtraData = createExtraData(blockHeaderBuilder.buildHeader(), extraDataCodec);
final BlockHeader blockHeaderWithExtraData = blockHeaderBuilder.extraData(extraDataCodec.encode(originalExtraData)).buildHeader();
final Block block = new Block(blockHeaderWithExtraData, new BlockBody(Collections.emptyList(), Collections.emptyList()));
when(blockCreator.createBlock(eq(1L))).thenReturn(block);
return block;
}
use of org.hyperledger.besu.ethereum.core.BlockBody in project besu by hyperledger.
the class ValidationTestUtils method readBody.
public static BlockBody readBody(final long num) throws IOException {
final RLPInput input = new BytesValueRLPInput(Bytes.wrap(Resources.toByteArray(EthHashTest.class.getResource(String.format("block_%d.blocks", num)))), false);
input.enterList();
input.skipNext();
final List<Transaction> transactions = input.readList(Transaction::readFrom);
final List<BlockHeader> ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()));
return new BlockBody(transactions, ommers);
}
use of org.hyperledger.besu.ethereum.core.BlockBody in project besu by hyperledger.
the class ValidationTestUtils method readBlock.
public static Block readBlock(final long num) throws IOException {
final RLPInput input = new BytesValueRLPInput(Bytes.wrap(Resources.toByteArray(EthHashTest.class.getResource(String.format("block_%d.blocks", num)))), false);
input.enterList();
final BlockHeader header = BlockHeader.readFrom(input, new MainnetBlockHeaderFunctions());
final List<Transaction> transactions = input.readList(Transaction::readFrom);
final List<BlockHeader> ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()));
final BlockBody body = new BlockBody(transactions, ommers);
return new Block(header, body);
}
use of org.hyperledger.besu.ethereum.core.BlockBody in project besu by hyperledger.
the class BaseFeeBlockBodyValidatorTest method BlockBodyValidatorFail_MaxFeePerGas.
@Test
public void BlockBodyValidatorFail_MaxFeePerGas() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody()).thenReturn(new BlockBody(List.of(// underpriced eip1559 transaction
new TransactionTestFixture().maxFeePerGas(Optional.of(Wei.of(1L))).maxPriorityFeePerGas(Optional.of(Wei.of(10L))).type(TransactionType.EIP1559).createTransaction(keyPair)), Collections.emptyList()));
assertThat(blockBodyValidator.validateTransactionGasPrice(block)).isFalse();
}
Aggregations