use of org.hyperledger.besu.ethereum.rlp.RLPInput 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.rlp.RLPInput in project besu by hyperledger.
the class QbftPayloadTest method readingConsensusRoundExpectsScalarValues.
@Test
public void readingConsensusRoundExpectsScalarValues() {
final long sequence = 100;
final int round = 8;
final BytesValueRLPOutput out = new BytesValueRLPOutput();
out.startList();
out.writeLongScalar(sequence);
out.writeIntScalar(round);
out.endList();
final RLPInput rlpIn = RLP.input(out.encoded());
rlpIn.enterList();
final ConsensusRoundIdentifier roundIdentifier = QbftPayload.readConsensusRound(rlpIn);
rlpIn.leaveList();
assertThat(roundIdentifier.getSequenceNumber()).isEqualTo(sequence);
assertThat(roundIdentifier.getRoundNumber()).isEqualTo(round);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class RoundChange method decode.
public static RoundChange decode(final Bytes data, final BftExtraDataCodec bftExtraDataCodec) {
final RLPInput rlpIn = RLP.input(data);
rlpIn.enterList();
final SignedData<RoundChangePayload> payload = readPayload(rlpIn, RoundChangePayload::readFrom);
final Optional<Block> block;
if (rlpIn.nextIsList() && rlpIn.nextSize() == 0) {
rlpIn.skipNext();
block = Optional.empty();
} else {
block = Optional.of(Block.readFrom(rlpIn, BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec)));
}
final List<SignedData<PreparePayload>> prepares = rlpIn.readList(r -> readPayload(r, PreparePayload::readFrom));
rlpIn.leaveList();
return new RoundChange(payload, block, prepares);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput 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.rlp.RLPInput 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);
}
Aggregations