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

    // Required methods
    fn electable_targets(
        bounds: DataProviderBounds
    ) -> Result<Vec<Self::AccountId>>;
    fn electing_voters(bounds: DataProviderBounds) -> Result<Vec<VoterOf<Self>>>;
    fn desired_targets() -> Result<u32>;
    fn next_election_prediction(now: Self::BlockNumber) -> Self::BlockNumber;

    // Provided methods
    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§

source

type AccountId: Encode

The account identifier type.

source

type BlockNumber

The block number type.

source

type MaxVotesPerVoter: Get<u32>

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

Required Methods§

source

fn electable_targets(bounds: DataProviderBounds) -> Result<Vec<Self::AccountId>>

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

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.

source

fn electing_voters(bounds: DataProviderBounds) -> Result<Vec<VoterOf<Self>>>

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

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

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.

source

fn desired_targets() -> Result<u32>

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

source

fn next_election_prediction(now: Self::BlockNumber) -> Self::BlockNumber

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§

source

fn put_snapshot( _voters: Vec<VoterOf<Self>>, _targets: Vec<Self::AccountId>, _target_stake: Option<VoteWeight> )

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

source

fn add_voter( _voter: Self::AccountId, _weight: VoteWeight, _targets: BoundedVec<Self::AccountId, Self::MaxVotesPerVoter> )

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.

source

fn add_target(_target: Self::AccountId)

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.

source

fn clear()

Clear all voters and targets.

Implementors§