Crates.io | pallet-elections-phragmen |
lib.rs | pallet-elections-phragmen |
version | 39.0.0 |
source | src |
created_at | 2020-02-27 23:20:52.731725 |
updated_at | 2024-09-26 06:33:27.830724 |
description | FRAME pallet based on seq-Phragmén election method. |
homepage | https://paritytech.github.io/polkadot-sdk/ |
repository | https://github.com/paritytech/polkadot-sdk.git |
max_upload_size | |
id | 213379 |
size | 200,231 |
An election module based on sequential phragmen.
The election happens in rounds: every N
blocks, all previous members are retired and a new set is elected (which may
or may not have an intersection with the previous set). Each round lasts for some number of blocks defined by
TermDuration
storage item. The words term and round can be used interchangeably in this context.
TermDuration
might change during a round. This can shorten or extend the length of the round. The next election
round's block number is never stored but rather always checked on the fly. Based on the current block number and
TermDuration
, the condition BlockNumber % TermDuration == 0
being satisfied will always trigger a new election
round.
Voters can vote for any set of the candidates by providing a list of account ids. Invalid votes (voting for
non-candidates) are ignored during election. Yet, a voter might vote for a future candidate. Voters reserve a bond as
they vote. Each vote defines a value
. This amount is locked from the account of the voter and indicates the weight of
the vote. Voters can update their votes at any time by calling vote()
again. This keeps the bond untouched but can
optionally change the locked value
. After a round, votes are kept and might still be valid for further rounds. A voter
is responsible for calling remove_voter
once they are done to have their bond back and remove the lock.
Voters also report other voters as being defunct to earn their bond. A voter is defunct once all of the candidates that
they have voted for are neither a valid candidate anymore nor a member. Upon reporting, if the target voter is actually
defunct, the reporter will be rewarded by the voting bond of the target. The target will lose their bond and get
removed. If the target is not defunct, the reporter is slashed and removed. To prevent being reported, voters should
manually submit a remove_voter()
as soon as they are in the defunct state.
Candidates also reserve a bond as they submit candidacy. A candidate cannot take their candidacy back. A candidate can end up in one of the below situations:
[remove_member]
, or when an active member renounces their candidacy. Runners are automatically counted as a
candidate for the next election.All candidates, elected or not, can renounce their candidacy. A call to [Module::renounce_candidacy
] will always cause
the candidacy bond to be refunded.
Note that with the members being the default candidates for the next round and votes persisting in storage, the election
system is entirely stable given no further input. This means that if the system has a particular set of candidates C
and voters V
that lead to a set of members M
being elected, as long as V
and C
don't remove their candidacy and
votes, M
will keep being re-elected at the end of each round.
License: Apache-2.0
Polkadot SDK stable2409