pub struct ValidatorSet { /* private fields */ }Implementations§
Source§impl ValidatorSet
impl ValidatorSet
pub fn new(validators: Vec<ValidatorInfo>) -> Self
Sourcepub fn from_signers(signers: &[&dyn Signer]) -> Self
pub fn from_signers(signers: &[&dyn Signer]) -> Self
Build a ValidatorSet from signers with equal power (1 each).
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuild the index map after deserialization.
NOTE: This is now called automatically during deserialization. You only need to call this manually if you modify the validators list directly.
pub fn validators(&self) -> &[ValidatorInfo]
pub fn total_power(&self) -> u64
Sourcepub fn quorum_threshold(&self) -> u64
pub fn quorum_threshold(&self) -> u64
Quorum threshold: ceil(2n/3) where n = total_power
Sourcepub fn max_faulty_power(&self) -> u64
pub fn max_faulty_power(&self) -> u64
Maximum faulty power: total_power - quorum_threshold
Sourcepub fn leader_for_view(&self, view: ViewNumber) -> &ValidatorInfo
pub fn leader_for_view(&self, view: ViewNumber) -> &ValidatorInfo
Round-robin leader selection: v mod n
pub fn validator_count(&self) -> usize
Sourcepub fn index_of(&self, id: ValidatorId) -> Option<usize>
pub fn index_of(&self, id: ValidatorId) -> Option<usize>
O(1) index lookup
Sourcepub fn get(&self, id: ValidatorId) -> Option<&ValidatorInfo>
pub fn get(&self, id: ValidatorId) -> Option<&ValidatorInfo>
O(1) validator info lookup
pub fn power_of(&self, id: ValidatorId) -> u64
Sourcepub fn apply_updates(&self, updates: &[ValidatorUpdate]) -> ValidatorSet
pub fn apply_updates(&self, updates: &[ValidatorUpdate]) -> ValidatorSet
Apply validator updates and return a new ValidatorSet.
power > 0: update existing validator’s power/key, or add new validatorpower == 0: remove validator
Trait Implementations§
Source§impl Clone for ValidatorSet
impl Clone for ValidatorSet
Source§fn clone(&self) -> ValidatorSet
fn clone(&self) -> ValidatorSet
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ValidatorSet
impl Debug for ValidatorSet
Source§impl<'de> Deserialize<'de> for ValidatorSet
impl<'de> Deserialize<'de> for ValidatorSet
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ValidatorSet
impl RefUnwindSafe for ValidatorSet
impl Send for ValidatorSet
impl Sync for ValidatorSet
impl Unpin for ValidatorSet
impl UnsafeUnpin for ValidatorSet
impl UnwindSafe for ValidatorSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more