Search in sources :

Example 1 with VoteProcessingResult

use of com.radixdlt.consensus.bft.VoteProcessingResult in project radixdlt by radixdlt.

the class PendingVotesTest method when_inserting_valid_timeout_votes__then_tc_is_formed.

@Test
public void when_inserting_valid_timeout_votes__then_tc_is_formed() {
    HashCode vertexId1 = HashUtils.random256();
    HashCode vertexId2 = HashUtils.random256();
    Vote vote1 = makeSignedVoteFor(mock(BFTNode.class), View.genesis(), vertexId1);
    when(vote1.getTimeoutSignature()).thenReturn(Optional.of(mock(ECDSASignature.class)));
    when(vote1.isTimeout()).thenReturn(true);
    Vote vote2 = makeSignedVoteFor(mock(BFTNode.class), View.genesis(), vertexId2);
    when(vote2.getTimeoutSignature()).thenReturn(Optional.of(mock(ECDSASignature.class)));
    when(vote2.isTimeout()).thenReturn(true);
    BFTValidatorSet validatorSet = BFTValidatorSet.from(Arrays.asList(BFTValidator.from(vote1.getAuthor(), UInt256.ONE), BFTValidator.from(vote2.getAuthor(), UInt256.ONE)));
    assertTrue(this.pendingVotes.insertVote(vote1, validatorSet) instanceof VoteProcessingResult.VoteAccepted);
    VoteProcessingResult result2 = this.pendingVotes.insertVote(vote2, validatorSet);
    assertTrue(result2 instanceof VoteProcessingResult.QuorumReached);
    assertTrue(((VoteProcessingResult.QuorumReached) result2).getViewVotingResult() instanceof ViewVotingResult.FormedTC);
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) HashCode(com.google.common.hash.HashCode) ViewVotingResult(com.radixdlt.consensus.bft.ViewVotingResult) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) VoteProcessingResult(com.radixdlt.consensus.bft.VoteProcessingResult) Test(org.junit.Test)

Example 2 with VoteProcessingResult

use of com.radixdlt.consensus.bft.VoteProcessingResult in project radixdlt by radixdlt.

the class PendingVotes method insertVote.

/**
 * Inserts a vote for a given vertex, attempting to form either a quorum certificate for that
 * vertex or a timeout certificate. A quorum will only be formed if permitted by the {@link
 * BFTValidatorSet}.
 *
 * @param vote The vote to be inserted
 * @return The result of vote processing
 */
public VoteProcessingResult insertVote(Vote vote, BFTValidatorSet validatorSet) {
    final BFTNode node = vote.getAuthor();
    final VoteData voteData = vote.getVoteData();
    final HashCode voteDataHash = this.hasher.hash(voteData);
    if (!validatorSet.containsNode(node)) {
        return VoteProcessingResult.rejected(VoteRejectedReason.INVALID_AUTHOR);
    }
    if (!replacePreviousVote(node, vote, voteDataHash)) {
        return VoteProcessingResult.rejected(VoteRejectedReason.DUPLICATE_VOTE);
    }
    return processVoteForQC(vote, validatorSet).<VoteProcessingResult>map(VoteProcessingResult::qcQuorum).or(() -> processVoteForTC(vote, validatorSet).map(VoteProcessingResult::tcQuorum)).orElseGet(VoteProcessingResult::accepted);
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) HashCode(com.google.common.hash.HashCode) VoteProcessingResult(com.radixdlt.consensus.bft.VoteProcessingResult)

Aggregations

HashCode (com.google.common.hash.HashCode)2 BFTNode (com.radixdlt.consensus.bft.BFTNode)2 VoteProcessingResult (com.radixdlt.consensus.bft.VoteProcessingResult)2 BFTValidatorSet (com.radixdlt.consensus.bft.BFTValidatorSet)1 ViewVotingResult (com.radixdlt.consensus.bft.ViewVotingResult)1 Test (org.junit.Test)1