Search in sources :

Example 11 with BFTHeader

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

the class VertexStoreTest method setUp.

@Before
public void setUp() {
    // No type check issues with mocking generic here
    Ledger ssc = mock(Ledger.class);
    this.ledger = ssc;
    // TODO: replace mock with the real thing
    doAnswer(invocation -> {
        VerifiedVertex verifiedVertex = invocation.getArgument(1);
        return Optional.of(new PreparedVertex(verifiedVertex, MOCKED_HEADER, ImmutableList.of(), ImmutableMap.of(), 1L));
    }).when(ledger).prepare(any(), any());
    this.bftUpdateSender = rmock(EventDispatcher.class);
    this.rebuildUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.bftHighQCUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.committedSender = rmock(EventDispatcher.class);
    this.genesisHash = HashUtils.zero256();
    this.genesisVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(MOCKED_HEADER), genesisHash);
    this.rootQC = QuorumCertificate.ofGenesis(genesisVertex, MOCKED_HEADER);
    this.sut = VertexStore.create(VerifiedVertexStoreState.create(HighQC.from(rootQC), genesisVertex, Optional.empty(), hasher), ledger, hasher, bftUpdateSender, rebuildUpdateEventDispatcher, bftHighQCUpdateEventDispatcher, committedSender);
    AtomicReference<BFTHeader> lastParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGreatGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    this.nextSkippableVertex = (skipOne) -> {
        BFTHeader parentHeader = lastParentHeader.get();
        BFTHeader grandParentHeader = lastGrandParentHeader.get();
        BFTHeader greatGrandParentHeader = lastGreatGrandParentHeader.get();
        final QuorumCertificate qc;
        if (!parentHeader.getView().equals(View.genesis())) {
            VoteData data = new VoteData(parentHeader, grandParentHeader, skipOne ? null : greatGrandParentHeader);
            qc = new QuorumCertificate(data, new TimestampedECDSASignatures());
        } else {
            qc = rootQC;
        }
        View view = parentHeader.getView().next();
        if (skipOne) {
            view = view.next();
        }
        var rawVertex = UnverifiedVertex.create(qc, view, List.of(Txn.create(new byte[0])), BFTNode.random());
        HashCode hash = hasher.hash(rawVertex);
        VerifiedVertex vertex = new VerifiedVertex(rawVertex, hash);
        lastParentHeader.set(new BFTHeader(view, hash, MOCKED_HEADER));
        lastGrandParentHeader.set(parentHeader);
        lastGreatGrandParentHeader.set(grandParentHeader);
        return vertex;
    };
    this.nextVertex = () -> nextSkippableVertex.apply(false);
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Ledger(com.radixdlt.consensus.Ledger) AtomicReference(java.util.concurrent.atomic.AtomicReference) VoteData(com.radixdlt.consensus.VoteData) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Before(org.junit.Before)

Example 12 with BFTHeader

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

Example 13 with BFTHeader

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

Example 14 with BFTHeader

use of com.radixdlt.consensus.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.consensus.BFTHeader) Test(org.junit.Test)

Example 15 with BFTHeader

use of com.radixdlt.consensus.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.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) Test(org.junit.Test)

Aggregations

BFTHeader (com.radixdlt.consensus.BFTHeader)16 Test (org.junit.Test)12 HighQC (com.radixdlt.consensus.HighQC)8 Vote (com.radixdlt.consensus.Vote)7 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)6 VoteData (com.radixdlt.consensus.VoteData)6 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)5 View (com.radixdlt.consensus.bft.View)5 LedgerHeader (com.radixdlt.consensus.LedgerHeader)4 Builder (com.radixdlt.consensus.safety.SafetyState.Builder)4 HashCode (com.google.common.hash.HashCode)3 HashSigner (com.radixdlt.consensus.HashSigner)1 Ledger (com.radixdlt.consensus.Ledger)1 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1 PreparedVertex (com.radixdlt.consensus.bft.PreparedVertex)1 VerifiedVertexStoreState (com.radixdlt.consensus.bft.VerifiedVertexStoreState)1 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)1 Hasher (com.radixdlt.crypto.Hasher)1