Search in sources :

Example 1 with VoteType

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();
}
Also used : VoteType(org.hyperledger.besu.consensus.common.validator.VoteType)

Example 2 with VoteType

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();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) VoteType(org.hyperledger.besu.consensus.common.validator.VoteType)

Example 3 with VoteType

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()));
}
Also used : Address(org.hyperledger.besu.datatypes.Address) ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) VoteType(org.hyperledger.besu.consensus.common.validator.VoteType) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with VoteType

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);
}
Also used : Vote(org.hyperledger.besu.consensus.common.bft.Vote) Address(org.hyperledger.besu.datatypes.Address) VoteType(org.hyperledger.besu.consensus.common.validator.VoteType) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException)

Example 5 with VoteType

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();
}
Also used : VoteType(org.hyperledger.besu.consensus.common.validator.VoteType)

Aggregations

VoteType (org.hyperledger.besu.consensus.common.validator.VoteType)7 Address (org.hyperledger.besu.datatypes.Address)5 ValidatorVote (org.hyperledger.besu.consensus.common.validator.ValidatorVote)3 Vote (org.hyperledger.besu.consensus.common.bft.Vote)2 RLPException (org.hyperledger.besu.ethereum.rlp.RLPException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1