Trait frame_election_provider_support::SortedListProvider [−][src]
pub trait SortedListProvider<AccountId> {
type Error;
fn iter() -> Box<dyn Iterator<Item = AccountId>>ⓘimpl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
;
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 unsafe_regenerate(
all: impl IntoIterator<Item = AccountId>,
weight_of: Box<dyn Fn(&AccountId) -> VoteWeight>
) -> u32;
fn unsafe_clear();
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
fn iter() -> Box<dyn Iterator<Item = AccountId>>ⓘimpl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn iter() -> Box<dyn Iterator<Item = AccountId>>ⓘimpl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
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 unsafe_regenerate(
all: impl IntoIterator<Item = AccountId>,
weight_of: Box<dyn Fn(&AccountId) -> VoteWeight>
) -> u32
fn unsafe_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.
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.
fn unsafe_clear()
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.
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.