use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.
the class WeightedRotatingLeadersTest method setUp.
private void setUp(int validatorSetSize, int sizeOfCache) {
this.validatorsInOrder = Stream.generate(() -> ECKeyPair.generateNew().getPublicKey()).limit(validatorSetSize).map(BFTNode::create).map(node -> BFTValidator.from(node, UInt256.ONE)).sorted(Comparator.comparing(v -> v.getNode().getKey(), KeyComparator.instance().reversed())).collect(ImmutableList.toImmutableList());
BFTValidatorSet validatorSet = BFTValidatorSet.from(validatorsInOrder);
this.weightedRotatingLeaders = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
this.weightedRotatingLeaders2 = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
}
use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.
the class PendingVotes method insertVote.
/**
* Inserts a vote for a given vertex, attempting to form either a quorum certificate for that
* vertex or a timeout certificate. A quorum will only be formed if permitted by the {@link
* BFTValidatorSet}.
*
* @param vote The vote to be inserted
* @return The result of vote processing
*/
public VoteProcessingResult insertVote(Vote vote, BFTValidatorSet validatorSet) {
final BFTNode node = vote.getAuthor();
final VoteData voteData = vote.getVoteData();
final HashCode voteDataHash = this.hasher.hash(voteData);
if (!validatorSet.containsNode(node)) {
return VoteProcessingResult.rejected(VoteRejectedReason.INVALID_AUTHOR);
}
if (!replacePreviousVote(node, vote, voteDataHash)) {
return VoteProcessingResult.rejected(VoteRejectedReason.DUPLICATE_VOTE);
}
return processVoteForQC(vote, validatorSet).<VoteProcessingResult>map(VoteProcessingResult::qcQuorum).or(() -> processVoteForTC(vote, validatorSet).map(VoteProcessingResult::tcQuorum)).orElseGet(VoteProcessingResult::accepted);
}
use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.
the class PendingVotes method processVoteForQC.
private Optional<QuorumCertificate> processVoteForQC(Vote vote, BFTValidatorSet validatorSet) {
final VoteData voteData = vote.getVoteData();
final HashCode voteDataHash = this.hasher.hash(voteData);
final BFTNode node = vote.getAuthor();
final ValidationState validationState = this.voteState.computeIfAbsent(voteDataHash, k -> validatorSet.newValidationState());
final boolean signatureAdded = validationState.addSignature(node, vote.getTimestamp(), vote.getSignature());
if (signatureAdded && validationState.complete()) {
return Optional.of(new QuorumCertificate(voteData, validationState.signatures()));
} else {
return Optional.empty();
}
}
use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.
the class Pacemaker method startView.
private void startView() {
this.isViewTimedOut = false;
this.timeoutVoteVertexId = Optional.empty();
long timeout = timeoutCalculator.timeout(latestViewUpdate.uncommittedViewsCount());
ScheduledLocalTimeout scheduledLocalTimeout = ScheduledLocalTimeout.create(latestViewUpdate, timeout);
this.timeoutSender.dispatch(scheduledLocalTimeout, timeout);
final BFTNode currentViewProposer = latestViewUpdate.getLeader();
if (this.self.equals(currentViewProposer)) {
Optional<Proposal> proposalMaybe = generateProposal(latestViewUpdate.getCurrentView());
proposalMaybe.ifPresent(proposal -> {
log.trace("Broadcasting proposal: {}", proposal);
this.proposalDispatcher.dispatch(this.validatorSet.nodes(), proposal);
this.counters.increment(CounterType.BFT_PACEMAKER_PROPOSALS_SENT);
});
}
}
use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.
the class DeterministicNodes method handleMessage.
public void handleMessage(Timed<ControlledMessage> timedNextMsg) {
ControlledMessage nextMsg = timedNextMsg.value();
int senderIndex = nextMsg.channelId().senderIndex();
int receiverIndex = nextMsg.channelId().receiverIndex();
BFTNode sender = this.nodeLookup.inverse().get(senderIndex);
var injector = nodeInstances.get(receiverIndex);
ThreadContext.put("self", " " + injector.getInstance(Key.get(String.class, Self.class)));
try {
log.debug("Received message {} at {}", nextMsg, timedNextMsg.time());
nodeInstances.get(receiverIndex).getInstance(DeterministicProcessor.class).handleMessage(sender, nextMsg.message(), nextMsg.typeLiteral());
} finally {
ThreadContext.remove("self");
}
}
Aggregations