finality_grandpa::voter_set

Struct VoterSet

Source
pub struct VoterSet<Id: Eq + Ord> { /* private fields */ }
Expand description

A (non-empty) set of voters and associated weights.

A VoterSet identifies all voters that are permitted to vote in a round of the protocol and their associated weights. A VoterSet is furthermore equipped with a total order, given by the ordering of the voter’s IDs.

Implementations§

Source§

impl<Id: Eq + Ord> VoterSet<Id>

Source

pub fn new<I>(weights: I) -> Option<Self>
where Id: Ord + Clone, I: IntoIterator<Item = (Id, u64)>,

Create a voter set from a weight distribution produced by the given iterator.

If the distribution contains multiple weights for the same voter ID, they are understood to be partial weights and are accumulated. As a result, the order in which the iterator produces the weights is irrelevant.

Returns None if the iterator does not yield a valid voter set, which is the case if it either produced no non-zero weights or, i.e. the voter set would be empty, or if the total voter weight exceeds u64::MAX.

Source

pub fn get(&self, id: &Id) -> Option<&VoterInfo>

Get the voter info for the voter with the given ID, if any.

Source

pub fn len(&self) -> NonZeroUsize

Get the size of the set.

Source

pub fn contains(&self, id: &Id) -> bool

Whether the set contains a voter with the given ID.

Source

pub fn nth_mod(&self, n: usize) -> (&Id, &VoterInfo)

Get the nth voter in the set, modulo the size of the set, as per the associated total order.

Source

pub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>

Get the nth voter in the set, if any.

Returns None if n >= len.

Source

pub fn threshold(&self) -> VoterWeight

Get the threshold vote weight required for supermajority w.r.t. this set of voters.

Source

pub fn total_weight(&self) -> VoterWeight

Get the total weight of all voters.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Id, &VoterInfo)>

Get an iterator over the voters in the set, as given by the associated total order.

Trait Implementations§

Source§

impl<Id: Clone + Eq + Ord> Clone for VoterSet<Id>

Source§

fn clone(&self) -> VoterSet<Id>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Id: Debug + Eq + Ord> Debug for VoterSet<Id>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Id: PartialEq + Eq + Ord> PartialEq for VoterSet<Id>

Source§

fn eq(&self, other: &VoterSet<Id>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Id: Eq + Eq + Ord> Eq for VoterSet<Id>

Source§

impl<Id: Eq + Ord> StructuralPartialEq for VoterSet<Id>

Auto Trait Implementations§

§

impl<Id> Freeze for VoterSet<Id>

§

impl<Id> RefUnwindSafe for VoterSet<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for VoterSet<Id>
where Id: Send,

§

impl<Id> Sync for VoterSet<Id>
where Id: Sync,

§

impl<Id> Unpin for VoterSet<Id>
where Id: Unpin,

§

impl<Id> UnwindSafe for VoterSet<Id>
where Id: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.