referrerpolicy=no-referrer-when-downgrade
frame_election_provider_support

Trait ElectionDataProvider

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

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

    // Provided methods
    fn electable_targets_stateless(
        bounds: DataProviderBounds,
    ) -> Result<Vec<Self::AccountId>> { ... }
    fn electing_voters_stateless(
        bounds: DataProviderBounds,
    ) -> Result<Vec<VoterOf<Self>>> { ... }
    fn put_snapshot(
        _voters: Vec<VoterOf<Self>>,
        _targets: Vec<Self::AccountId>,
        _target_stake: Option<VoteWeight>,
    ) { ... }
    fn fetch_page(_page: PageIndex) { ... }
    fn add_voter(
        _voter: Self::AccountId,
        _weight: VoteWeight,
        _targets: BoundedVec<Self::AccountId, Self::MaxVotesPerVoter>,
    ) { ... }
    fn add_target(_target: Self::AccountId) { ... }
    fn clear() { ... }
    fn set_desired_targets(_count: u32) { ... }
}
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, page: PageIndex, ) -> Result<Vec<Self::AccountId>>

Returns the possible targets for the election associated with the provided page, 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, page: PageIndex, ) -> Result<Vec<VoterOf<Self>>>

All the voters that participate in the election associated with page page, 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 electable_targets_stateless( bounds: DataProviderBounds, ) -> Result<Vec<Self::AccountId>>

A state-less version of Self::electable_targets.

An election-provider that only uses 1 page should use this.

Source

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

A state-less version of Self::electing_voters.

An election-provider that only uses 1 page should use this.

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 fetch_page(_page: PageIndex)

Instruct the data provider to fetch a page of the solution.

This can be useful to measure the export process in benchmarking.

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.

Source

fn set_desired_targets(_count: u32)

Force set the desired targets in the snapshot.

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§

impl<T: Config> ElectionDataProvider for Pallet<T>

impl<T: Config> ElectionDataProvider for Pallet<T>