Search in sources :

Example 16 with BFTHeader

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

the class BFTEventReducerTest method when_view_is_timed_out__then_dont_vote.

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

Example 17 with BFTHeader

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

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

Example 19 with BFTHeader

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

the class SafetyRulesTest method when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(0));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.hasDirectParent()).thenReturn(true);
    when(vertex.touchesGenesis()).thenReturn(true);
    when(vertex.parentHasDirectParent()).thenReturn(true);
    when(vertex.getView()).thenReturn(View.of(1));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(vertex.getGrandParentHeader()).thenReturn(grandParent);
    BFTHeader header = mock(BFTHeader.class);
    Optional<Vote> voteMaybe = safetyRules.voteFor(vertex, header, 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getProposed()).isEqualTo(header);
    assertThat(vote.getVoteData().getParent()).isEqualTo(parent);
    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 20 with BFTHeader

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

the class VerifiedVertexStoreStateCreationTest method creating_vertex_store_with_qc_not_matching_vertex_should_fail.

@Test
public void creating_vertex_store_with_qc_not_matching_vertex_should_fail() {
    BFTHeader genesisHeader = new BFTHeader(View.of(0), HashUtils.random256(), mock(LedgerHeader.class));
    VoteData voteData = new VoteData(genesisHeader, genesisHeader, genesisHeader);
    QuorumCertificate badRootQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    assertThatThrownBy(() -> VerifiedVertexStoreState.create(HighQC.from(badRootQC), genesisVertex, Optional.empty(), hasher)).isInstanceOf(IllegalStateException.class);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VoteData(com.radixdlt.hotstuff.VoteData) 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