ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

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:

  1. Quorum not reached: multiple block targets are candidates, each accumulating votes and weight. All targets compete to reach quorum first.
  2. 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 separate NoQuorum and Quorum types representing the two states (1) and (2) described above, respectively.
  • PerasTargetVoteState: tracks votes for one specific block target
  • PerasVoteCollection: raw vote count and weight accumulation
  • PerasTargetVoteStatus: 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

Documentation

data PerasRoundVoteState blk Source #

Current vote state for a given round

Instances

Instances details
(StandardHash blk, Eq (PerasVote blk), Eq (PerasCert blk), Eq (PerasVotingCommittee blk))Eq (PerasRoundVoteState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

Generic (PerasRoundVoteState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

Associated Types

type Rep (PerasRoundVoteState blk) 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

(StandardHash blk, Show (PerasVote blk), Show (PerasCert blk), Show (PerasVotingCommittee blk))Show (PerasRoundVoteState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

(StandardHash blk, NoThunks (PerasVote blk), NoThunks (PerasCert blk), NoThunks (PerasVotingCommittee blk))NoThunks (PerasRoundVoteState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

type Rep (PerasRoundVoteState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

getPerasRoundVoteStateRoundPerasRoundVoteState blk → PerasRoundNo Source #

Get the round number of a round vote state

getPerasRoundVoteStateCertMaybePerasRoundVoteState blk → Maybe (ValidatedPerasCert blk) Source #

Get the certificate if quorum was reached for the given round

getPerasRoundVoteStateMaxTargetedSlotPerasRoundVoteState 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 VoteGeneratedNewCertValidatedPerasCert blk → PerasRoundVoteState blk Source #

Matches a round vote state where a certificate has just been forged

pattern VoteDidntGenerateNewCertPerasRoundVoteState blk Source #

Matches a round vote state where a certificate has either not yet been forged, or was forged by a previous vote

updatePerasRoundVoteStatesStandardHash 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

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

Instances details
(Eq (PerasVoteCollection blk), Eq (ValidatedPerasCert blk))Eq (PerasTargetVoteState blk status) Source # 
Instance details

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 # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

Methods

comparePerasTargetVoteState 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 #

maxPerasTargetVoteState blk status → PerasTargetVoteState blk status → PerasTargetVoteState blk status #

minPerasTargetVoteState blk status → PerasTargetVoteState blk status → PerasTargetVoteState blk status #

(Show (PerasVoteCollection blk), Show (ValidatedPerasCert blk))Show (PerasTargetVoteState blk status) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Vote.Aggregation

Methods

showsPrecIntPerasTargetVoteState blk status → ShowS #

showPerasTargetVoteState blk status → String #

showList ∷ [PerasTargetVoteState blk status] → ShowS #

(NoThunks (PerasVoteCollection blk), NoThunks (ValidatedPerasCert blk))NoThunks (PerasTargetVoteState blk status) Source # 
Instance details

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