use of org.hyperledger.besu.ethereum.core.BlockHeaderBuilder in project besu by hyperledger.
the class ProofOfWorkValidationRuleTest method failsWithNonEip1559BlockAfterFork.
@Test
public void failsWithNonEip1559BlockAfterFork() {
final ProofOfWorkValidationRule proofOfWorkValidationRule = new ProofOfWorkValidationRule(new EpochCalculator.DefaultEpochCalculator(), PoWHasher.ETHASH_LIGHT, Optional.of(FeeMarket.london(0L)));
final BlockHeaderBuilder headerBuilder = BlockHeaderBuilder.fromHeader(blockHeader).difficulty(Difficulty.ONE).blockHeaderFunctions(mainnetBlockHashFunction()).timestamp(1);
final BlockHeader preHeader = headerBuilder.buildBlockHeader();
final Hash headerHash = validationRule.hashHeader(preHeader);
PoWSolution solution = PoWHasher.ETHASH_LIGHT.hash(preHeader.getNonce(), preHeader.getNumber(), new EpochCalculator.DefaultEpochCalculator(), headerHash);
final BlockHeader header = headerBuilder.mixHash(solution.getMixHash()).buildBlockHeader();
assertThat(proofOfWorkValidationRule.validate(header, parentHeader)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.BlockHeaderBuilder in project besu by hyperledger.
the class CliqueBlockInterfaceTest method blendingDropVoteToHeaderResultsInHeaderWithNonceOfZero.
@Test
public void blendingDropVoteToHeaderResultsInHeaderWithNonceOfZero() {
final ValidatorVote vote = new ValidatorVote(DROP, AddressHelpers.ofValue(1), AddressHelpers.ofValue(2));
final BlockHeaderBuilder builderWithVote = CliqueBlockInterface.createHeaderBuilderWithVoteHeaders(builder, Optional.of(vote));
final BlockHeader header = builderWithVote.buildBlockHeader();
assertThat(header.getCoinbase()).isEqualTo(vote.getRecipient());
assertThat(header.getNonce()).isEqualTo(0x0L);
}
use of org.hyperledger.besu.ethereum.core.BlockHeaderBuilder in project besu by hyperledger.
the class CliqueBlockHashingTest method createGenesisBlock.
private BlockHeader createGenesisBlock() {
// The following was taken from the Rinkeby genesis file
final BlockHeaderBuilder builder = new BlockHeaderBuilder();
builder.difficulty(Difficulty.ONE);
builder.extraData(Bytes.fromHexString("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
builder.gasLimit(4700000);
builder.gasUsed(0);
// Do not do Hash.
builder.logsBloom(LogsBloomFilter.fromHexString("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
builder.coinbase(Address.fromHexString("0x0000000000000000000000000000000000000000"));
builder.mixHash(Hash.ZERO);
builder.nonce(0);
builder.number(0);
builder.parentHash(Hash.ZERO);
builder.receiptsRoot(Hash.ZERO);
builder.ommersHash(Hash.ZERO);
builder.stateRoot(Hash.ZERO);
builder.timestamp(1492009146);
builder.transactionsRoot(Hash.ZERO);
builder.blockHeaderFunctions(new CliqueBlockHeaderFunctions());
return builder.buildBlockHeader();
}
use of org.hyperledger.besu.ethereum.core.BlockHeaderBuilder in project besu by hyperledger.
the class CliqueBlockHashingTest method createKnownHeaderFromCapturedData.
private BlockHeader createKnownHeaderFromCapturedData() {
// The following text was a dump from the geth console of the 30_000 block on Rinkeby.
// eth.getBlock(30000)
final BlockHeaderBuilder builder = new BlockHeaderBuilder();
builder.difficulty(Difficulty.of(2));
builder.extraData(Bytes.fromHexString("0xd783010600846765746887676f312e372e33856c696e7578000000000000000042eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f0c5bc40d0535af16266714ccb26fc49448c10bdf2969411514707d7442956b3397b09a980f4bea9347f70eea52183326247a0239b6d01fa0b07afc44e8a05463301"));
builder.gasLimit(4712388);
builder.gasUsed(0);
// Do not do Hash.
builder.logsBloom(LogsBloomFilter.fromHexString("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
builder.coinbase(Address.fromHexString("0x0000000000000000000000000000000000000000"));
builder.mixHash(Hash.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000"));
builder.nonce(0);
builder.number(30000);
builder.parentHash(Hash.fromHexString("0xff570bb9893cb9bac64e346419fb9ad51e203c1cf6da5cfcc0c0dff3351b454b"));
builder.receiptsRoot(Hash.fromHexString("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"));
builder.ommersHash(Hash.fromHexString("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"));
builder.stateRoot(Hash.fromHexString("0x829b58faacea7b0aa625617ba90c93e08150bed160364a7a96505e8205043d34"));
builder.timestamp(1492460444);
builder.transactionsRoot(Hash.fromHexString("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"));
builder.blockHeaderFunctions(new CliqueBlockHeaderFunctions());
return builder.buildBlockHeader();
}
use of org.hyperledger.besu.ethereum.core.BlockHeaderBuilder in project besu by hyperledger.
the class CliqueBlockCreator method createFinalBlockHeader.
/**
* Responsible for signing (hash of) the block (including MixHash and Nonce), and then injecting
* the seal into the extraData. This is called after a suitable set of transactions have been
* identified, and all resulting hashes have been inserted into the passed-in SealableBlockHeader.
*
* @param sealableBlockHeader A block header containing StateRoots, TransactionHashes etc.
* @return The blockhead which is to be added to the block being proposed.
*/
@Override
protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableBlockHeader) {
final BlockHeaderFunctions blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
final BlockHeaderBuilder builder = BlockHeaderBuilder.create().populateFrom(sealableBlockHeader).mixHash(Hash.ZERO).blockHeaderFunctions(blockHeaderFunctions);
final Optional<ValidatorVote> vote = determineCliqueVote(sealableBlockHeader);
final BlockHeaderBuilder builderIncludingProposedVotes = CliqueBlockInterface.createHeaderBuilderWithVoteHeaders(builder, vote);
final CliqueExtraData sealedExtraData = constructSignedExtraData(builderIncludingProposedVotes.buildBlockHeader());
// Replace the extraData in the BlockHeaderBuilder, and return header.
return builderIncludingProposedVotes.extraData(sealedExtraData.encode()).buildBlockHeader();
}
Aggregations