Search in sources :

Example 6 with HighQC

use of com.radixdlt.hotstuff.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.hotstuff.HighQC) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Mockito(org.mockito.Mockito) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) EventDispatcher(com.radixdlt.environment.EventDispatcher) Mockito.times(org.mockito.Mockito.times) HighQC(com.radixdlt.hotstuff.HighQC) Test(org.junit.Test) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) Before(org.junit.Before) Test(org.junit.Test)

Example 7 with HighQC

use of com.radixdlt.hotstuff.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.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Example 8 with HighQC

use of com.radixdlt.hotstuff.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.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 9 with HighQC

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

the class GetVerticesErrorResponseMessageSerializeTest method get.

private static GetVerticesErrorResponseMessage get() {
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    VerifiedVertex verifiedVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(ledgerHeader), HashUtils.zero256());
    QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, ledgerHeader);
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    final var request = new GetVerticesRequestMessage(HashUtils.random256(), 3);
    return new GetVerticesErrorResponseMessage(highQC, request);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate)

Example 10 with HighQC

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

the class Pacemaker method generateProposal.

private Optional<Proposal> generateProposal(View view) {
    final HighQC highQC = this.latestViewUpdate.getHighQC();
    final QuorumCertificate highestQC = highQC.highestQC();
    final List<Txn> nextTxns;
    // TODO: Remove isEndOfEpoch knowledge from consensus
    if (highestQC.getProposed().getLedgerHeader().isEndOfEpoch()) {
        nextTxns = List.of();
    } else {
        final List<PreparedVertex> preparedVertices = vertexStore.getPathFromRoot(highestQC.getProposed().getVertexId());
        nextTxns = nextTxnsGenerator.generateNextTxns(view, preparedVertices);
        systemCounters.add(SystemCounters.CounterType.BFT_PACEMAKER_PROPOSED_TRANSACTIONS, nextTxns.size());
    }
    final UnverifiedVertex proposedVertex = UnverifiedVertex.create(highestQC, view, nextTxns, self);
    final VerifiedVertex verifiedVertex = new VerifiedVertex(proposedVertex, hasher.hash(proposedVertex));
    return safetyRules.signProposal(verifiedVertex, highQC.highestCommittedQC(), highQC.highestTC());
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Txn(com.radixdlt.atom.Txn) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex)

Aggregations

HighQC (com.radixdlt.hotstuff.HighQC)16 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)14 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)11 View (com.radixdlt.hotstuff.bft.View)9 Test (org.junit.Test)9 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)8 EventDispatcher (com.radixdlt.environment.EventDispatcher)6 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 Vote (com.radixdlt.hotstuff.Vote)6 Before (org.junit.Before)6 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)5 TypedMocks.rmock (com.radixdlt.utils.TypedMocks.rmock)5 Mockito.times (org.mockito.Mockito.times)5 BFTHeader (com.radixdlt.hotstuff.BFTHeader)4 AbstractModule (com.google.inject.AbstractModule)3 Provides (com.google.inject.Provides)3 TypeLiteral (com.google.inject.TypeLiteral)3 Txn (com.radixdlt.atom.Txn)3 SystemCounters (com.radixdlt.counters.SystemCounters)3 Hasher (com.radixdlt.crypto.Hasher)3