use of com.radixdlt.consensus.QuorumCertificate in project radixdlt by radixdlt.
the class PacemakerStateTest method when_process_qc_with_a_high_tc__then_should_move_to_tc_view.
@Test
public void when_process_qc_with_a_high_tc__then_should_move_to_tc_view() {
HighQC highQC = mock(HighQC.class);
QuorumCertificate qc = mock(QuorumCertificate.class);
when(qc.getView()).thenReturn(View.of(3));
when(highQC.getHighestView()).thenReturn(View.of(5));
when(highQC.highestCommittedQC()).thenReturn(qc);
this.pacemakerState.processQC(highQC);
verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(6))));
}
use of com.radixdlt.consensus.QuorumCertificate in project radixdlt by radixdlt.
the class PacemakerTest method setUp.
@Before
public void setUp() {
HighQC highQC = mock(HighQC.class);
QuorumCertificate committedQc = mock(QuorumCertificate.class);
when(committedQc.getView()).thenReturn(View.of(0));
when(highQC.highestCommittedQC()).thenReturn(committedQc);
ViewUpdate initialViewUpdate = ViewUpdate.create(View.of(0), highQC, mock(BFTNode.class), mock(BFTNode.class));
this.pacemaker = new Pacemaker(this.self, this.counters, this.validatorSet, this.vertexStore, this.safetyRules, this.timeoutDispatcher, this.timeoutSender, this.timeoutCalculator, this.nextTxnsGenerator, this.proposalDispatcher, this.voteDispatcher, hasher, timeSupplier, initialViewUpdate, new SystemCountersImpl());
}
use of com.radixdlt.consensus.QuorumCertificate 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.QuorumCertificate in project radixdlt by radixdlt.
the class VertexStoreTest method adding_a_qc_with_commit_should_commit_vertices_to_ledger.
@Test
public void adding_a_qc_with_commit_should_commit_vertices_to_ledger() {
// Arrange
final var vertices = Stream.generate(this.nextVertex).limit(4).toList();
sut.insertVertex(vertices.get(0));
sut.insertVertex(vertices.get(1));
sut.insertVertex(vertices.get(2));
// Act
QuorumCertificate qc = vertices.get(3).getQC();
boolean success = sut.addQC(qc);
// Assert
assertThat(success).isTrue();
assertThat(sut.highQC().highestQC()).isEqualTo(qc);
assertThat(sut.highQC().highestCommittedQC()).isEqualTo(qc);
assertThat(sut.getVertices(vertices.get(2).getId(), 3)).hasValue(ImmutableList.of(vertices.get(2), vertices.get(1), vertices.get(0)));
verify(committedSender, times(1)).dispatch(argThat(u -> u.committed().size() == 1 && u.committed().get(0).getVertex().equals(vertices.get(0))));
}
use of com.radixdlt.consensus.QuorumCertificate in project radixdlt by radixdlt.
the class BFTEventReducerTest method when_process_vote_with_quorum__then_processed.
@Test
public void when_process_vote_with_quorum__then_processed() {
BFTNode author = mock(BFTNode.class);
Vote vote = mock(Vote.class);
when(vote.getAuthor()).thenReturn(author);
QuorumCertificate qc = mock(QuorumCertificate.class);
HighQC highQc = mock(HighQC.class);
QuorumCertificate highestCommittedQc = mock(QuorumCertificate.class);
when(highQc.highestCommittedQC()).thenReturn(highestCommittedQc);
when(vote.getView()).thenReturn(View.of(1));
when(this.pendingVotes.insertVote(any(), any())).thenReturn(VoteProcessingResult.qcQuorum(qc));
when(this.vertexStore.highQC()).thenReturn(highQc);
// Move to view 1
this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(1), highQc, mock(BFTNode.class), this.self));
this.bftEventReducer.processVote(vote);
verify(this.viewQuorumReachedEventDispatcher, times(1)).dispatch(any());
verify(this.pendingVotes, times(1)).insertVote(eq(vote), any());
verifyNoMoreInteractions(this.pendingVotes);
}
Aggregations