Search in sources :

Example 1 with HighQC

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

the class PacemakerStateTest method when_process_qc_for_wrong_view__then_ignored.

@Test
public void when_process_qc_for_wrong_view__then_ignored() {
    HighQC highQC = mock(HighQC.class);
    when(highQC.getHighestView()).thenReturn(View.of(1));
    // Move ahead for a bit so we can send in a QC for a lower view
    this.pacemakerState.processQC(highQCFor(View.of(0)));
    this.pacemakerState.processQC(highQCFor(View.of(1)));
    this.pacemakerState.processQC(highQCFor(View.of(2)));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(1))));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(2))));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(3))));
    this.pacemakerState.processQC(highQC);
    verifyNoMoreInteractions(viewUpdateSender);
}
Also used : HighQC(com.radixdlt.consensus.HighQC) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) Mockito(org.mockito.Mockito) HighQC(com.radixdlt.consensus.HighQC) EventDispatcher(com.radixdlt.environment.EventDispatcher) BFTNode(com.radixdlt.consensus.bft.BFTNode) Mockito.times(org.mockito.Mockito.times) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) Test(org.junit.Test) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) Before(org.junit.Before) Test(org.junit.Test)

Example 2 with HighQC

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

the class PacemakerStateTest method highQCFor.

private HighQC highQCFor(View view) {
    HighQC highQC = mock(HighQC.class);
    QuorumCertificate hqc = mock(QuorumCertificate.class);
    QuorumCertificate cqc = mock(QuorumCertificate.class);
    when(hqc.getView()).thenReturn(view);
    when(cqc.getView()).thenReturn(View.of(0));
    when(highQC.highestQC()).thenReturn(hqc);
    when(highQC.highestCommittedQC()).thenReturn(cqc);
    when(highQC.getHighestView()).thenReturn(view);
    return highQC;
}
Also used : HighQC(com.radixdlt.consensus.HighQC) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate)

Example 3 with HighQC

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

the class PacemakerStateTest method when_process_qc_for_current_view__then_processed.

@Test
public void when_process_qc_for_current_view__then_processed() {
    HighQC highQC = mock(HighQC.class);
    when(highQC.getHighestView()).thenReturn(View.of(0));
    this.pacemakerState.processQC(highQC);
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(1))));
    when(highQC.getHighestView()).thenReturn(View.of(1));
    this.pacemakerState.processQC(highQC);
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(2))));
}
Also used : HighQC(com.radixdlt.consensus.HighQC) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) Mockito(org.mockito.Mockito) HighQC(com.radixdlt.consensus.HighQC) EventDispatcher(com.radixdlt.environment.EventDispatcher) BFTNode(com.radixdlt.consensus.bft.BFTNode) Mockito.times(org.mockito.Mockito.times) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) Test(org.junit.Test) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) Before(org.junit.Before) Test(org.junit.Test)

Example 4 with HighQC

use of com.radixdlt.consensus.HighQC 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)

Example 5 with HighQC

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

the class GetVerticesErrorResponseMessageTest method sensibleToString.

@Test
public void sensibleToString() {
    VerifiedVertex verifiedVertex = mock(VerifiedVertex.class);
    when(verifiedVertex.getView()).thenReturn(View.genesis());
    when(verifiedVertex.getId()).thenReturn(HashCode.fromInt(1));
    QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, mock(LedgerHeader.class));
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    final var request = mock(GetVerticesRequestMessage.class);
    GetVerticesErrorResponseMessage msg1 = new GetVerticesErrorResponseMessage(highQC, request);
    String s1 = msg1.toString();
    assertThat(s1).contains(GetVerticesErrorResponseMessage.class.getSimpleName());
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) LedgerHeader(com.radixdlt.consensus.LedgerHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Aggregations

HighQC (com.radixdlt.consensus.HighQC)16 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)14 BFTNode (com.radixdlt.consensus.bft.BFTNode)11 View (com.radixdlt.consensus.bft.View)9 Test (org.junit.Test)9 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)8 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 Vote (com.radixdlt.consensus.Vote)6 EventDispatcher (com.radixdlt.environment.EventDispatcher)6 Before (org.junit.Before)6 LedgerHeader (com.radixdlt.consensus.LedgerHeader)5 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)4 GetVerticesErrorResponse (com.radixdlt.consensus.sync.GetVerticesErrorResponse)4 GetVerticesRequest (com.radixdlt.consensus.sync.GetVerticesRequest)4 AbstractModule (com.google.inject.AbstractModule)3 Provides (com.google.inject.Provides)3 TypeLiteral (com.google.inject.TypeLiteral)3 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)3 BFTHeader (com.radixdlt.consensus.BFTHeader)3 HashSigner (com.radixdlt.consensus.HashSigner)3