Skip to main content

StakingManager

Struct StakingManager 

Source
pub struct StakingManager<S: StakingStore> { /* private fields */ }
Expand description

Central staking manager that operates on any StakingStore backend.

Use this inside your [Application::execute_block] to process staking transactions, distribute rewards, apply slashing, and compute validator set updates for epoch transitions.

Implementations§

Source§

impl<S: StakingStore> StakingManager<S>

Source

pub fn new(store: S, config: StakingConfig) -> Self

Source

pub fn config(&self) -> &StakingConfig

Source

pub fn store(&self) -> &S

Source

pub fn store_mut(&mut self) -> &mut S

Source

pub fn register_validator( &mut self, id: ValidatorId, pubkey: PublicKey, self_stake: u64, ) -> Result<()>

Register a new validator with an initial self-stake.

Source

pub fn unregister_validator(&mut self, id: ValidatorId) -> Result<u64>

Remove a validator from the staking system entirely. All delegated stakes are returned (caller handles balance credits).

Source

pub fn delegate( &mut self, staker: &[u8], validator: ValidatorId, amount: u64, ) -> Result<()>

Delegate amount from staker to validator.

Source

pub fn undelegate( &mut self, staker: &[u8], validator: ValidatorId, amount: u64, current_height: u64, ) -> Result<()>

Undelegate amount from staker’s delegation to validator.

Voting power is reduced immediately. If unbonding_period > 0, the tokens are locked in an unbonding queue and released only after [process_unbonding] is called at or after current_height + unbonding_period.

Source

pub fn process_unbonding(&mut self, current_height: u64) -> Vec<UnbondingEntry>

Process mature unbondings whose lock period has elapsed.

Returns the completed entries so the application can credit the released tokens to the stakers’ balances.

Source

pub fn slash( &mut self, id: ValidatorId, reason: SlashReason, current_height: u64, ) -> Result<SlashResult>

Slash a validator for misbehavior.

Reduces self-stake and delegated stakes proportionally, jails the validator, and returns the total slashed amount.

Source

pub fn unjail(&mut self, id: ValidatorId, current_height: u64) -> Result<()>

Unjail a validator if the jail period has passed.

Source

pub fn increment_score(&mut self, id: ValidatorId, delta: u32)

Increase a validator’s reputation score.

Source

pub fn decrement_score(&mut self, id: ValidatorId, delta: u32)

Decrease a validator’s reputation score.

Source

pub fn reward_proposer(&mut self, proposer: ValidatorId) -> Result<u64>

Add the configured block reward to the proposer’s self-stake. Returns the reward amount.

Source

pub fn get_validator(&self, id: ValidatorId) -> Option<ValidatorState>

Source

pub fn voting_power(&self, id: ValidatorId) -> u64

Source

pub fn total_staked(&self) -> u64

Source

pub fn formal_validator_list(&self) -> Vec<ValidatorState>

Return the top max_validators validators sorted by voting power (descending). Jailed validators are excluded.

Source

pub fn compute_validator_updates( &self, current_set: &ValidatorSet, ) -> Vec<ValidatorUpdate>

Compare current staking state against the active ValidatorSet and produce the list of ValidatorUpdates needed to synchronize them.

This is intended to be called at the end of execute_block and returned in [EndBlockResponse::validator_updates].

Auto Trait Implementations§

§

impl<S> Freeze for StakingManager<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for StakingManager<S>
where S: RefUnwindSafe,

§

impl<S> Send for StakingManager<S>
where S: Send,

§

impl<S> Sync for StakingManager<S>
where S: Sync,

§

impl<S> Unpin for StakingManager<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for StakingManager<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for StakingManager<S>
where S: 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> 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, 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.