Search in sources :

Example 1 with CliqueExtraData

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]));
}
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 CliqueExtraData

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();
}
Also used : ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) ScheduleBasedBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions) BlockHeaderBuilder(org.hyperledger.besu.ethereum.core.BlockHeaderBuilder) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData)

Example 3 with CliqueExtraData

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();
}
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 4 with CliqueExtraData

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);
}
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 5 with CliqueExtraData

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());
}
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

CliqueExtraData (org.hyperledger.besu.consensus.clique.CliqueExtraData)7 CliqueBlockHeaderFunctions (org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions)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)2 ValidatorVote (org.hyperledger.besu.consensus.common.validator.ValidatorVote)1 Hash (org.hyperledger.besu.datatypes.Hash)1 BlockHeaderBuilder (org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)1 BlockHeaderFunctions (org.hyperledger.besu.ethereum.core.BlockHeaderFunctions)1 ScheduleBasedBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions)1 Block (org.web3j.protocol.core.methods.response.EthBlock.Block)1