Search in sources :

Example 16 with Vote

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);
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Test(org.junit.Test)

Example 17 with 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);
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder)

Example 18 with 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);
}
Also used : BFTHeader(com.radixdlt.hotstuff.BFTHeader) Vote(com.radixdlt.hotstuff.Vote)

Example 19 with Vote

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();
}
Also used : Vote(com.radixdlt.hotstuff.Vote) SafetyState(com.radixdlt.hotstuff.safety.SafetyState) Test(org.junit.Test)

Example 20 with Vote

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());
}
Also used : Vote(com.radixdlt.hotstuff.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) 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