Search in sources :

Example 6 with View

use of com.radixdlt.consensus.bft.View 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 7 with View

use of com.radixdlt.consensus.bft.View in project radixdlt by radixdlt.

the class WeightedRotatingLeadersTest method when_get_proposer_multiple_times__then_should_return_the_same_key.

@Test
public void when_get_proposer_multiple_times__then_should_return_the_same_key() {
    for (int validatorSetSize = 1; validatorSetSize <= 128; validatorSetSize *= 2) {
        for (int sizeOfCache = 1; sizeOfCache <= 128; sizeOfCache *= 2) {
            setUp(validatorSetSize, sizeOfCache);
            // 2 * sizeOfCache so cache eviction occurs
            final int viewsToTest = 2 * sizeOfCache;
            BFTNode expectedNodeForView0 = weightedRotatingLeaders.getProposer(View.of(0));
            for (View view = View.of(1); view.compareTo(View.of(viewsToTest)) <= 0; view = view.next()) {
                weightedRotatingLeaders.getProposer(view);
            }
            assertThat(weightedRotatingLeaders.getProposer(View.of(0))).isEqualTo(expectedNodeForView0);
        }
    }
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 8 with View

use of com.radixdlt.consensus.bft.View in project radixdlt by radixdlt.

the class UnverifiedVertexSerializeTest method get.

private static UnverifiedVertex get() {
    View view = View.of(1234567891L);
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, HashUtils.random256(), ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
    return UnverifiedVertex.create(qc, view, List.of(txn), BFTNode.random());
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.consensus.LedgerHeader) BFTHeader(com.radixdlt.consensus.BFTHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) VoteData(com.radixdlt.consensus.VoteData)

Example 9 with View

use of com.radixdlt.consensus.bft.View in project radixdlt by radixdlt.

the class VoteSerializeTest method get.

private static Vote get() {
    View view = View.of(1234567891L);
    HashCode id = HashUtils.random256();
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, id, ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    return new Vote(author, voteData, 123456L, ECDSASignature.zeroSignature(), highQC, Optional.empty());
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) HighQC(com.radixdlt.consensus.HighQC) LedgerHeader(com.radixdlt.consensus.LedgerHeader) BFTHeader(com.radixdlt.consensus.BFTHeader) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) HashCode(com.google.common.hash.HashCode) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) VoteData(com.radixdlt.consensus.VoteData)

Example 10 with View

use of com.radixdlt.consensus.bft.View in project radixdlt by radixdlt.

the class ProposalSerializeTest method get.

private static Proposal get() {
    View view = View.of(1234567891L);
    HashCode id = HashUtils.random256();
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, id, ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
    // add a particle to ensure atom is valid and has at least one shard
    BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
    UnverifiedVertex vertex = UnverifiedVertex.create(qc, view, List.of(txn), author);
    return new Proposal(vertex, qc, ECDSASignature.zeroSignature(), Optional.empty());
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.consensus.LedgerHeader) BFTHeader(com.radixdlt.consensus.BFTHeader) BFTNode(com.radixdlt.consensus.bft.BFTNode) HashCode(com.google.common.hash.HashCode) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) VoteData(com.radixdlt.consensus.VoteData) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) Proposal(com.radixdlt.consensus.Proposal)

Aggregations

View (com.radixdlt.consensus.bft.View)24 BFTNode (com.radixdlt.consensus.bft.BFTNode)11 Test (org.junit.Test)10 HighQC (com.radixdlt.consensus.HighQC)8 BFTHeader (com.radixdlt.consensus.BFTHeader)7 HashCode (com.google.common.hash.HashCode)6 LedgerHeader (com.radixdlt.consensus.LedgerHeader)5 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)5 Vote (com.radixdlt.consensus.Vote)5 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)5 Proposal (com.radixdlt.consensus.Proposal)4 VoteData (com.radixdlt.consensus.VoteData)4 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)3 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)3 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)3 ScheduledLocalTimeout (com.radixdlt.consensus.liveness.ScheduledLocalTimeout)3 SystemCounters (com.radixdlt.counters.SystemCounters)3 EventDispatcher (com.radixdlt.environment.EventDispatcher)3 Before (org.junit.Before)3 AbstractModule (com.google.inject.AbstractModule)2