Trait frame_election_provider_support::SortedListProvider[][src]

pub trait SortedListProvider<AccountId> {
    type Error;
    fn iter() -> Box<dyn Iterator<Item = AccountId>>;
fn count() -> u32;
fn contains(id: &AccountId) -> bool;
fn on_insert(id: AccountId, weight: VoteWeight) -> Result<(), Self::Error>;
fn on_update(id: &AccountId, weight: VoteWeight);
fn on_remove(id: &AccountId);
fn regenerate(
        all: impl IntoIterator<Item = AccountId>,
        weight_of: Box<dyn Fn(&AccountId) -> VoteWeight>
    ) -> u32;
fn clear(maybe_count: Option<u32>) -> u32;
fn sanity_check() -> Result<(), &'static str>; fn weight_update_worst_case(
        _who: &AccountId,
        _is_increase: bool
    ) -> VoteWeight { ... } }
Expand description

A utility trait for something to implement ElectionDataProvider in a sensible way.

This is generic over AccountId and it can represent a validator, a nominator, or any other entity.

To simplify the trait, the VoteWeight is hardcoded as the weight of each entity. The weights are ascending, the higher, the better. In the long term, if this trait ends up having use cases outside of the election context, it is easy enough to make it generic over the VoteWeight.

Something that implements this trait will do a best-effort sort over ids, and thus can be used on the implementing side of ElectionDataProvider.

Associated Types

The list’s error type.

Required methods

An iterator over the list, which can have take called on it.

The current count of ids in the list.

Return true if the list already contains id.

Hook for inserting a new id.

Hook for updating a single id.

Hook for removing am id from the list.

Regenerate this list from scratch. Returns the count of items inserted.

This should typically only be used at a runtime upgrade.

Remove maybe_count number of items from the list. Returns the number of items actually removed. WARNING: removes all items if maybe_count is None, which should never be done in production settings because it can lead to an unbounded amount of storage accesses.

Sanity check internal state of list. Only meant for debug compilation.

Provided methods

If who changes by the returned amount they are guaranteed to have a worst case change in their list position.

Implementors