refactor(x/staking): return errors on Hooks calls (#19277)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
78cdf36562
commit
c3a2357d3e
@ -29,6 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* [#19277](https://github.com/cosmos/cosmos-sdk/pull/19277) Hooks calls on `SetUnbondingDelegationEntry`, `SetRedelegationEntry`, `Slash` and `RemoveValidator` returns errors instead of logging just like other hooks calls.
|
||||
* [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `IterateBondedValidatorsByPower`, `GetDelegatorBonded`, `Delegate`, `Unbond`, `Slash`, `Jail`, `SlashRedelegation`, `ApplyAndReturnValidatorSetUpdates` methods no longer panics on any kind of errors but instead returns appropriate errors.
|
||||
* [#18506](https://github.com/cosmos/cosmos-sdk/pull/18506) Detect the length of the ed25519 pubkey in CreateValidator to prevent panic.
|
||||
|
||||
|
||||
@ -338,7 +338,7 @@ func (k Keeper) SetUnbondingDelegationEntry(
|
||||
}
|
||||
|
||||
if err := k.Hooks().AfterUnbondingInitiated(ctx, id); err != nil {
|
||||
k.Logger(ctx).Error("failed to call after unbonding initiated hook", "error", err)
|
||||
return ubd, fmt.Errorf("failed to call after unbonding initiated hook: %w", err)
|
||||
}
|
||||
}
|
||||
return ubd, nil
|
||||
@ -554,8 +554,7 @@ func (k Keeper) SetRedelegationEntry(ctx context.Context,
|
||||
}
|
||||
|
||||
if err := k.Hooks().AfterUnbondingInitiated(ctx, id); err != nil {
|
||||
k.Logger(ctx).Error("failed to call after unbonding initiated hook", "error", err)
|
||||
// TODO (Facu): Should we return here? We are ignoring this error
|
||||
return types.Redelegation{}, fmt.Errorf("failed to call after unbonding initiated hook: %w", err)
|
||||
}
|
||||
|
||||
return red, nil
|
||||
|
||||
@ -76,12 +76,12 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
|
||||
operatorAddress, err := k.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
|
||||
if err != nil {
|
||||
return math.Int{}, err
|
||||
return math.NewInt(0), err
|
||||
}
|
||||
|
||||
// call the before-modification hook
|
||||
if err := k.Hooks().BeforeValidatorModified(ctx, operatorAddress); err != nil {
|
||||
k.Logger(ctx).Error("failed to call before validator modified hook", "error", err)
|
||||
return math.NewInt(0), fmt.Errorf("failed to call before validator modified hook: %w", err)
|
||||
}
|
||||
|
||||
// Track remaining slash amount for the validator
|
||||
@ -170,7 +170,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
}
|
||||
// call the before-slashed hook
|
||||
if err := k.Hooks().BeforeValidatorSlashed(ctx, operatorAddress, effectiveFraction); err != nil {
|
||||
k.Logger(ctx).Error("failed to call before validator slashed hook", "error", err)
|
||||
return math.NewInt(0), fmt.Errorf("failed to call before validator slashed hook: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -251,7 +251,7 @@ func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) err
|
||||
}
|
||||
|
||||
if err := k.Hooks().AfterValidatorRemoved(ctx, valConsAddr, str); err != nil {
|
||||
k.Logger(ctx).Error("error in after validator removed hook", "error", err)
|
||||
return fmt.Errorf("error in after validator removed hook: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user