Search in sources :

Example 1 with VoteTimeout

use of com.radixdlt.consensus.liveness.VoteTimeout in project radixdlt by radixdlt.

the class SafetyRules method timeoutVote.

public Vote timeoutVote(Vote vote) {
    if (vote.isTimeout()) {
        // vote is already timed out
        return vote;
    }
    final VoteTimeout voteTimeout = VoteTimeout.of(vote);
    final HashCode voteTimeoutHash = hasher.hash(voteTimeout);
    final ECDSASignature timeoutSignature = this.signer.sign(voteTimeoutHash);
    final Vote timeoutVote = vote.withTimeoutSignature(timeoutSignature);
    this.state = this.state.toBuilder().lastVote(timeoutVote).build();
    this.persistentSafetyStateStore.commitState(this.state);
    return timeoutVote;
}
Also used : Vote(com.radixdlt.consensus.Vote) HashCode(com.google.common.hash.HashCode) ECDSASignature(com.radixdlt.crypto.ECDSASignature) VoteTimeout(com.radixdlt.consensus.liveness.VoteTimeout)

Example 2 with VoteTimeout

use of com.radixdlt.consensus.liveness.VoteTimeout in project radixdlt by radixdlt.

the class PendingVotes method processVoteForTC.

private Optional<TimeoutCertificate> processVoteForTC(Vote vote, BFTValidatorSet validatorSet) {
    if (!vote.isTimeout()) {
        // TC can't be formed if vote is not timed out
        return Optional.empty();
    }
    final ECDSASignature timeoutSignature = vote.getTimeoutSignature().orElseThrow();
    final VoteTimeout voteTimeout = VoteTimeout.of(vote);
    final HashCode voteTimeoutHash = this.hasher.hash(voteTimeout);
    final BFTNode node = vote.getAuthor();
    final ValidationState validationState = this.timeoutVoteState.computeIfAbsent(voteTimeoutHash, k -> validatorSet.newValidationState());
    final boolean signatureAdded = validationState.addSignature(node, vote.getTimestamp(), timeoutSignature);
    if (signatureAdded && validationState.complete()) {
        return Optional.of(new TimeoutCertificate(voteTimeout.getEpoch(), voteTimeout.getView(), validationState.signatures()));
    } else {
        return Optional.empty();
    }
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) ValidationState(com.radixdlt.consensus.bft.ValidationState) HashCode(com.google.common.hash.HashCode) ECDSASignature(com.radixdlt.crypto.ECDSASignature) VoteTimeout(com.radixdlt.consensus.liveness.VoteTimeout)

Aggregations

HashCode (com.google.common.hash.HashCode)2 VoteTimeout (com.radixdlt.consensus.liveness.VoteTimeout)2 ECDSASignature (com.radixdlt.crypto.ECDSASignature)2 Vote (com.radixdlt.consensus.Vote)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1 ValidationState (com.radixdlt.consensus.bft.ValidationState)1