use of org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions 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.CliqueBlockHeaderFunctions 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.CliqueBlockHeaderFunctions 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.CliqueBlockHeaderFunctions 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