pub trait ElectionDataProvider {
    type AccountId;
    type BlockNumber;
    type MaxVotesPerVoter: Get<u32>;

    fn electable_targets(
        maybe_max_len: Option<usize>
    ) -> Result<Vec<Self::AccountId>>; fn electing_voters(
        maybe_max_len: Option<usize>
    ) -> Result<Vec<VoterOf<Self>>>; fn desired_targets() -> Result<u32>; fn next_election_prediction(now: Self::BlockNumber) -> Self::BlockNumber; fn put_snapshot(
        _voters: Vec<VoterOf<Self>>,
        _targets: Vec<Self::AccountId>,
        _target_stake: Option<VoteWeight>
    ) { ... } fn add_voter(
        _voter: Self::AccountId,
        _weight: VoteWeight,
        _targets: BoundedVec<Self::AccountId, Self::MaxVotesPerVoter>
    ) { ... } fn add_target(_target: Self::AccountId) { ... } fn clear() { ... } }
Expand description

Something that can provide the data to an ElectionProvider.

Required Associated Types§

The account identifier type.

The block number type.

Maximum number of votes per voter that this data provider is providing.

Required Methods§

All possible targets for the election, i.e. the targets that could become elected, thus “electable”.

If maybe_max_len is Some(v) then the resulting vector MUST NOT be longer than v items long.

This should be implemented as a self-weighing function. The implementor should register its appropriate weight at the end of execution with the system pallet directly.

All the voters that participate in the election, thus “electing”.

Note that if a notion of self-vote exists, it should be represented here.

If maybe_max_len is Some(v) then the resulting vector MUST NOT be longer than v items long.

This should be implemented as a self-weighing function. The implementor should register its appropriate weight at the end of execution with the system pallet directly.

The number of targets to elect.

This should be implemented as a self-weighing function. The implementor should register its appropriate weight at the end of execution with the system pallet directly.

A sensible implementation should use the minimum between this value and [Self::targets().len()], since desiring a winner set larger than candidates is not feasible.

This is documented further in issue: https://github.com/paritytech/substrate/issues/9478

Provide a best effort prediction about when the next election is about to happen.

In essence, the implementor should predict with this function when it will trigger the ElectionProvider::elect.

This is only useful for stateful election providers.

Provided Methods§

Utility function only to be used in benchmarking scenarios, to be implemented optionally, else a noop.

Utility function only to be used in benchmarking scenarios, to be implemented optionally, else a noop.

Same as put_snapshot, but can add a single voter one by one.

Utility function only to be used in benchmarking scenarios, to be implemented optionally, else a noop.

Same as put_snapshot, but can add a single voter one by one.

Clear all voters and targets.

Implementors§