diff --git a/x/staking/CHANGELOG.md b/x/staking/CHANGELOG.md index fcd621d9b544..34f2a5ac3a18 100644 --- a/x/staking/CHANGELOG.md +++ b/x/staking/CHANGELOG.md @@ -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. diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 651cc6310b62..a092ed3068b8 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -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 diff --git a/x/staking/keeper/slash.go b/x/staking/keeper/slash.go index 17d07a8da57a..9a5b5e406407 100644 --- a/x/staking/keeper/slash.go +++ b/x/staking/keeper/slash.go @@ -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) } } diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index b62403d1003c..1a222b2cb4b4 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -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