Search in sources :

Example 16 with Vote

use of com.radixdlt.consensus.Vote in project radixdlt by radixdlt.

the class PacemakerTest method when_local_timeout__then_resend_previous_vote.

@Test
public void when_local_timeout__then_resend_previous_vote() {
    View view = View.of(0);
    Vote lastVote = mock(Vote.class);
    Vote lastVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.of(lastVote));
    when(this.safetyRules.timeoutVote(lastVote)).thenReturn(lastVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(0), mock(HighQC.class), mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(viewUpdate, 0L));
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(lastVoteWithTimeout));
    verifyNoMoreInteractions(this.vertexStore);
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).timeoutVote(lastVote);
    verifyNoMoreInteractions(this.safetyRules);
}
Also used : ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) HighQC(com.radixdlt.consensus.HighQC) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 17 with Vote

use of com.radixdlt.consensus.Vote in project radixdlt by radixdlt.

the class SafetyRulesTest method when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(1));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex proposal = mock(VerifiedVertex.class);
    when(proposal.touchesGenesis()).thenReturn(true);
    when(proposal.hasDirectParent()).thenReturn(true);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(1));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(2));
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandParent);
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 18 with Vote

use of com.radixdlt.consensus.Vote in project radixdlt by radixdlt.

the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(1));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex proposal = mock(VerifiedVertex.class);
    when(proposal.touchesGenesis()).thenReturn(false);
    when(proposal.hasDirectParent()).thenReturn(false);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(4));
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandParent);
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 19 with Vote

use of com.radixdlt.consensus.Vote in project radixdlt by radixdlt.

the class SafetyRulesTest method when_timeout_already_timed_out_vote_than_the_same_vote_is_returned.

@Test
public void when_timeout_already_timed_out_vote_than_the_same_vote_is_returned() {
    Vote vote = mock(Vote.class);
    when(vote.isTimeout()).thenReturn(true);
    assertEquals(vote, safetyRules.timeoutVote(vote));
}
Also used : Vote(com.radixdlt.consensus.Vote) Test(org.junit.Test)

Example 20 with Vote

use of com.radixdlt.consensus.Vote in project radixdlt by radixdlt.

the class BFTEventReducerTest method when_process_vote_with_quorum__then_processed.

@Test
public void when_process_vote_with_quorum__then_processed() {
    BFTNode author = mock(BFTNode.class);
    Vote vote = mock(Vote.class);
    when(vote.getAuthor()).thenReturn(author);
    QuorumCertificate qc = mock(QuorumCertificate.class);
    HighQC highQc = mock(HighQC.class);
    QuorumCertificate highestCommittedQc = mock(QuorumCertificate.class);
    when(highQc.highestCommittedQC()).thenReturn(highestCommittedQc);
    when(vote.getView()).thenReturn(View.of(1));
    when(this.pendingVotes.insertVote(any(), any())).thenReturn(VoteProcessingResult.qcQuorum(qc));
    when(this.vertexStore.highQC()).thenReturn(highQc);
    // Move to view 1
    this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(1), highQc, mock(BFTNode.class), this.self));
    this.bftEventReducer.processVote(vote);
    verify(this.viewQuorumReachedEventDispatcher, times(1)).dispatch(any());
    verify(this.pendingVotes, times(1)).insertVote(eq(vote), any());
    verifyNoMoreInteractions(this.pendingVotes);
}
Also used : HighQC(com.radixdlt.consensus.HighQC) Vote(com.radixdlt.consensus.Vote) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Aggregations

Vote (com.radixdlt.consensus.Vote)22 Test (org.junit.Test)16 HighQC (com.radixdlt.consensus.HighQC)10 View (com.radixdlt.consensus.bft.View)8 BFTHeader (com.radixdlt.consensus.BFTHeader)7 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 Builder (com.radixdlt.consensus.safety.SafetyState.Builder)7 ECDSASignature (com.radixdlt.crypto.ECDSASignature)6 BFTNode (com.radixdlt.consensus.bft.BFTNode)4 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)4 HashSigner (com.radixdlt.consensus.HashSigner)3 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)3 HashCode (com.google.common.hash.HashCode)2 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)2 Proposal (com.radixdlt.consensus.Proposal)2 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)2 BFTHighQCUpdate (com.radixdlt.consensus.bft.BFTHighQCUpdate)2 BFTRebuildUpdate (com.radixdlt.consensus.bft.BFTRebuildUpdate)2