Created
January 23, 2024 17:55
-
-
Save erwanor/9d8411d47298ba5ef1b959b89ab51f40 to your computer and use it in GitHub Desktop.
Unbonding excerpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn unbonding_end_epoch_for( | |
&self, | |
id: &IdentityKey, | |
start_epoch_index: u64, | |
) -> Result<u64> { | |
let unbonding_epochs = self.get_stake_params().await?.unbonding_epochs; | |
let default_unbonding = start_epoch_index + unbonding_epochs; | |
let validator_unbonding = | |
if let Some(validator::BondingState::Unbonding { unbonding_epoch }) = | |
self.validator_bonding_state(id).await? | |
{ | |
unbonding_epoch | |
} else { | |
u64::MAX | |
}; | |
Ok(std::cmp::min(default_unbonding, validator_unbonding)) | |
} | |
/// Return the epoch index at which the validator will be unbonded. | |
/// This is the minimum of the default unbonding epoch and the validator's | |
/// unbonding epoch. | |
async fn current_unbonding_end_epoch_for(&self, id: &IdentityKey) -> Result<u64> { | |
let current_epoch = self.get_current_epoch().await?; | |
let unbonding_epochs = self.get_stake_params().await?.unbonding_epochs; | |
let default_unbonding = current_epoch.index + unbonding_epochs; | |
let validator_unbonding = | |
if let Some(validator::BondingState::Unbonding { unbonding_epoch }) = | |
self.validator_bonding_state(id).await? | |
{ | |
unbonding_epoch | |
} else { | |
u64::MAX | |
}; | |
Ok(std::cmp::min(default_unbonding, validator_unbonding)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment