Search in sources :

Example 6 with Vote

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

the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis__then_returned_vote_has_commit.

@Test
public void when_vote_on_proposal_three_after_genesis__then_returned_vote_has_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(1));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex proposal = mock(VerifiedVertex.class);
    when(proposal.touchesGenesis()).thenReturn(false);
    when(proposal.hasDirectParent()).thenReturn(true);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader grandparentHeader = mock(BFTHeader.class);
    when(grandparentHeader.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandparentHeader);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(3));
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).hasValue(grandparentHeader);
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 7 with Vote

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

the class SafetyRulesTest method when_vote_with_qc_on_different_locked_view__then_exception_is_thrown.

@Test
public void when_vote_with_qc_on_different_locked_view__then_exception_is_thrown() {
    Hasher hasher = mock(Hasher.class);
    when(hasher.hash(any())).thenReturn(mock(HashCode.class));
    HashSigner hashSigner = mock(HashSigner.class);
    when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
    Vote lastVote = mock(Vote.class);
    when(lastVote.getView()).thenReturn(View.of(1));
    SafetyRules safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner);
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.getView()).thenReturn(View.of(3));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    assertThat(safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Hasher(com.radixdlt.crypto.Hasher) Vote(com.radixdlt.consensus.Vote) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.consensus.HashSigner) Test(org.junit.Test)

Example 8 with Vote

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

the class SafetyRulesTest method when_timeout_a_vote_than_it_has_a_timeout_signature.

@Test
public void when_timeout_a_vote_than_it_has_a_timeout_signature() {
    Vote vote = mock(Vote.class);
    Vote voteWithTimeout = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(1L);
    when(vote.withTimeoutSignature(any())).thenReturn(voteWithTimeout);
    when(vote.isTimeout()).thenReturn(false);
    Builder builder = mock(Builder.class);
    when(builder.lastVote(any())).thenReturn(builder);
    when(builder.build()).thenReturn(this.safetyState);
    when(safetyState.toBuilder()).thenReturn(builder);
    Vote resultVote = safetyRules.timeoutVote(vote);
    verify(vote, times(1)).withTimeoutSignature(any());
    assertEquals(voteWithTimeout, resultVote);
}
Also used : Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) Test(org.junit.Test)

Example 9 with Vote

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

the class SafetyRulesTest method when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(0));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.hasDirectParent()).thenReturn(true);
    when(vertex.touchesGenesis()).thenReturn(true);
    when(vertex.parentHasDirectParent()).thenReturn(true);
    when(vertex.getView()).thenReturn(View.of(1));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(vertex.getGrandParentHeader()).thenReturn(grandParent);
    BFTHeader header = mock(BFTHeader.class);
    Optional<Vote> voteMaybe = safetyRules.voteFor(vertex, header, 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getProposed()).isEqualTo(header);
    assertThat(vote.getVoteData().getParent()).isEqualTo(parent);
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Example 10 with Vote

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

the class Pacemaker method createAndSendTimeoutVote.

private void createAndSendTimeoutVote(PreparedVertex preparedVertex) {
    final BFTHeader bftHeader = new BFTHeader(preparedVertex.getView(), preparedVertex.getId(), preparedVertex.getLedgerHeader());
    final Vote baseVote = this.safetyRules.createVote(preparedVertex.getVertex(), bftHeader, this.timeSupplier.currentTime(), this.latestViewUpdate.getHighQC());
    final Vote timeoutVote = this.safetyRules.timeoutVote(baseVote);
    this.voteDispatcher.dispatch(this.validatorSet.nodes(), timeoutVote);
}
Also used : BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote)

Aggregations

Vote (com.radixdlt.consensus.Vote)22 Test (org.junit.Test)16 HighQC (com.radixdlt.consensus.HighQC)10 View (com.radixdlt.consensus.bft.View)8 BFTHeader (com.radixdlt.consensus.BFTHeader)7 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 Builder (com.radixdlt.consensus.safety.SafetyState.Builder)7 ECDSASignature (com.radixdlt.crypto.ECDSASignature)6 BFTNode (com.radixdlt.consensus.bft.BFTNode)4 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)4 HashSigner (com.radixdlt.consensus.HashSigner)3 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)3 HashCode (com.google.common.hash.HashCode)2 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)2 Proposal (com.radixdlt.consensus.Proposal)2 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)2 BFTHighQCUpdate (com.radixdlt.consensus.bft.BFTHighQCUpdate)2 BFTRebuildUpdate (com.radixdlt.consensus.bft.BFTRebuildUpdate)2