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§
Sourcetype BlockNumber
type BlockNumber
The block number type.
Sourcetype MaxWinnersPerPage: Get<u32>
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.
Sourcetype MaxBackersPerWinner: Get<u32>
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.
Sourcetype DataProvider: ElectionDataProvider<AccountId = Self::AccountId, BlockNumber = Self::BlockNumber>
type DataProvider: ElectionDataProvider<AccountId = Self::AccountId, BlockNumber = Self::BlockNumber>
The data provider of the election.
Required Methods§
Sourcefn elect(page: PageIndex) -> Result<BoundedSupportsOf<Self>, Self::Error>
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.
Sourcefn duration() -> Self::BlockNumber
fn duration() -> Self::BlockNumber
Return the duration of your election.
This excludes the duration of the export. For that, use Self::duration_with_export
.
Sourcefn status() -> Result<bool, ()>
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§
Sourcefn msp() -> PageIndex
fn msp() -> PageIndex
The index of the most significant page that this election provider supports.
Sourcefn lsp() -> PageIndex
fn lsp() -> PageIndex
The index of the least significant page that this election provider supports.
Sourcefn desired_targets_checked() -> Result<u32>
fn desired_targets_checked() -> Result<u32>
checked call to Self::DataProvider::desired_targets()
ensuring the value never exceeds
Self::MaxWinnersPerPage
.
Sourcefn duration_with_export() -> Self::BlockNumber
fn duration_with_export() -> Self::BlockNumber
Return the duration of your election, including the export.
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.