Search in sources :

Example 21 with Vote

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

the class SafetyRules method timeoutVote.

public Vote timeoutVote(Vote vote) {
    if (vote.isTimeout()) {
        // vote is already timed out
        return vote;
    }
    final VoteTimeout voteTimeout = VoteTimeout.of(vote);
    final HashCode voteTimeoutHash = hasher.hash(voteTimeout);
    final ECDSASignature timeoutSignature = this.signer.sign(voteTimeoutHash);
    final Vote timeoutVote = vote.withTimeoutSignature(timeoutSignature);
    this.state = this.state.toBuilder().lastVote(timeoutVote).build();
    this.persistentSafetyStateStore.commitState(this.state);
    return timeoutVote;
}
Also used : Vote(com.radixdlt.hotstuff.Vote) HashCode(com.google.common.hash.HashCode) ECDSASignature(com.radixdlt.crypto.ECDSASignature) VoteTimeout(com.radixdlt.hotstuff.liveness.VoteTimeout)

Example 22 with Vote

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

the class PacemakerTest method when_local_timeout__then_resend_previous_vote.

@Test
public void when_local_timeout__then_resend_previous_vote() {
    View view = View.of(0);
    Vote lastVote = mock(Vote.class);
    Vote lastVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.of(lastVote));
    when(this.safetyRules.timeoutVote(lastVote)).thenReturn(lastVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(0), mock(HighQC.class), mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(viewUpdate, 0L));
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(lastVoteWithTimeout));
    verifyNoMoreInteractions(this.vertexStore);
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).timeoutVote(lastVote);
    verifyNoMoreInteractions(this.safetyRules);
}
Also used : ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) HighQC(com.radixdlt.hotstuff.HighQC) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 23 with Vote

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

the class MessageCentralBFTNetworkTest method when_send_vote__then_message_central_should_be_sent_vote_message.

@Test
public void when_send_vote__then_message_central_should_be_sent_vote_message() {
    Vote vote = mock(Vote.class);
    ECPublicKey leaderPk = ECKeyPair.generateNew().getPublicKey();
    BFTNode leader = mock(BFTNode.class);
    when(leader.getKey()).thenReturn(leaderPk);
    network.voteDispatcher().dispatch(leader, vote);
    verify(messageCentral, times(1)).send(eq(NodeId.fromPublicKey(leaderPk)), any(ConsensusEventMessage.class));
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) ECPublicKey(com.radixdlt.crypto.ECPublicKey) Test(org.junit.Test)

Example 24 with Vote

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

the class SafetyRulesTest method when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_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(true);
    when(proposal.hasDirectParent()).thenReturn(true);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(1));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(2));
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandParent);
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 25 with Vote

use of com.radixdlt.hotstuff.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.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Aggregations

Vote (com.radixdlt.hotstuff.Vote)26 Test (org.junit.Test)19 HighQC (com.radixdlt.hotstuff.HighQC)11 View (com.radixdlt.hotstuff.bft.View)9 BFTHeader (com.radixdlt.hotstuff.BFTHeader)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)7 Builder (com.radixdlt.hotstuff.safety.SafetyState.Builder)7 ECDSASignature (com.radixdlt.crypto.ECDSASignature)6 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)6 HashCode (com.google.common.hash.HashCode)4 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)4 HashSigner (com.radixdlt.hotstuff.HashSigner)3 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)3 BFTInsertUpdate (com.radixdlt.hotstuff.bft.BFTInsertUpdate)3 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 Hasher (com.radixdlt.crypto.Hasher)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)2