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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations