use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class Pacemaker method generateProposal.
private Optional<Proposal> generateProposal(View view) {
final HighQC highQC = this.latestViewUpdate.getHighQC();
final QuorumCertificate highestQC = highQC.highestQC();
final List<Txn> nextTxns;
// TODO: Remove isEndOfEpoch knowledge from consensus
if (highestQC.getProposed().getLedgerHeader().isEndOfEpoch()) {
nextTxns = List.of();
} else {
final List<PreparedVertex> preparedVertices = vertexStore.getPathFromRoot(highestQC.getProposed().getVertexId());
nextTxns = nextTxnsGenerator.generateNextTxns(view, preparedVertices);
systemCounters.add(SystemCounters.CounterType.BFT_PACEMAKER_PROPOSED_TRANSACTIONS, nextTxns.size());
}
final UnverifiedVertex proposedVertex = UnverifiedVertex.create(highestQC, view, nextTxns, self);
final VerifiedVertex verifiedVertex = new VerifiedVertex(proposedVertex, hasher.hash(proposedVertex));
return safetyRules.signProposal(verifiedVertex, highQC.highestCommittedQC(), highQC.highestTC());
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class MockedStateComputer method commit.
@Override
public void commit(VerifiedTxnsAndProof txnsAndProof, VerifiedVertexStoreState vertexStoreState) {
var output = txnsAndProof.getProof().getNextValidatorSet().map(validatorSet -> {
LedgerProof header = txnsAndProof.getProof();
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header.getRaw());
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
QuorumCertificate genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
final var initialState = VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, initialState);
return new EpochChange(header, bftConfiguration);
}).map(e -> ImmutableClassToInstanceMap.<Object, EpochChange>of(EpochChange.class, e)).orElse(ImmutableClassToInstanceMap.of());
var ledgerUpdate = new LedgerUpdate(txnsAndProof, output);
ledgerUpdateDispatcher.dispatch(ledgerUpdate);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class QuorumCertificateTest method when_create_genesis_qc_with_non_genesis_vertex__then_should_throw_exception.
@Test
public void when_create_genesis_qc_with_non_genesis_vertex__then_should_throw_exception() {
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.getView()).thenReturn(View.of(1));
assertThatThrownBy(() -> QuorumCertificate.ofGenesis(vertex, mock(LedgerHeader.class))).isInstanceOf(IllegalArgumentException.class);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class EpochManagerTest method should_not_send_consensus_messages_if_not_part_of_new_epoch.
@Test
public void should_not_send_consensus_messages_if_not_part_of_new_epoch() {
// Arrange
epochManager.start();
BFTValidatorSet nextValidatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)));
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
LedgerHeader header = LedgerHeader.genesis(accumulatorState, nextValidatorSet, 0);
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header);
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
var proposerElection = new WeightedRotatingLeaders(nextValidatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, nextValidatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher));
LedgerProof proof = mock(LedgerProof.class);
when(proof.getEpoch()).thenReturn(header.getEpoch() + 1);
var epochChange = new EpochChange(proof, bftConfiguration);
var ledgerUpdate = new LedgerUpdate(mock(VerifiedTxnsAndProof.class), ImmutableClassToInstanceMap.of(EpochChange.class, epochChange));
// Act
epochManager.epochsLedgerUpdateEventProcessor().process(ledgerUpdate);
// Assert
verify(proposalDispatcher, never()).dispatch(any(Iterable.class), argThat(p -> p.getEpoch() == epochChange.getEpoch()));
verify(voteDispatcher, never()).dispatch(any(BFTNode.class), any());
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class ConsensusModuleTest method on_sync_request_timeout_should_retry.
@Test
public void on_sync_request_timeout_should_retry() {
// Arrange
QuorumCertificate parent = vertexStore.highQC().highestQC();
Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, validatorKeyPair);
HighQC unsyncedHighQC = HighQC.from(nextVertex.getFirst(), nextVertex.getFirst(), Optional.empty());
bftSync.syncToQC(unsyncedHighQC, validatorBftNode);
GetVerticesRequest request = new GetVerticesRequest(nextVertex.getSecond().getId(), 1);
VertexRequestTimeout timeout = VertexRequestTimeout.create(request);
// Act
// FIXME: Remove when rate limit on send removed
nothrowSleep(100);
bftSync.vertexRequestTimeoutEventProcessor().process(timeout);
// Assert
verify(requestSender, times(2)).dispatch(eq(validatorBftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Aggregations