| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Peras.Vote.Aggregation
Description
Peras vote aggregation and certificate forging
This module implements the core voting logic for the Peras protocol, which aggregates weighted votes on chain blocks and forges certificates when quorum is reached.
Overview
In Peras, validators vote on specific blocks during designated voting rounds. Each vote carries a weight, and votes are aggregated by:
- Round: each vote belongs to a specific
PerasRoundNo - Target: within a round, votes are cast for different block
Points
As votes arrive, the system tracks the total weight backing each candidate block. When one target accumulates enough weight to exceed the configured quorum threshold, a certificate is automatically forged for that block, making it a winner for that round.
State Machine
For every round being voted for, the aggregation follows a state machine:
- Quorum not reached: multiple block targets are candidates, each accumulating votes and weight. All targets compete to reach quorum first.
- Quorum reached: once a target reaches quorum, it becomes the winner and a certificate is forged. All other targets become losers and continue tracking votes without affecting the outcome.
Quorum Threshold and Multiple Winners
The quorum threshold is parameterized via PerasParams. Depending on this
configuration and the weight distribution, it may be theoretically possible
for multiple targets to exceed the threshold within the same round.
This module treats multiple winners as an error condition and rejects votes
that would cause this, raising instead a RoundVoteStateLoserAboveQuorum
exception. This indicates that either:
* The quorum threshold is misconfigured, or that
* We were extremely unlucky when randomly selecting the voting committee.
With a correct threshold configuration (e.g., > 3/4 of total weight + a small safety margin to account for an unlucky local sortition when selecting non-persistent voters during committee selection), multiple winners should be impossible given honest weight distribution.
Key Types
PerasRoundVoteState: tracks all voting activity for a single round, and its logically split between separateNoQuorumandQuorumtypes representing the two states (1) and (2) described above, respectively.PerasTargetVoteState: tracks votes for one specific block targetPerasVoteCollection: raw vote count and weight accumulationPerasTargetVoteStatus: type-level status (CandidateWinnerLoser)UpdateRoundVoteStateError: errors from invalid state transitions
Usage
The primary entry point is updatePerasRoundVoteStates, which adds a new
vote to the aggregate state. Pattern synonyms VoteGeneratedNewCert and
VoteDidntGenerateNewCert allow clients to observe when certificates are
freshly forged (as opposed to voting on an already-won target).
Synopsis
- data PerasRoundVoteState blk
- getPerasRoundVoteStateRound ∷ PerasRoundVoteState blk → PerasRoundNo
- getPerasRoundVoteStateCertMaybe ∷ PerasRoundVoteState blk → Maybe (ValidatedPerasCert blk)
- getPerasRoundVoteStateMaxTargetedSlot ∷ PerasRoundVoteState blk → WithOrigin SlotNo
- pattern VoteGeneratedNewCert ∷ ValidatedPerasCert blk → PerasRoundVoteState blk
- pattern VoteDidntGenerateNewCert ∷ PerasRoundVoteState blk
- updatePerasRoundVoteStates ∷ StandardHash blk ⇒ WithArrivalTime (ValidatedPerasVote blk) → PerasParams blk → Map PerasRoundNo (PerasRoundVoteState blk) → Either (UpdateRoundVoteStateError blk) (PerasRoundVoteState blk, Map PerasRoundNo (PerasRoundVoteState blk))
- data UpdateRoundVoteStateError blk
- = RoundVoteStateLoserAboveQuorum (PerasTargetVoteState blk 'Winner) (PerasTargetVoteState blk 'Loser)
- | RoundVoteStateForgingCertError (PerasError blk)
- data PerasTargetVoteState blk (status ∷ PerasTargetVoteStatus)
- getPerasTargetVoteStateTotalWeight ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → VoteWeight
- getPerasTargetVoteStateBlock ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → Point blk
Documentation
data PerasRoundVoteState blk Source #
Current vote state for a given round
Instances
getPerasRoundVoteStateRound ∷ PerasRoundVoteState blk → PerasRoundNo Source #
Get the round number of a round vote state
getPerasRoundVoteStateCertMaybe ∷ PerasRoundVoteState blk → Maybe (ValidatedPerasCert blk) Source #
Get the certificate if quorum was reached for the given round
getPerasRoundVoteStateMaxTargetedSlot ∷ PerasRoundVoteState blk → WithOrigin SlotNo Source #
Get the youngest (maximum) slot targeted by a vote in this round.
This is useful for garbage collection: a round voting data can be fully collected only when its youngest targeted slot is strictly older than the GC threshold.
pattern VoteGeneratedNewCert ∷ ValidatedPerasCert blk → PerasRoundVoteState blk Source #
Matches a round vote state where a certificate has just been forged
pattern VoteDidntGenerateNewCert ∷ PerasRoundVoteState blk Source #
Matches a round vote state where a certificate has either not yet been forged, or was forged by a previous vote
updatePerasRoundVoteStates ∷ StandardHash blk ⇒ WithArrivalTime (ValidatedPerasVote blk) → PerasParams blk → Map PerasRoundNo (PerasRoundVoteState blk) → Either (UpdateRoundVoteStateError blk) (PerasRoundVoteState blk, Map PerasRoundNo (PerasRoundVoteState blk)) Source #
Updates the round vote states map with the given vote.
A new entry is created if necessary (i.e., if there is no existing state for the vote's round).
May fail if the state transition is invalid (e.g., a loser going above quorum) or if forging the certificate fails.
data UpdateRoundVoteStateError blk Source #
Errors that may occur when updating the round vote state with a new vote
Constructors
| RoundVoteStateLoserAboveQuorum (PerasTargetVoteState blk 'Winner) (PerasTargetVoteState blk 'Loser) | |
| RoundVoteStateForgingCertError (PerasError blk) |
data PerasTargetVoteState blk (status ∷ PerasTargetVoteStatus) Source #
Voting state for a given target.
We indicate at type level the status of the target w.r.t the voting process.
Instances
| (Eq (PerasVoteCollection blk), Eq (ValidatedPerasCert blk)) ⇒ Eq (PerasTargetVoteState blk status) Source # | |
Defined in Ouroboros.Consensus.Peras.Vote.Aggregation Methods (==) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # (/=) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # | |
| (Ord (PerasVoteCollection blk), Ord (ValidatedPerasCert blk)) ⇒ Ord (PerasTargetVoteState blk status) Source # | |
Defined in Ouroboros.Consensus.Peras.Vote.Aggregation Methods compare ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Ordering # (<) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # (<=) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # (>) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # (>=) ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → Bool # max ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → PerasTargetVoteState blk status # min ∷ PerasTargetVoteState blk status → PerasTargetVoteState blk status → PerasTargetVoteState blk status # | |
| (Show (PerasVoteCollection blk), Show (ValidatedPerasCert blk)) ⇒ Show (PerasTargetVoteState blk status) Source # | |
Defined in Ouroboros.Consensus.Peras.Vote.Aggregation Methods showsPrec ∷ Int → PerasTargetVoteState blk status → ShowS # show ∷ PerasTargetVoteState blk status → String # showList ∷ [PerasTargetVoteState blk status] → ShowS # | |
| (NoThunks (PerasVoteCollection blk), NoThunks (ValidatedPerasCert blk)) ⇒ NoThunks (PerasTargetVoteState blk status) Source # | |
Defined in Ouroboros.Consensus.Peras.Vote.Aggregation | |
getPerasTargetVoteStateTotalWeight ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → VoteWeight Source #
Extract the total weight from a target vote state
getPerasTargetVoteStateBlock ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → Point blk Source #
Extract the block point from a target vote state