use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.
the class ConsensusEventMessageTest method sensibleToStringVote.
@Test
public void sensibleToStringVote() {
Vote m = mock(Vote.class);
ConsensusEventMessage msg1 = new ConsensusEventMessage(m);
String s1 = msg1.toString();
assertThat(s1).contains(ConsensusEventMessage.class.getSimpleName()).contains(m.toString());
assertTrue(msg1.getConsensusMessage() instanceof Vote);
}
use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.
the class SafetyRules method voteFor.
/**
* Vote for a proposed vertex while ensuring that safety invariants are upheld.
*
* @param proposedVertex The proposed vertex
* @param proposedHeader results of vertex execution
* @param timestamp timestamp to use for the vote in milliseconds since epoch
* @param highQC our current sync state
* @return A vote result containing the vote and any committed vertices
*/
public Optional<Vote> voteFor(VerifiedVertex proposedVertex, BFTHeader proposedHeader, long timestamp, HighQC highQC) {
Builder safetyStateBuilder = this.state.toBuilder();
if (!checkLastVoted(proposedVertex)) {
return Optional.empty();
}
if (!checkLocked(proposedVertex, safetyStateBuilder)) {
return Optional.empty();
}
final Vote vote = createVote(proposedVertex, proposedHeader, timestamp, highQC);
safetyStateBuilder.lastVote(vote);
this.state = safetyStateBuilder.build();
this.persistentSafetyStateStore.commitState(this.state);
return Optional.of(vote);
}
use of com.radixdlt.hotstuff.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);
}
use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.
the class RecoveryTest method on_reboot_should_load_same_last_vote.
@Test
public void on_reboot_should_load_same_last_vote() {
// Arrange
processForCount(processForCount);
Vote vote = getLastVote();
// Act
restartNode();
// Assert
SafetyState safetyState = currentInjector.getInstance(SafetyState.class);
assertThat(safetyState.getLastVotedView().equals(vote.getView()) || (safetyState.getLastVotedView().equals(View.genesis()) && vote.getView().equals(View.of(epochCeilingView + 3)))).isTrue();
}
use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.
the class BFTEventVerifierTest method when_process_bad_author_vote_then_should_not_be_forwarded.
@Test
public void when_process_bad_author_vote_then_should_not_be_forwarded() {
Vote vote = mock(Vote.class);
BFTNode author = mock(BFTNode.class);
when(vote.getAuthor()).thenReturn(author);
when(vote.getSignature()).thenReturn(mock(ECDSASignature.class));
when(validatorSet.containsNode(eq(author))).thenReturn(false);
when(verifier.verify(any(), any(), any())).thenReturn(true);
eventVerifier.processVote(vote);
verify(forwardTo, never()).processVote(any());
}
Aggregations