pub enum ValidatorStake {
V1(ValidatorStakeV1),
}
Expand description
Stores validator and its stake.
Variants§
Implementations§
source§impl ValidatorStake
impl ValidatorStake
pub fn new_v1( account_id: AccountId, public_key: PublicKey, stake: Balance ) -> Self
pub fn new(account_id: AccountId, public_key: PublicKey, stake: Balance) -> Self
pub fn into_v1(self) -> ValidatorStakeV1
pub fn account_and_stake(self) -> (AccountId, Balance)
pub fn destructure(self) -> (AccountId, PublicKey, Balance)
pub fn take_account_id(self) -> AccountId
pub fn account_id(&self) -> &AccountId
pub fn take_public_key(self) -> PublicKey
pub fn public_key(&self) -> &PublicKey
pub fn stake(&self) -> Balance
pub fn stake_mut(&mut self) -> &mut Balance
pub fn get_approval_stake(&self, is_next_epoch: bool) -> ApprovalStake
sourcepub fn num_mandates(&self, stake_per_mandate: Balance) -> u16
pub fn num_mandates(&self, stake_per_mandate: Balance) -> u16
Returns the validator’s number of mandates (rounded down) at stake_per_seat
.
It returns u16
since it allows infallible conversion to usize
and with u16::MAX
equalling 65_535 it should be sufficient to hold the number of mandates per validator.
§Why u16
should be sufficient
As of October 2023, a recommended lower bound for the stake required per mandate is
25k $NEAR. At this price, the validator with highest stake would have 1_888 mandates,
which is well below u16::MAX
.
From another point of view, with more than u16::MAX
mandates for validators, sampling
mandates might become computationally too expensive. This might trigger an increase in
the required stake per mandate, bringing down the number of mandates per validator.
§Panics
Panics if the number of mandates overflows u16
.
sourcepub fn partial_mandate_weight(&self, stake_per_mandate: Balance) -> Balance
pub fn partial_mandate_weight(&self, stake_per_mandate: Balance) -> Balance
Returns the weight attributed to the validator’s partial mandate.
A validator has a partial mandate if its stake cannot be divided evenly by
stake_per_mandate
. The remainder of that division is the weight of the partial
mandate.
Due to this definintion a validator has exactly one partial mandate with 0 <= weight < stake_per_mandate
.
§Example
Let V
be a validator with stake of 12. If stake_per_mandate
equals 5 then the weight
of V
’s partial mandate is 12 % 5 = 2
.
Trait Implementations§
source§impl BorshDeserialize for ValidatorStake
impl BorshDeserialize for ValidatorStake
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl BorshSerialize for ValidatorStake
impl BorshSerialize for ValidatorStake
source§impl Clone for ValidatorStake
impl Clone for ValidatorStake
source§fn clone(&self) -> ValidatorStake
fn clone(&self) -> ValidatorStake
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ValidatorStake
impl Debug for ValidatorStake
source§impl EnumExt for ValidatorStake
impl EnumExt for ValidatorStake
source§impl From<ValidatorStake> for ValidatorStakeView
impl From<ValidatorStake> for ValidatorStakeView
source§fn from(stake: ValidatorStake) -> Self
fn from(stake: ValidatorStake) -> Self
source§impl From<ValidatorStakeView> for ValidatorStake
impl From<ValidatorStakeView> for ValidatorStake
source§fn from(view: ValidatorStakeView) -> Self
fn from(view: ValidatorStakeView) -> Self
source§impl PartialEq for ValidatorStake
impl PartialEq for ValidatorStake
source§fn eq(&self, other: &ValidatorStake) -> bool
fn eq(&self, other: &ValidatorStake) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for ValidatorStake
impl Serialize for ValidatorStake
impl Eq for ValidatorStake
impl StructuralPartialEq for ValidatorStake
Auto Trait Implementations§
impl Freeze for ValidatorStake
impl RefUnwindSafe for ValidatorStake
impl Send for ValidatorStake
impl Sync for ValidatorStake
impl Unpin for ValidatorStake
impl UnwindSafe for ValidatorStake
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
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
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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