Search in sources :

Example 11 with QuorumCertificate

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

the class VertexStoreTest method setUp.

@Before
public void setUp() {
    // No type check issues with mocking generic here
    Ledger ssc = mock(Ledger.class);
    this.ledger = ssc;
    // TODO: replace mock with the real thing
    doAnswer(invocation -> {
        VerifiedVertex verifiedVertex = invocation.getArgument(1);
        return Optional.of(new PreparedVertex(verifiedVertex, MOCKED_HEADER, ImmutableList.of(), ImmutableMap.of(), 1L));
    }).when(ledger).prepare(any(), any());
    this.bftUpdateSender = rmock(EventDispatcher.class);
    this.rebuildUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.bftHighQCUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.committedSender = rmock(EventDispatcher.class);
    this.genesisHash = HashUtils.zero256();
    this.genesisVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(MOCKED_HEADER), genesisHash);
    this.rootQC = QuorumCertificate.ofGenesis(genesisVertex, MOCKED_HEADER);
    this.sut = VertexStore.create(VerifiedVertexStoreState.create(HighQC.from(rootQC), genesisVertex, Optional.empty(), hasher), ledger, hasher, bftUpdateSender, rebuildUpdateEventDispatcher, bftHighQCUpdateEventDispatcher, committedSender);
    AtomicReference<BFTHeader> lastParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGreatGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    this.nextSkippableVertex = (skipOne) -> {
        BFTHeader parentHeader = lastParentHeader.get();
        BFTHeader grandParentHeader = lastGrandParentHeader.get();
        BFTHeader greatGrandParentHeader = lastGreatGrandParentHeader.get();
        final QuorumCertificate qc;
        if (!parentHeader.getView().equals(View.genesis())) {
            VoteData data = new VoteData(parentHeader, grandParentHeader, skipOne ? null : greatGrandParentHeader);
            qc = new QuorumCertificate(data, new TimestampedECDSASignatures());
        } else {
            qc = rootQC;
        }
        View view = parentHeader.getView().next();
        if (skipOne) {
            view = view.next();
        }
        var rawVertex = UnverifiedVertex.create(qc, view, List.of(Txn.create(new byte[0])), BFTNode.random());
        HashCode hash = hasher.hash(rawVertex);
        VerifiedVertex vertex = new VerifiedVertex(rawVertex, hash);
        lastParentHeader.set(new BFTHeader(view, hash, MOCKED_HEADER));
        lastGrandParentHeader.set(parentHeader);
        lastGreatGrandParentHeader.set(grandParentHeader);
        return vertex;
    };
    this.nextVertex = () -> nextSkippableVertex.apply(false);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Ledger(com.radixdlt.hotstuff.Ledger) AtomicReference(java.util.concurrent.atomic.AtomicReference) VoteData(com.radixdlt.hotstuff.VoteData) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Before(org.junit.Before)

Example 12 with QuorumCertificate

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

the class PacemakerStateTest method when_process_qc_with_a_high_tc__then_should_move_to_tc_view.

@Test
public void when_process_qc_with_a_high_tc__then_should_move_to_tc_view() {
    HighQC highQC = mock(HighQC.class);
    QuorumCertificate qc = mock(QuorumCertificate.class);
    when(qc.getView()).thenReturn(View.of(3));
    when(highQC.getHighestView()).thenReturn(View.of(5));
    when(highQC.highestCommittedQC()).thenReturn(qc);
    this.pacemakerState.processQC(highQC);
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(6))));
}
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) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 13 with QuorumCertificate

use of com.radixdlt.hotstuff.QuorumCertificate 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 14 with QuorumCertificate

use of com.radixdlt.hotstuff.QuorumCertificate 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 15 with QuorumCertificate

use of com.radixdlt.hotstuff.QuorumCertificate 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)

Aggregations

QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)25 HighQC (com.radixdlt.hotstuff.HighQC)14 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)13 Test (org.junit.Test)13 BFTHeader (com.radixdlt.hotstuff.BFTHeader)12 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)12 VoteData (com.radixdlt.hotstuff.VoteData)12 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)9 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 View (com.radixdlt.hotstuff.bft.View)8 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)7 EventDispatcher (com.radixdlt.environment.EventDispatcher)6 Before (org.junit.Before)6 HashCode (com.google.common.hash.HashCode)5 Txn (com.radixdlt.atom.Txn)5 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)5 Hasher (com.radixdlt.crypto.Hasher)4 Ledger (com.radixdlt.hotstuff.Ledger)4 Proposal (com.radixdlt.hotstuff.Proposal)4 VerifiedVertexStoreState (com.radixdlt.hotstuff.bft.VerifiedVertexStoreState)4