referrerpolicy=no-referrer-when-downgrade
pub trait SortedListProvider<AccountId> {
    type Error: Debug;
    type Score: Bounded + Saturating + Zero;

Show 14 methods // Required methods fn iter() -> Box<dyn Iterator<Item = AccountId>>; fn iter_from( start: &AccountId, ) -> Result<Box<dyn Iterator<Item = AccountId>>, Self::Error>; fn count() -> u32; fn contains(id: &AccountId) -> bool; fn on_insert(id: AccountId, score: Self::Score) -> Result<(), Self::Error>; fn on_update(id: &AccountId, score: Self::Score) -> Result<(), Self::Error>; fn get_score(id: &AccountId) -> Result<Self::Score, Self::Error>; fn on_remove(id: &AccountId) -> Result<(), Self::Error>; fn unsafe_regenerate( all: impl IntoIterator<Item = AccountId>, score_of: Box<dyn Fn(&AccountId) -> Self::Score>, ) -> u32; fn unsafe_clear(); fn try_state() -> Result<(), TryRuntimeError>; fn score_update_worst_case( _who: &AccountId, _is_increase: bool, ) -> Self::Score; // Provided methods fn on_increase( id: &AccountId, additional: Self::Score, ) -> Result<(), Self::Error> { ... } fn on_decrease( id: &AccountId, decreased: Self::Score, ) -> Result<(), Self::Error> { ... }
}
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.

The scores (see Self::Score) are ascending, the higher, the better.

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

Required Associated Types§

source

type Error: Debug

The list’s error type.

source

type Score: Bounded + Saturating + Zero

The type used by the list to compare nodes for ordering.

Required Methods§

source

fn iter() -> Box<dyn Iterator<Item = AccountId>>

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

source

fn iter_from( start: &AccountId, ) -> Result<Box<dyn Iterator<Item = AccountId>>, Self::Error>

Returns an iterator over the list, starting right after from the given voter.

May return an error if start is invalid.

source

fn count() -> u32

The current count of ids in the list.

source

fn contains(id: &AccountId) -> bool

Return true if the list already contains id.

source

fn on_insert(id: AccountId, score: Self::Score) -> Result<(), Self::Error>

Hook for inserting a new id.

Implementation should return an error if duplicate item is being inserted.

source

fn on_update(id: &AccountId, score: Self::Score) -> Result<(), Self::Error>

Hook for updating a single id.

The new score is given.

Returns Ok(()) iff it successfully updates an item, an Err(_) otherwise.

source

fn get_score(id: &AccountId) -> Result<Self::Score, Self::Error>

Get the score of id.

source

fn on_remove(id: &AccountId) -> Result<(), Self::Error>

Hook for removing am id from the list.

Returns Ok(()) iff it successfully removes an item, an Err(_) otherwise.

source

fn unsafe_regenerate( all: impl IntoIterator<Item = AccountId>, score_of: Box<dyn Fn(&AccountId) -> Self::Score>, ) -> u32

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

This should typically only be used at a runtime upgrade.

§WARNING

This function should be called with care, regenerate will remove the current list write the new list, which can lead to too many storage accesses, exhausting the block weight.

source

fn unsafe_clear()

Remove all items from the list.

§WARNING

This function should never be called in production settings because it can lead to an unbounded amount of storage accesses.

source

fn try_state() -> Result<(), TryRuntimeError>

Check internal state of the list. Only meant for debugging.

source

fn score_update_worst_case(_who: &AccountId, _is_increase: bool) -> Self::Score

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

Provided Methods§

source

fn on_increase( id: &AccountId, additional: Self::Score, ) -> Result<(), Self::Error>

Same as on_update, but incorporate some increased score.

source

fn on_decrease( id: &AccountId, decreased: Self::Score, ) -> Result<(), Self::Error>

Same as on_update, but incorporate some decreased score.

If the new score of the item is Zero, it is removed.

Object Safety§

This trait is not object safe.

Implementors§