Search in sources :

Example 1 with BFTHeader

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

the class BFTEventReducerTest method when_previous_vote_exists_for_this_view__then_dont_vote.

@Test
public void when_previous_vote_exists_for_this_view__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());
    when(safetyRules.getLastVote(View.of(3))).thenReturn(Optional.of(mock(Vote.class)));
    this.bftEventReducer.processBFTUpdate(bftUpdate);
    verifyNoMoreInteractions(this.voteDispatcher);
    verifyNoMoreInteractions(this.noVoteEventDispatcher);
}
Also used : HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Test(org.junit.Test)

Example 2 with BFTHeader

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

the class VerifiedVertexStoreStateCreationTest method creating_vertex_store_with_committed_qc_not_matching_vertex_should_fail.

@Test
public void creating_vertex_store_with_committed_qc_not_matching_vertex_should_fail() {
    BFTHeader genesisHeader = new BFTHeader(View.of(0), genesisHash, mock(LedgerHeader.class));
    BFTHeader otherHeader = new BFTHeader(View.of(0), HashUtils.random256(), mock(LedgerHeader.class));
    VoteData voteData = new VoteData(genesisHeader, genesisHeader, otherHeader);
    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.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) LedgerHeader(com.radixdlt.consensus.LedgerHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) VoteData(com.radixdlt.consensus.VoteData) Test(org.junit.Test)

Example 3 with BFTHeader

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

the class VerifiedVertexStoreStateCreationTest method creating_vertex_store_with_root_not_committed_should_fail.

@Test
public void creating_vertex_store_with_root_not_committed_should_fail() {
    BFTHeader genesisHeader = new BFTHeader(View.of(0), genesisHash, mock(LedgerHeader.class));
    VoteData voteData = new VoteData(genesisHeader, genesisHeader, null);
    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.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) LedgerHeader(com.radixdlt.consensus.LedgerHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) VoteData(com.radixdlt.consensus.VoteData) Test(org.junit.Test)

Example 4 with BFTHeader

use of com.radixdlt.consensus.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.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) LedgerHeader(com.radixdlt.consensus.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Example 5 with BFTHeader

use of com.radixdlt.consensus.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.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Vote(com.radixdlt.consensus.Vote) Builder(com.radixdlt.consensus.safety.SafetyState.Builder) View(com.radixdlt.consensus.bft.View) Test(org.junit.Test)

Aggregations

BFTHeader (com.radixdlt.consensus.BFTHeader)22 Test (org.junit.Test)12 View (com.radixdlt.consensus.bft.View)11 VoteData (com.radixdlt.consensus.VoteData)10 HighQC (com.radixdlt.consensus.HighQC)9 LedgerHeader (com.radixdlt.consensus.LedgerHeader)9 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)9 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)8 Vote (com.radixdlt.consensus.Vote)8 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)8 HashCode (com.google.common.hash.HashCode)5 BFTNode (com.radixdlt.consensus.bft.BFTNode)4 Builder (com.radixdlt.consensus.safety.SafetyState.Builder)4 PreparedVertex (com.radixdlt.consensus.bft.PreparedVertex)2 ImmutableList (com.google.common.collect.ImmutableList)1 Inject (com.google.inject.Inject)1 HashSigner (com.radixdlt.consensus.HashSigner)1 Ledger (com.radixdlt.consensus.Ledger)1 Proposal (com.radixdlt.consensus.Proposal)1 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)1