Search in sources :

Example 1 with CliqueBlockHeaderFunctions

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]));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData) Test(org.junit.Test)

Example 2 with CliqueBlockHeaderFunctions

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();
}
Also used : CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) Block(org.web3j.protocol.core.methods.response.EthBlock.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData)

Example 3 with CliqueBlockHeaderFunctions

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData) Test(org.junit.Test)

Example 4 with CliqueBlockHeaderFunctions

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());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData) Test(org.junit.Test)

Aggregations

CliqueBlockHeaderFunctions (org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions)4 CliqueExtraData (org.hyperledger.besu.consensus.clique.CliqueExtraData)4 Bytes (org.apache.tuweni.bytes.Bytes)3 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 GasPricePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter)3 Test (org.junit.Test)3 Address (org.hyperledger.besu.datatypes.Address)1 Block (org.web3j.protocol.core.methods.response.EthBlock.Block)1