use of com.radixdlt.hotstuff.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);
}
use of com.radixdlt.hotstuff.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.hotstuff.BFTHeader in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_with_qc_on_different_locked_view__then_exception_is_thrown.
@Test
public void when_vote_with_qc_on_different_locked_view__then_exception_is_thrown() {
Hasher hasher = mock(Hasher.class);
when(hasher.hash(any())).thenReturn(mock(HashCode.class));
HashSigner hashSigner = mock(HashSigner.class);
when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
Vote lastVote = mock(Vote.class);
when(lastVote.getView()).thenReturn(View.of(1));
final var hashVerifier = mock(HashVerifier.class);
final var validatorSet = mock(BFTValidatorSet.class);
final var safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.getView()).thenReturn(View.of(3));
BFTHeader parent = mock(BFTHeader.class);
when(parent.getView()).thenReturn(View.of(0));
when(vertex.getParentHeader()).thenReturn(parent);
assertThat(safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
use of com.radixdlt.hotstuff.BFTHeader in project radixdlt by radixdlt.
the class Pacemaker method createAndSendTimeoutVote.
private void createAndSendTimeoutVote(PreparedVertex preparedVertex) {
final BFTHeader bftHeader = new BFTHeader(preparedVertex.getView(), preparedVertex.getId(), preparedVertex.getLedgerHeader());
final Vote baseVote = this.safetyRules.createVote(preparedVertex.getVertex(), bftHeader, this.timeSupplier.currentTime(), this.latestViewUpdate.getHighQC());
final Vote timeoutVote = this.safetyRules.timeoutVote(baseVote);
this.voteDispatcher.dispatch(this.validatorSet.nodes(), timeoutVote);
}
use of com.radixdlt.hotstuff.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);
}
Aggregations