Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com>
This commit is contained in:
parent
18733a684e
commit
d9d9a52221
@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (x/staking/keeper) [#]18049(https://github.com/cosmos/cosmos-sdk/pull/18049) return early if Slash encounters zero tokens to burn.
|
||||
* (x/staking/keeper) [#18035](https://github.com/cosmos/cosmos-sdk/pull/18035) Hoisted out of the redelegation loop, the non-changing validator and delegator addresses parsing.
|
||||
* (keyring) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) Add `NewAutoCLIKeyring` for creating an AutoCLI keyring from a SDK keyring.
|
||||
* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) Let `ToProtoConsensusParams()` return an error.
|
||||
|
||||
@ -145,12 +145,26 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
tokensToBurn := math.MinInt(remainingSlashAmount, validator.Tokens)
|
||||
tokensToBurn = math.MaxInt(tokensToBurn, math.ZeroInt()) // defensive.
|
||||
|
||||
if tokensToBurn.IsZero() {
|
||||
// Nothing to burn, we can end this route immediately! We also don't
|
||||
// need to call the k.Hooks().BeforeValidatorSlashed hook as we won't
|
||||
// be slashing at all.
|
||||
logger.Info(
|
||||
"no validator slashing because slash amount is zero",
|
||||
"validator", validator.GetOperator(),
|
||||
"slash_factor", slashFactor.String(),
|
||||
"burned", tokensToBurn,
|
||||
"validatorTokens", validator.Tokens,
|
||||
)
|
||||
return math.NewInt(0), nil
|
||||
}
|
||||
|
||||
// we need to calculate the *effective* slash fraction for distribution
|
||||
if validator.Tokens.IsPositive() {
|
||||
effectiveFraction := math.LegacyNewDecFromInt(tokensToBurn).QuoRoundUp(math.LegacyNewDecFromInt(validator.Tokens))
|
||||
// possible if power has changed
|
||||
if effectiveFraction.GT(math.LegacyOneDec()) {
|
||||
effectiveFraction = math.LegacyOneDec()
|
||||
if oneDec := math.LegacyOneDec(); effectiveFraction.GT(oneDec) {
|
||||
effectiveFraction = oneDec
|
||||
}
|
||||
// call the before-slashed hook
|
||||
if err := k.Hooks().BeforeValidatorSlashed(ctx, operatorAddress, effectiveFraction); err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user