Trait ElectionDataProvider

Source
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;
}
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§