Search in sources :

Example 1 with Vote

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

the class BFTEventReducerTest method when_process_vote_with_quorum_wrong_view__then_ignored.

@Test
public void when_process_vote_with_quorum_wrong_view__then_ignored() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(3), mock(HighQC.class), mock(BFTNode.class), this.self));
    this.bftEventReducer.processVote(vote);
    verifyNoMoreInteractions(this.pendingVotes);
}
Also used : Vote(com.radixdlt.consensus.Vote) Test(org.junit.Test)

Example 2 with Vote

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

the class BFTEventVerifierTest method when_process_bad_signature_vote_then_should_not_be_forwarded.

@Test
public void when_process_bad_signature_vote_then_should_not_be_forwarded() {
    Vote vote = mock(Vote.class);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    when(vote.getSignature()).thenReturn(mock(ECDSASignature.class));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), any())).thenReturn(false);
    eventVerifier.processVote(vote);
    verify(forwardTo, never()).processVote(any());
}
Also used : Vote(com.radixdlt.consensus.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Example 3 with Vote

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

the class BFTEventVerifierTest method when_process_bad_timeout_signature_vote_then_should_not_be_forwarded.

@Test
public void when_process_bad_timeout_signature_vote_then_should_not_be_forwarded() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(0L);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    ECDSASignature voteSignature = mock(ECDSASignature.class);
    ECDSASignature timeoutSignature = mock(ECDSASignature.class);
    when(vote.getSignature()).thenReturn(voteSignature);
    when(vote.getTimeoutSignature()).thenReturn(Optional.of(timeoutSignature));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(voteSignature))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(timeoutSignature))).thenReturn(false);
    eventVerifier.processVote(vote);
    verify(forwardTo, never()).processVote(any());
}
Also used : Vote(com.radixdlt.consensus.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Example 4 with Vote

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

the class BFTEventVerifierTest method when_process_correct_vote_then_should_be_forwarded.

@Test
public void when_process_correct_vote_then_should_be_forwarded() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(0L);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    ECDSASignature voteSignature = mock(ECDSASignature.class);
    ECDSASignature timeoutSignature = mock(ECDSASignature.class);
    when(vote.getSignature()).thenReturn(voteSignature);
    when(vote.getTimeoutSignature()).thenReturn(Optional.of(timeoutSignature));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(voteSignature))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(timeoutSignature))).thenReturn(true);
    eventVerifier.processVote(vote);
    verify(forwardTo, times(1)).processVote(eq(vote));
}
Also used : Vote(com.radixdlt.consensus.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Example 5 with Vote

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

the class PacemakerTest method when_local_timeout__then_send_empty_vote_if_no_previous.

@Test
public void when_local_timeout__then_send_empty_vote_if_no_previous() {
    HighQC viewUpdateHighQc = mock(HighQC.class);
    QuorumCertificate committedQc = mock(QuorumCertificate.class);
    QuorumCertificate highestQc = mock(QuorumCertificate.class);
    when(viewUpdateHighQc.highestCommittedQC()).thenReturn(committedQc);
    when(viewUpdateHighQc.highestQC()).thenReturn(highestQc);
    BFTHeader highestQcProposed = mock(BFTHeader.class);
    HashCode highQcParentVertexId = mock(HashCode.class);
    when(highestQcProposed.getVertexId()).thenReturn(highQcParentVertexId);
    when(highestQc.getProposed()).thenReturn(highestQcProposed);
    when(committedQc.getView()).thenReturn(View.of(0));
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(1), viewUpdateHighQc, mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processViewUpdate(viewUpdate);
    View view = View.of(1);
    Vote emptyVote = mock(Vote.class);
    Vote emptyVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    BFTHeader bftHeader = mock(BFTHeader.class);
    HighQC highQC = mock(HighQC.class);
    BFTInsertUpdate bftInsertUpdate = mock(BFTInsertUpdate.class);
    when(bftInsertUpdate.getHeader()).thenReturn(bftHeader);
    PreparedVertex preparedVertex = mock(PreparedVertex.class);
    when(preparedVertex.getView()).thenReturn(view);
    when(preparedVertex.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    VerifiedVertexStoreState vertexStoreState = mock(VerifiedVertexStoreState.class);
    when(vertexStoreState.getHighQC()).thenReturn(highQC);
    when(bftInsertUpdate.getInserted()).thenReturn(preparedVertex);
    when(bftInsertUpdate.getVertexStoreState()).thenReturn(vertexStoreState);
    var node = BFTNode.random();
    when(preparedVertex.getId()).thenReturn(hasher.hash(UnverifiedVertex.createTimeout(highestQc, view, node)));
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.empty());
    when(this.safetyRules.createVote(any(), any(), anyLong(), any())).thenReturn(emptyVote);
    when(this.safetyRules.timeoutVote(emptyVote)).thenReturn(emptyVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    when(this.vertexStore.getPreparedVertex(any())).thenReturn(Optional.empty());
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(ViewUpdate.create(View.of(1), mock(HighQC.class), node, BFTNode.random()), 0L));
    this.pacemaker.processBFTUpdate(bftInsertUpdate);
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(emptyVoteWithTimeout));
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).createVote(any(), any(), anyLong(), any());
    verify(this.safetyRules, times(1)).timeoutVote(emptyVote);
    verifyNoMoreInteractions(this.safetyRules);
    verify(this.vertexStore, times(1)).getPreparedVertex(any());
    ArgumentCaptor<VerifiedVertex> insertVertexCaptor = ArgumentCaptor.forClass(VerifiedVertex.class);
    verify(this.vertexStore, times(1)).insertVertex(insertVertexCaptor.capture());
    assertEquals(insertVertexCaptor.getValue().getParentId(), highQcParentVertexId);
    verifyNoMoreInteractions(this.vertexStore);
}
Also used : HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) LedgerHeader(com.radixdlt.consensus.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Aggregations

Vote (com.radixdlt.consensus.Vote)26 Test (org.junit.Test)19 HighQC (com.radixdlt.consensus.HighQC)11 View (com.radixdlt.consensus.bft.View)9 BFTHeader (com.radixdlt.consensus.BFTHeader)8 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 Builder (com.radixdlt.consensus.safety.SafetyState.Builder)7 BFTNode (com.radixdlt.consensus.bft.BFTNode)6 ECDSASignature (com.radixdlt.crypto.ECDSASignature)6 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)4 HashCode (com.google.common.hash.HashCode)3 HashSigner (com.radixdlt.consensus.HashSigner)3 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)3 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)2 LedgerHeader (com.radixdlt.consensus.LedgerHeader)2 Proposal (com.radixdlt.consensus.Proposal)2 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)2 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)2