Search in sources :

Example 1 with ValidatorVote

use of org.hyperledger.besu.consensus.common.validator.ValidatorVote 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);
}
Also used : ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BlockHeaderBuilder(org.hyperledger.besu.ethereum.core.BlockHeaderBuilder) Test(org.junit.Test)

Example 2 with ValidatorVote

use of org.hyperledger.besu.consensus.common.validator.ValidatorVote 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 ValidatorVote

use of org.hyperledger.besu.consensus.common.validator.ValidatorVote in project besu by hyperledger.

the class BftBlockInterface method extractVoteFromHeader.

@Override
public Optional<ValidatorVote> extractVoteFromHeader(final BlockHeader header) {
    final BftExtraData bftExtraData = bftExtraDataCodec.decode(header);
    if (bftExtraData.getVote().isPresent()) {
        final Vote headerVote = bftExtraData.getVote().get();
        final ValidatorVote vote = new ValidatorVote(headerVote.isAuth() ? VoteType.ADD : VoteType.DROP, getProposerOfBlock(header), headerVote.getRecipient());
        return Optional.of(vote);
    }
    return Optional.empty();
}
Also used : ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote)

Example 4 with ValidatorVote

use of org.hyperledger.besu.consensus.common.validator.ValidatorVote in project besu by hyperledger.

the class CliqueBlockInterface method createHeaderBuilderWithVoteHeaders.

public static BlockHeaderBuilder createHeaderBuilderWithVoteHeaders(final BlockHeaderBuilder builder, final Optional<ValidatorVote> vote) {
    final BlockHeaderBuilder voteHeaderBuilder = BlockHeaderBuilder.fromBuilder(builder);
    if (vote.isPresent()) {
        final ValidatorVote voteToCast = vote.get();
        voteHeaderBuilder.nonce(voteToValue.get(voteToCast.getVotePolarity()));
        voteHeaderBuilder.coinbase(voteToCast.getRecipient());
    } else {
        voteHeaderBuilder.nonce(voteToValue.get(VoteType.DROP));
        voteHeaderBuilder.coinbase(NO_VOTE_SUBJECT);
    }
    return voteHeaderBuilder;
}
Also used : ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) BlockHeaderBuilder(org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)

Example 5 with ValidatorVote

use of org.hyperledger.besu.consensus.common.validator.ValidatorVote in project besu by hyperledger.

the class IbftLegacyBlockInterfaceTest method headerWithNonceOfMaxLongReportsAddVote.

@Test
public void headerWithNonceOfMaxLongReportsAddVote() {
    headerBuilder.nonce(0xFFFFFFFFFFFFFFFFL).coinbase(AddressHelpers.ofValue(2));
    final BlockHeader header = TestHelpers.createIbftSignedBlockHeader(headerBuilder, proposerKeys, validatorList);
    final Optional<ValidatorVote> extractedVote = blockInterface.extractVoteFromHeader(header);
    assertThat(extractedVote).contains(new ValidatorVote(ADD, proposerAddress, header.getCoinbase()));
}
Also used : ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

ValidatorVote (org.hyperledger.besu.consensus.common.validator.ValidatorVote)49 Test (org.junit.Test)41 Address (org.hyperledger.besu.datatypes.Address)15 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)9 BlockHeaderBuilder (org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)6 VoteType (org.hyperledger.besu.consensus.common.validator.VoteType)3 ArrayList (java.util.ArrayList)2 Bytes (org.apache.tuweni.bytes.Bytes)2 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)2 GasPricePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CliqueExtraData (org.hyperledger.besu.consensus.clique.CliqueExtraData)1 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)1 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)1 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)1 VoteProvider (org.hyperledger.besu.consensus.common.validator.VoteProvider)1 BlockHeaderFunctions (org.hyperledger.besu.ethereum.core.BlockHeaderFunctions)1