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
Required methods
An iterator over the list, which can have take
called on it.
Hook for inserting a new id.
fn on_update(id: &AccountId, weight: VoteWeight)
fn on_update(id: &AccountId, weight: VoteWeight)
Hook for updating a single id.
fn regenerate(
all: impl IntoIterator<Item = AccountId>,
weight_of: Box<dyn Fn(&AccountId) -> VoteWeight>
) -> u32
fn regenerate(
all: impl IntoIterator<Item = AccountId>,
weight_of: Box<dyn Fn(&AccountId) -> VoteWeight>
) -> u32
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.
fn sanity_check() -> Result<(), &'static str>
fn sanity_check() -> Result<(), &'static str>
Sanity check internal state of list. Only meant for debug compilation.
Provided methods
fn weight_update_worst_case(_who: &AccountId, _is_increase: bool) -> VoteWeight
fn weight_update_worst_case(_who: &AccountId, _is_increase: bool) -> VoteWeight
If who
changes by the returned amount they are guaranteed to have a worst case change
in their list position.