Search in sources :

Example 16 with BFTNode

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);
}
Also used : IntStream(java.util.stream.IntStream) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Test(org.junit.Test) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Supplier(java.util.function.Supplier) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) View(com.radixdlt.hotstuff.bft.View) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableList(com.google.common.collect.ImmutableList) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Map(java.util.Map) KeyComparator(com.radixdlt.utils.KeyComparator) Comparator(java.util.Comparator) UInt256(com.radixdlt.utils.UInt256) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet)

Example 17 with BFTNode

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);
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) VoteProcessingResult(com.radixdlt.hotstuff.bft.VoteProcessingResult)

Example 18 with BFTNode

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();
    }
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ValidationState(com.radixdlt.hotstuff.bft.ValidationState) HashCode(com.google.common.hash.HashCode)

Example 19 with BFTNode

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);
        });
    }
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Proposal(com.radixdlt.hotstuff.Proposal)

Example 20 with BFTNode

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");
    }
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Self(com.radixdlt.hotstuff.bft.Self)

Aggregations

BFTNode (com.radixdlt.hotstuff.bft.BFTNode)40 Test (org.junit.Test)22 View (com.radixdlt.hotstuff.bft.View)14 LedgerProof (com.radixdlt.hotstuff.LedgerProof)9 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)9 HashCode (com.google.common.hash.HashCode)8 ECKeyPair (com.radixdlt.crypto.ECKeyPair)8 HighQC (com.radixdlt.hotstuff.HighQC)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 Vote (com.radixdlt.hotstuff.Vote)7 ImmutableList (com.google.common.collect.ImmutableList)6 AbstractModule (com.google.inject.AbstractModule)6 TypeLiteral (com.google.inject.TypeLiteral)6 BFTHeader (com.radixdlt.hotstuff.BFTHeader)6 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 Proposal (com.radixdlt.hotstuff.Proposal)5 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)5 BFTCommittedUpdate (com.radixdlt.hotstuff.bft.BFTCommittedUpdate)5 Self (com.radixdlt.hotstuff.bft.Self)5 Inject (com.google.inject.Inject)4