Search in sources :

Example 11 with BFTHeader

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

the class PacemakerTest method when_local_timeout__then_send_empty_vote_if_no_previous.

@Test
public void when_local_timeout__then_send_empty_vote_if_no_previous() {
    HighQC viewUpdateHighQc = mock(HighQC.class);
    QuorumCertificate committedQc = mock(QuorumCertificate.class);
    QuorumCertificate highestQc = mock(QuorumCertificate.class);
    when(viewUpdateHighQc.highestCommittedQC()).thenReturn(committedQc);
    when(viewUpdateHighQc.highestQC()).thenReturn(highestQc);
    BFTHeader highestQcProposed = mock(BFTHeader.class);
    HashCode highQcParentVertexId = mock(HashCode.class);
    when(highestQcProposed.getVertexId()).thenReturn(highQcParentVertexId);
    when(highestQc.getProposed()).thenReturn(highestQcProposed);
    when(committedQc.getView()).thenReturn(View.of(0));
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(1), viewUpdateHighQc, mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processViewUpdate(viewUpdate);
    View view = View.of(1);
    Vote emptyVote = mock(Vote.class);
    Vote emptyVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    BFTHeader bftHeader = mock(BFTHeader.class);
    HighQC highQC = mock(HighQC.class);
    BFTInsertUpdate bftInsertUpdate = mock(BFTInsertUpdate.class);
    when(bftInsertUpdate.getHeader()).thenReturn(bftHeader);
    PreparedVertex preparedVertex = mock(PreparedVertex.class);
    when(preparedVertex.getView()).thenReturn(view);
    when(preparedVertex.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    VerifiedVertexStoreState vertexStoreState = mock(VerifiedVertexStoreState.class);
    when(vertexStoreState.getHighQC()).thenReturn(highQC);
    when(bftInsertUpdate.getInserted()).thenReturn(preparedVertex);
    when(bftInsertUpdate.getVertexStoreState()).thenReturn(vertexStoreState);
    var node = BFTNode.random();
    when(preparedVertex.getId()).thenReturn(hasher.hash(UnverifiedVertex.createTimeout(highestQc, view, node)));
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.empty());
    when(this.safetyRules.createVote(any(), any(), anyLong(), any())).thenReturn(emptyVote);
    when(this.safetyRules.timeoutVote(emptyVote)).thenReturn(emptyVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    when(this.vertexStore.getPreparedVertex(any())).thenReturn(Optional.empty());
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(ViewUpdate.create(View.of(1), mock(HighQC.class), node, BFTNode.random()), 0L));
    this.pacemaker.processBFTUpdate(bftInsertUpdate);
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(emptyVoteWithTimeout));
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).createVote(any(), any(), anyLong(), any());
    verify(this.safetyRules, times(1)).timeoutVote(emptyVote);
    verifyNoMoreInteractions(this.safetyRules);
    verify(this.vertexStore, times(1)).getPreparedVertex(any());
    ArgumentCaptor<VerifiedVertex> insertVertexCaptor = ArgumentCaptor.forClass(VerifiedVertex.class);
    verify(this.vertexStore, times(1)).insertVertex(insertVertexCaptor.capture());
    assertEquals(insertVertexCaptor.getValue().getParentId(), highQcParentVertexId);
    verifyNoMoreInteractions(this.vertexStore);
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Example 12 with BFTHeader

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

the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_three_after_genesis_with_skip__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(false);
    when(proposal.hasDirectParent()).thenReturn(false);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(4));
    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 13 with BFTHeader

use of com.radixdlt.hotstuff.BFTHeader 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));
    final var hashVerifier = mock(HashVerifier.class);
    final var validatorSet = mock(BFTValidatorSet.class);
    final var safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
    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.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Hasher(com.radixdlt.crypto.Hasher) Vote(com.radixdlt.hotstuff.Vote) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.hotstuff.HashSigner) Test(org.junit.Test)

Example 14 with BFTHeader

use of com.radixdlt.hotstuff.BFTHeader 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 15 with BFTHeader

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

the class BFTEventReducerTest method when_bft_update_for_previous_view__then_ignore.

@Test
public void when_bft_update_for_previous_view__then_ignore() {
    BFTInsertUpdate update = mock(BFTInsertUpdate.class);
    BFTHeader header = mock(BFTHeader.class);
    this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(3), mock(HighQC.class), mock(BFTNode.class), this.self));
    verify(this.pacemaker, times(1)).processViewUpdate(any());
    when(update.getHeader()).thenReturn(header);
    when(header.getView()).thenReturn(View.of(2));
    this.bftEventReducer.processBFTUpdate(update);
    verifyNoMoreInteractions(this.pacemaker);
}
Also used : BFTHeader(com.radixdlt.hotstuff.BFTHeader) Test(org.junit.Test)

Aggregations

BFTHeader (com.radixdlt.hotstuff.BFTHeader)22 Test (org.junit.Test)12 View (com.radixdlt.hotstuff.bft.View)11 VoteData (com.radixdlt.hotstuff.VoteData)10 HighQC (com.radixdlt.hotstuff.HighQC)9 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)9 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)9 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)8 Vote (com.radixdlt.hotstuff.Vote)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 HashCode (com.google.common.hash.HashCode)5 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)4 Builder (com.radixdlt.hotstuff.safety.SafetyState.Builder)4 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Inject (com.google.inject.Inject)1 Hasher (com.radixdlt.crypto.Hasher)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 TestInvariantError (com.radixdlt.harness.simulation.TestInvariant.TestInvariantError)1