use of org.hyperledger.besu.consensus.clique.CliqueExtraData in project besu by hyperledger.
the class CliqueMinerExecutorTest method extraDataCreatedOnEpochBlocksContainsValidators.
@Test
public void extraDataCreatedOnEpochBlocksContainsValidators() {
final Bytes vanityData = generateRandomVanityData();
final CliqueMinerExecutor executor = new CliqueMinerExecutor(cliqueProtocolContext, CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, CliqueMinerExecutorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), proposerNodeKey, new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(vanityData).miningEnabled(false).build(), mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH));
// NOTE: Passing in the *parent* block, so must be 1 less than EPOCH
final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH - 1).buildHeader();
final Bytes extraDataBytes = executor.calculateExtraData(header);
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeaderBuilder.number(EPOCH_LENGTH).extraData(extraDataBytes).blockHeaderFunctions(new CliqueBlockHeaderFunctions()).buildHeader());
assertThat(cliqueExtraData.getVanityData()).isEqualTo(vanityData);
assertThat(cliqueExtraData.getValidators()).containsExactly(validatorList.toArray(new Address[0]));
}
use of org.hyperledger.besu.consensus.clique.CliqueExtraData 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();
}
use of org.hyperledger.besu.consensus.clique.CliqueExtraData in project besu by hyperledger.
the class ExpectedBlockHasProposer method proposerAddress.
private Address proposerAddress(final Node node) {
final Block block = node.execute(eth.block());
final BlockHeader blockHeader = BlockUtils.createBlockHeader(block, new CliqueBlockHeaderFunctions());
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeader);
return cliqueExtraData.getProposerAddress();
}
use of org.hyperledger.besu.consensus.clique.CliqueExtraData in project besu by hyperledger.
the class CliqueMinerExecutorTest method shouldUseLatestVanityData.
@Test
public void shouldUseLatestVanityData() {
final Bytes initialVanityData = generateRandomVanityData();
final Bytes modifiedVanityData = generateRandomVanityData();
final CliqueMinerExecutor executor = new CliqueMinerExecutor(cliqueProtocolContext, CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, CliqueMinerExecutorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), proposerNodeKey, new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(initialVanityData).miningEnabled(false).build(), mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH));
executor.setExtraData(modifiedVanityData);
final Bytes extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader());
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeaderBuilder.number(EPOCH_LENGTH).extraData(extraDataBytes).blockHeaderFunctions(new CliqueBlockHeaderFunctions()).buildHeader());
assertThat(cliqueExtraData.getVanityData()).isEqualTo(modifiedVanityData);
}
use of org.hyperledger.besu.consensus.clique.CliqueExtraData in project besu by hyperledger.
the class CliqueMinerExecutorTest method extraDataForNonEpochBlocksDoesNotContainValidaors.
@Test
public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
final Bytes vanityData = generateRandomVanityData();
final CliqueMinerExecutor executor = new CliqueMinerExecutor(cliqueProtocolContext, CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, CliqueMinerExecutorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), proposerNodeKey, new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(vanityData).miningEnabled(false).build(), mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH));
// Parent block was epoch, so the next block should contain no validators.
final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH).buildHeader();
final Bytes extraDataBytes = executor.calculateExtraData(header);
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeaderBuilder.number(EPOCH_LENGTH).extraData(extraDataBytes).blockHeaderFunctions(new CliqueBlockHeaderFunctions()).buildHeader());
assertThat(cliqueExtraData.getVanityData()).isEqualTo(vanityData);
assertThat(cliqueExtraData.getValidators()).isEqualTo(Lists.newArrayList());
}
Aggregations