Search in sources :

Example 11 with QuorumCertificate

use of com.radixdlt.consensus.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.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) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Example 12 with QuorumCertificate

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

the class PacemakerTest method setUp.

@Before
public void setUp() {
    HighQC highQC = mock(HighQC.class);
    QuorumCertificate committedQc = mock(QuorumCertificate.class);
    when(committedQc.getView()).thenReturn(View.of(0));
    when(highQC.highestCommittedQC()).thenReturn(committedQc);
    ViewUpdate initialViewUpdate = ViewUpdate.create(View.of(0), highQC, mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker = new Pacemaker(this.self, this.counters, this.validatorSet, this.vertexStore, this.safetyRules, this.timeoutDispatcher, this.timeoutSender, this.timeoutCalculator, this.nextTxnsGenerator, this.proposalDispatcher, this.voteDispatcher, hasher, timeSupplier, initialViewUpdate, new SystemCountersImpl());
}
Also used : HighQC(com.radixdlt.consensus.HighQC) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) BFTNode(com.radixdlt.consensus.bft.BFTNode) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) Before(org.junit.Before)

Example 13 with QuorumCertificate

use of com.radixdlt.consensus.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.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Ledger(com.radixdlt.consensus.Ledger) AtomicReference(java.util.concurrent.atomic.AtomicReference) VoteData(com.radixdlt.consensus.VoteData) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Before(org.junit.Before)

Example 14 with QuorumCertificate

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

the class VertexStoreTest method adding_a_qc_with_commit_should_commit_vertices_to_ledger.

@Test
public void adding_a_qc_with_commit_should_commit_vertices_to_ledger() {
    // Arrange
    final var vertices = Stream.generate(this.nextVertex).limit(4).toList();
    sut.insertVertex(vertices.get(0));
    sut.insertVertex(vertices.get(1));
    sut.insertVertex(vertices.get(2));
    // Act
    QuorumCertificate qc = vertices.get(3).getQC();
    boolean success = sut.addQC(qc);
    // Assert
    assertThat(success).isTrue();
    assertThat(sut.highQC().highestQC()).isEqualTo(qc);
    assertThat(sut.highQC().highestCommittedQC()).isEqualTo(qc);
    assertThat(sut.getVertices(vertices.get(2).getId(), 3)).hasValue(ImmutableList.of(vertices.get(2), vertices.get(1), vertices.get(0)));
    verify(committedSender, times(1)).dispatch(argThat(u -> u.committed().size() == 1 && u.committed().get(0).getVertex().equals(vertices.get(0))));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HighQC(com.radixdlt.consensus.HighQC) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Hasher(com.radixdlt.crypto.Hasher) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) ImmutableList(com.google.common.collect.ImmutableList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Ledger(com.radixdlt.consensus.Ledger) AccumulatorState(com.radixdlt.ledger.AccumulatorState) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) HashUtils(com.radixdlt.crypto.HashUtils) Before(org.junit.Before) ImmutableMap(com.google.common.collect.ImmutableMap) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Txn(com.radixdlt.atom.Txn) Mockito.times(org.mockito.Mockito.times) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) Test(org.junit.Test) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) TimeoutCertificate(com.radixdlt.consensus.TimeoutCertificate) Mockito.verify(org.mockito.Mockito.verify) BFTHeader(com.radixdlt.consensus.BFTHeader) LedgerHeader(com.radixdlt.consensus.LedgerHeader) VoteData(com.radixdlt.consensus.VoteData) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Example 15 with QuorumCertificate

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

QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)16 Test (org.junit.Test)11 BFTHeader (com.radixdlt.consensus.BFTHeader)9 HighQC (com.radixdlt.consensus.HighQC)9 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)8 VoteData (com.radixdlt.consensus.VoteData)8 LedgerHeader (com.radixdlt.consensus.LedgerHeader)7 BFTNode (com.radixdlt.consensus.bft.BFTNode)5 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)5 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)5 Before (org.junit.Before)5 Txn (com.radixdlt.atom.Txn)4 Ledger (com.radixdlt.consensus.Ledger)4 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)4 Vote (com.radixdlt.consensus.Vote)4 View (com.radixdlt.consensus.bft.View)4 EventDispatcher (com.radixdlt.environment.EventDispatcher)4 ImmutableList (com.google.common.collect.ImmutableList)3 HashCode (com.google.common.hash.HashCode)3 Sha256Hasher (com.radixdlt.consensus.Sha256Hasher)3