| 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 stake-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 stake 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 stake backing each candidate block. When one target accumulates enough stake 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 stake. 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 PerasCfg. Depending on this
configuration and the stake 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 stake + 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 stake 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 targetPerasTargetVoteTally: raw vote count and stake 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
- ptvsTotalStake ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → PerasVoteStake
- pattern VoteGeneratedNewCert ∷ ValidatedPerasCert blk → PerasRoundVoteState blk
- pattern VoteDidntGenerateNewCert ∷ PerasRoundVoteState blk
- updatePerasRoundVoteStates ∷ StandardHash blk ⇒ WithArrivalTime (ValidatedPerasVote blk) → PerasCfg blk → Map PerasRoundNo (PerasRoundVoteState blk) → Either (UpdateRoundVoteStateError blk) (PerasRoundVoteState blk, Map PerasRoundNo (PerasRoundVoteState blk))
- getPerasRoundVoteStateCertMaybe ∷ PerasRoundVoteState blk → Maybe (ValidatedPerasCert blk)
- data UpdateRoundVoteStateError blk
- = RoundVoteStateLoserAboveQuorum (PerasTargetVoteState blk 'Winner) (PerasTargetVoteState blk 'Loser)
- | RoundVoteStateForgingCertError (PerasForgeErr blk)
Documentation
data PerasRoundVoteState blk Source #
Current vote state for a given round
Instances
ptvsTotalStake ∷ ∀ blk (status ∷ PerasTargetVoteStatus). PerasTargetVoteState blk status → PerasVoteStake Source #
Extract the total stake from a target vote state
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) → PerasCfg 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.
getPerasRoundVoteStateCertMaybe ∷ PerasRoundVoteState blk → Maybe (ValidatedPerasCert blk) Source #
Get the certificate if quorum was reached for the given round
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 (PerasForgeErr blk) |