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;
}
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);
}
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));
}
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();
}
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);
}
Aggregations