use of org.hyperledger.besu.consensus.common.validator.VoteType in project besu by hyperledger.
the class QbftExtraDataCodec method encodeVote.
protected void encodeVote(final RLPOutput rlpOutput, final Vote vote) {
final VoteType voteType = vote.isAuth() ? VoteType.ADD : VoteType.DROP;
rlpOutput.startList();
rlpOutput.writeBytes(vote.getRecipient());
if (voteType == VoteType.ADD) {
rlpOutput.writeByte(ADD_BYTE_VALUE);
} else {
rlpOutput.writeNull();
}
rlpOutput.endList();
}
use of org.hyperledger.besu.consensus.common.validator.VoteType in project besu by hyperledger.
the class IbftLegacyBlockInterface method extractVoteFromHeader.
@Override
public Optional<ValidatorVote> extractVoteFromHeader(final BlockHeader header) {
final Address candidate = header.getCoinbase();
if (!candidate.equals(NO_VOTE_SUBJECT)) {
final Address proposer = getProposerOfBlock(header);
final VoteType votePolarity = voteToValue.inverse().get(header.getNonce());
final Address recipient = header.getCoinbase();
return Optional.of(new ValidatorVote(votePolarity, proposer, recipient));
}
return Optional.empty();
}
use of org.hyperledger.besu.consensus.common.validator.VoteType in project besu by hyperledger.
the class VoteProposer method getVote.
/**
* Gets a valid vote from our list of pending votes
*
* @param localAddress The address of this validator node
* @param tally the vote tally at the height of the chain we need a vote for
* @return Either an address with the vote (auth or drop) or no vote if we have no valid pending
* votes
*/
public Optional<ValidatorVote> getVote(final Address localAddress, final VoteTally tally) {
final Collection<Address> validators = tally.getValidators();
final List<Map.Entry<Address, VoteType>> validVotes = new ArrayList<>();
proposals.entrySet().forEach(proposal -> {
if (voteNotYetCast(localAddress, proposal.getKey(), proposal.getValue(), validators, tally)) {
validVotes.add(proposal);
}
});
if (validVotes.isEmpty()) {
return Optional.empty();
}
// Get the next position in the voting queue we should propose
final int currentVotePosition = votePosition.updateAndGet(i -> ++i % validVotes.size());
final Map.Entry<Address, VoteType> voteToCast = validVotes.get(currentVotePosition);
// Get a vote from the valid votes and return it
return Optional.of(new ValidatorVote(voteToCast.getValue(), localAddress, voteToCast.getKey()));
}
use of org.hyperledger.besu.consensus.common.validator.VoteType in project besu by hyperledger.
the class IbftExtraDataCodec method decodeVote.
private Vote decodeVote(final RLPInput rlpInput) {
rlpInput.enterList();
final Address recipient = Address.readFrom(rlpInput);
final VoteType vote = voteToValue.inverse().get(rlpInput.readByte());
if (vote == null) {
throw new RLPException("Vote field was of an incorrect binary value.");
}
rlpInput.leaveList();
return new Vote(recipient, vote);
}
use of org.hyperledger.besu.consensus.common.validator.VoteType in project besu by hyperledger.
the class IbftExtraDataCodec method encodeVote.
private void encodeVote(final RLPOutput rlpOutput, final Vote vote) {
final VoteType voteType = vote.isAuth() ? VoteType.ADD : VoteType.DROP;
rlpOutput.startList();
rlpOutput.writeBytes(vote.getRecipient());
rlpOutput.writeByte(voteToValue.get(voteType));
rlpOutput.endList();
}
Aggregations