referrerpolicy=no-referrer-when-downgrade
frame_election_provider_support

Trait ElectionProvider

Source
pub trait ElectionProvider {
    type AccountId;
    type BlockNumber;
    type Error: Debug + PartialEq;
    type MaxWinnersPerPage: Get<u32>;
    type MaxBackersPerWinner: Get<u32>;
    type Pages: Get<PageIndex>;
    type DataProvider: ElectionDataProvider<AccountId = Self::AccountId, BlockNumber = Self::BlockNumber>;

    // Required methods
    fn elect(page: PageIndex) -> Result<BoundedSupportsOf<Self>, Self::Error>;
    fn duration() -> Self::BlockNumber;
    fn start() -> Result<(), Self::Error>;
    fn status() -> Result<bool, ()>;

    // Provided methods
    fn msp() -> PageIndex { ... }
    fn lsp() -> PageIndex { ... }
    fn desired_targets_checked() -> Result<u32> { ... }
    fn duration_with_export() -> Self::BlockNumber
       where Self::BlockNumber: From<PageIndex> + Add<Output = Self::BlockNumber> { ... }
    fn asap() { ... }
}
Expand description

Something that can compute the result of an election and pass it back to the caller in a paged way.

Required Associated Types§

Source

type AccountId

The account ID identifier;

Source

type BlockNumber

The block number type.

Source

type Error: Debug + PartialEq

The error type returned by the provider;

Source

type MaxWinnersPerPage: Get<u32>

The maximum number of winners per page in results returned by this election provider.

A winner is an AccountId that is part of the final election result.

Source

type MaxBackersPerWinner: Get<u32>

The maximum number of backers that a single page may have in results returned by this election provider.

A backer is an AccountId that “backs” one or more winners. For example, in the context of nominated proof of stake, a backer is a voter that nominates a winner validator in the election result.

Source

type Pages: Get<PageIndex>

The number of pages that this election provider supports.

Source

type DataProvider: ElectionDataProvider<AccountId = Self::AccountId, BlockNumber = Self::BlockNumber>

The data provider of the election.

Required Methods§

Source

fn elect(page: PageIndex) -> Result<BoundedSupportsOf<Self>, Self::Error>

Elect a new set of winners.

A complete election may require multiple calls to ElectionProvider::elect if ElectionProvider::Pages is higher than one.

The result is returned in a target major format, namely as vector of supports.

Source

fn duration() -> Self::BlockNumber

Return the duration of your election.

This excludes the duration of the export. For that, use Self::duration_with_export.

Source

fn start() -> Result<(), Self::Error>

Signal that the election should start

Source

fn status() -> Result<bool, ()>

Indicate whether this election provider is currently ongoing an asynchronous election.

Err(()) should signal that we are not doing anything, and elect should def. not be called. Ok(false) means we are doing something, but work is still ongoing. elect should not be called. Ok(true) means we are done and ready for a call to elect.

Provided Methods§

Source

fn msp() -> PageIndex

The index of the most significant page that this election provider supports.

Source

fn lsp() -> PageIndex

The index of the least significant page that this election provider supports.

Source

fn desired_targets_checked() -> Result<u32>

checked call to Self::DataProvider::desired_targets() ensuring the value never exceeds Self::MaxWinnersPerPage.

Source

fn duration_with_export() -> Self::BlockNumber
where Self::BlockNumber: From<PageIndex> + Add<Output = Self::BlockNumber>,

Return the duration of your election, including the export.

Source

fn asap()

Signal the election provider that we are about to call elect asap, and it should prepare itself.

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§

Source§

impl<AccountId, BlockNumber, DataProvider, MaxWinnersPerPage, MaxBackersPerWinner> ElectionProvider for NoElection<(AccountId, BlockNumber, DataProvider, MaxWinnersPerPage, MaxBackersPerWinner)>
where DataProvider: ElectionDataProvider<AccountId = AccountId, BlockNumber = BlockNumber>, MaxWinnersPerPage: Get<u32>, MaxBackersPerWinner: Get<u32>, BlockNumber: Zero,

Source§

type AccountId = AccountId

Source§

type BlockNumber = BlockNumber

Source§

type Error = &'static str

Source§

type Pages = ConstU32<1>

Source§

type DataProvider = DataProvider

Source§

type MaxWinnersPerPage = MaxWinnersPerPage

Source§

type MaxBackersPerWinner = MaxBackersPerWinner

Source§

impl<T: Config> ElectionProvider for OnChainExecution<T>

Source§

type AccountId = <<T as Config>::System as Config>::AccountId

Source§

type BlockNumber = <<<<T as Config>::System as Config>::Block as HeaderProvider>::HeaderT as Header>::Number

Source§

type Error = Error

Source§

type MaxWinnersPerPage = <T as Config>::MaxWinnersPerPage

Source§

type MaxBackersPerWinner = <T as Config>::MaxBackersPerWinner

Source§

type Pages = ConstU32<1>

Source§

type DataProvider = <T as Config>::DataProvider

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

impl<T: Config> ElectionProvider for Continue<T>

impl<T: Config> ElectionProvider for InitiateEmergencyPhase<T>

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