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