Struct finality_grandpa::voter_set::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>
impl<Id: Eq + Ord> VoterSet<Id>
sourcepub fn new<I>(weights: I) -> Option<Self>where
Id: Ord + Clone,
I: IntoIterator<Item = (Id, u64)>,
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
.
sourcepub fn get(&self, id: &Id) -> Option<&VoterInfo>
pub fn get(&self, id: &Id) -> Option<&VoterInfo>
Get the voter info for the voter with the given ID, if any.
sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Get the size of the set.
sourcepub fn nth_mod(&self, n: usize) -> (&Id, &VoterInfo)
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.
sourcepub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>
pub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>
Get the nth voter in the set, if any.
Returns None
if n >= len
.
sourcepub fn threshold(&self) -> VoterWeight
pub fn threshold(&self) -> VoterWeight
Get the threshold vote weight required for supermajority w.r.t. this set of voters.
sourcepub fn total_weight(&self) -> VoterWeight
pub fn total_weight(&self) -> VoterWeight
Get the total weight of all voters.