use of com.radixdlt.consensus.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));
SafetyRules safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner);
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.consensus.BFTHeader in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit.
@Test
public void when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit() {
when(safetyState.getLastVotedView()).thenReturn(View.of(0));
when(safetyState.getLockedView()).thenReturn(View.of(0));
when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.hasDirectParent()).thenReturn(true);
when(vertex.touchesGenesis()).thenReturn(true);
when(vertex.parentHasDirectParent()).thenReturn(true);
when(vertex.getView()).thenReturn(View.of(1));
BFTHeader parent = mock(BFTHeader.class);
when(parent.getView()).thenReturn(View.of(0));
when(vertex.getParentHeader()).thenReturn(parent);
BFTHeader grandParent = mock(BFTHeader.class);
when(grandParent.getView()).thenReturn(mock(View.class));
when(vertex.getGrandParentHeader()).thenReturn(grandParent);
BFTHeader header = mock(BFTHeader.class);
Optional<Vote> voteMaybe = safetyRules.voteFor(vertex, header, 1L, mock(HighQC.class));
assertThat(voteMaybe).isNotEmpty();
Vote vote = voteMaybe.get();
assertThat(vote.getVoteData().getProposed()).isEqualTo(header);
assertThat(vote.getVoteData().getParent()).isEqualTo(parent);
assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
use of com.radixdlt.consensus.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.consensus.BFTHeader in project radixdlt by radixdlt.
the class ConsensusModuleTest method createNextVertex.
private Pair<QuorumCertificate, VerifiedVertex> createNextVertex(QuorumCertificate parent, BFTNode bftNode, Txn txn) {
var unverifiedVertex = UnverifiedVertex.create(parent, View.of(1), List.of(txn), bftNode);
var hash = hasher.hash(unverifiedVertex);
var verifiedVertex = new VerifiedVertex(unverifiedVertex, hash);
var next = new BFTHeader(View.of(1), verifiedVertex.getId(), LedgerHeader.create(1, View.of(1), new AccumulatorState(1, HashUtils.zero256()), 1));
var voteData = new VoteData(next, parent.getProposed(), parent.getParent());
var unsyncedQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures(Map.of(bftNode, TimestampedECDSASignature.from(1, zeroSignature()))));
return Pair.of(unsyncedQC, verifiedVertex);
}
use of com.radixdlt.consensus.BFTHeader in project radixdlt by radixdlt.
the class SafetyRules method constructVoteData.
private static VoteData constructVoteData(VerifiedVertex proposedVertex, BFTHeader proposedHeader) {
final BFTHeader parent = proposedVertex.getParentHeader();
// Add a vertex to commit if creating a quorum for the proposed vertex would
// create three consecutive qcs.
final BFTHeader toCommit;
if (proposedVertex.touchesGenesis() || !proposedVertex.hasDirectParent() || !proposedVertex.parentHasDirectParent()) {
toCommit = null;
} else {
toCommit = proposedVertex.getGrandParentHeader();
}
return new VoteData(proposedHeader, parent, toCommit);
}
Aggregations