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>
impl<S: StakingStore> StakingManager<S>
pub fn new(store: S, config: StakingConfig) -> Self
pub fn config(&self) -> &StakingConfig
pub fn store(&self) -> &S
pub fn store_mut(&mut self) -> &mut S
Sourcepub fn register_validator(
&mut self,
id: ValidatorId,
pubkey: PublicKey,
self_stake: u64,
) -> Result<()>
pub fn register_validator( &mut self, id: ValidatorId, pubkey: PublicKey, self_stake: u64, ) -> Result<()>
Register a new validator with an initial self-stake.
Sourcepub fn unregister_validator(&mut self, id: ValidatorId) -> Result<u64>
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).
Sourcepub fn delegate(
&mut self,
staker: &[u8],
validator: ValidatorId,
amount: u64,
) -> Result<()>
pub fn delegate( &mut self, staker: &[u8], validator: ValidatorId, amount: u64, ) -> Result<()>
Delegate amount from staker to validator.
Sourcepub fn undelegate(
&mut self,
staker: &[u8],
validator: ValidatorId,
amount: u64,
current_height: u64,
) -> Result<()>
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.
Sourcepub fn process_unbonding(&mut self, current_height: u64) -> Vec<UnbondingEntry>
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.
Sourcepub fn slash(
&mut self,
id: ValidatorId,
reason: SlashReason,
current_height: u64,
) -> Result<SlashResult>
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.
Sourcepub fn unjail(&mut self, id: ValidatorId, current_height: u64) -> Result<()>
pub fn unjail(&mut self, id: ValidatorId, current_height: u64) -> Result<()>
Unjail a validator if the jail period has passed.
Sourcepub fn increment_score(&mut self, id: ValidatorId, delta: u32)
pub fn increment_score(&mut self, id: ValidatorId, delta: u32)
Increase a validator’s reputation score.
Sourcepub fn decrement_score(&mut self, id: ValidatorId, delta: u32)
pub fn decrement_score(&mut self, id: ValidatorId, delta: u32)
Decrease a validator’s reputation score.
Sourcepub fn reward_proposer(&mut self, proposer: ValidatorId) -> Result<u64>
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.
pub fn get_validator(&self, id: ValidatorId) -> Option<ValidatorState>
pub fn voting_power(&self, id: ValidatorId) -> u64
pub fn total_staked(&self) -> u64
Sourcepub fn formal_validator_list(&self) -> Vec<ValidatorState>
pub fn formal_validator_list(&self) -> Vec<ValidatorState>
Return the top max_validators validators sorted by voting power (descending).
Jailed validators are excluded.
Sourcepub fn compute_validator_updates(
&self,
current_set: &ValidatorSet,
) -> Vec<ValidatorUpdate>
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].