ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Leios.VoteState

Description

The votes the node has accepted, from whichever peer.

Each LeiosNotify client already holds its own upstream peer to one vote per seat in an election. But the node relays what it accepts from all its peers, and a downstream peer holds the node to the same, and to having relayed the announcement a vote is for. So the node decides once, here, whether a vote is new and valid, and only then relays it.

A vote is relayed only to be aggregated into a certificate, which the earliest block that can carry it needs in the first slot at or after the vote's deadline, the end of its diffusion period (voteUntil). The node neither keeps nor relays a vote it has only after its deadline. Such a vote could still complete a certificate for a later block, but a quorum that late is no evidence that the endorser block's data diffused in time, so the node deliberately gives up that throughput rather than endanger safety.

So the node aggregates the votes for an announcement into its certificate as soon as they reach quorum, which is before pruneVotes passes their deadline, or never. It keeps the certificate until the announcing block is immutable, long after it forgot the votes, for whichever block comes to certify it.

Synopsis

Documentation

data VoteState (m ∷ Type → Type) blk Source #

The node's votes, and where it learns which announcements it relays and relays the votes.

newVoteState ∷ IOLike m ⇒ Tracer m TraceLeiosVoteState → AnnounceState m blk → NotifyLog m blk → m (VoteState m blk) Source #

data TraceLeiosVoteState Source #

What the node's VoteState traces, for each vote it adds or does not, so these are frequent. What addVote did with a vote is up to its caller to trace.

Constructors

TraceLeiosVoteAdding !LeiosVote

The node starts to add a vote, and to check whether it should.

TraceLeiosVoteAwaitingWindow !LeiosVote !NominalDiffTime

The vote arrived before its window opened, so the node waits this long before adding it.

TraceLeiosVoteValidated !LeiosVote

The node validated a vote, its seat and signature, and has yet to add it.

TraceLeiosCertified !RankingBlockHash !LeiosCert

The votes for this announcement reached quorum, and the node aggregated them into its certificate.

TraceLeiosAggregationFailed !RankingBlockHash !AggregationError

The node could not aggregate the votes for this announcement, though they reached quorum.

TraceLeiosQuorumMissed !RankingBlockHash !Weight

The deadline of the votes for this announcement passed with only this much weight voting for it, short of quorum. Not traced for an announcement without any vote. Many of these, for announcements of valid endorser blocks, mean the diffusion period is too short for the network.

Votes

currentVotes ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ VoteState m blk → STM m (Map SlotNo (Map LeiosSeatId LeiosVote)) Source #

The votes the node keeps, by election slot and seat.

addVote ∷ (IOLike m, ConvertRawHash blk, GetHeader blk) ⇒ VoteState m blk → SystemTime m → AcceptedVote → m AddVoteResult Source #

Add a vote, if it is the first valid vote of its seat in its election, for an announcement the node relays, and the node has it by its deadline.

NOTE: This will wait until the vote's window is open.

The signature is verified between two transactions, so that a retry does not repeat a BLS verification. As verifying takes time, recordVote checks again whether the node has seen or forgotten the vote. The relay log stops relaying it after its deadline.

data AddVoteResult Source #

What addVote did with a vote.

Constructors

ArrivedTooLate

The node had it only after its deadline, or after it forgot its election.

AlreadyKnown

We already saw a vote of its seat in its election.

NotAnnounced

We did not relay the announcement it is for.

VoteInvalid !InvalidVoteReason

Its seat has no key in the committee, or its signature does not verify under it.

Added

The node keeps the vote and relays it.

Instances

Instances details
Eq AddVoteResult Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.VoteState

Show AddVoteResult Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.VoteState

validateVote ∷ AcceptedVote → Either InvalidVoteReason ValidatedVote Source #

Validate a vote against its election's committee, or say why it is invalid.

data ValidatedVote Source #

A vote whose seat has a key in the committee, and whose signature verifies under it.

Constructors

MkValidatedVote 

Fields

recordVote ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ VoteState m blk → ValidatedVote → STM m (Either AddVoteResult (Maybe (Map LeiosSeatId LeiosSignature))) Source #

Keep and relay a vote the node has neither seen nor forgotten, as it was pruned past the vote's deadline already. If the votes for its announcement reach quorum, return their signatures.

pruneVotes ∷ IOLike m ⇒ VoteState m blk → RelativeTime → m () Source #

Forget the votes of every election slot whose deadline has passed at the given time, and trace the announcements among them that missed their quorum.

recordVote then finds any later copy of their votes ArrivedTooLate.

Certificates

getCertificate ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ VoteState m blk → RankingBlockHash → STM m (Maybe LeiosCert) Source #

The certificate of this announcement, if the votes for it reached quorum before pruneVotes passed their deadline.

pruneCertificates ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ VoteState m blk → SlotNo → STM m () Source #

Forget the certificates of every election slot before the given slot, the immutable tip's.

The announcing block of such a certificate is immutable, and all of its successors are either also immutable or unreachable from the immutable tip. Until then, a certificate is kept for whichever block comes to certify it, however late.