[][src]Crate sp_phragmen

Rust implementation of the Phragmén election algorithm. This is used in several pallets to optimally distribute the weight of a set of voters among an elected set of candidates. In the context of staking this is mapped to validators and nominators.

The algorithm has two phases:

  • Sequential phragmen: performed in elect function which is first pass of the distribution The results are not optimal but the execution time is less.
  • Equalize post-processing: tries to further distribute the weight fairly among candidates. Incurs more execution time.

The main objective of the assignments done by phragmen is to maximize the minimum backed candidate in the elected set.

Reference implementation: https://github.com/w3f/consensus Further details: https://research.web3.foundation/en/latest/polkadot/NPoS/4.%20Sequential%20Phragm%C3%A9n%E2%80%99s%20method/

Structs

Candidate

A candidate entity for phragmen election.

Edge

A candidate being backed by a voter.

PhragmenResult

Final result of the phragmen election.

Support

A structure to demonstrate the phragmen result from the perspective of the candidate, i.e. how much support each candidate is receiving.

Voter

A voter entity.

Functions

build_support_map

Build the support map from the given phragmen result.

elect

Perform election based on Phragmén algorithm.

equalize

Performs equalize post-processing to the output of the election algorithm. This happens in rounds. The number of rounds and the maximum diff-per-round tolerance can be tuned through input parameters.

Type Definitions

ExtendedBalance

A type in which performing operations on balances and stakes of candidates and voters are safe.

PhragmenAssignment

Particular AccountId was backed by T-ratio of a nominator's stake.

PhragmenStakedAssignment

Particular AccountId was backed by ExtendedBalance of a nominator's stake.

SupportMap

A linkage from a candidate and its Support.