From 641d946ae775febdd7e5915607d3e122ab594049 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Wed, 16 Sep 2020 20:44:15 -0400 Subject: [PATCH] [R4R] address potential panic in validator vesting (#645) * emit event instead of panic on undelegation errors --- x/validator-vesting/keeper/keeper.go | 9 ++++++++- x/validator-vesting/types/errors.go | 12 ++++++++++++ x/validator-vesting/types/events.go | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 x/validator-vesting/types/errors.go create mode 100644 x/validator-vesting/types/events.go diff --git a/x/validator-vesting/keeper/keeper.go b/x/validator-vesting/keeper/keeper.go index de51ffdf..5469578a 100644 --- a/x/validator-vesting/keeper/keeper.go +++ b/x/validator-vesting/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" "github.com/tendermint/tendermint/libs/log" @@ -185,7 +186,13 @@ func (k Keeper) HandleVestingDebt(ctx sdk.Context, addr sdk.AccAddress, blockTim k.stakingKeeper.IterateDelegations(ctx, vv.Address, func(index int64, d stakingexported.DelegationI) (stop bool) { _, err := k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares()) if err != nil { - panic(err) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeBeginBlockError, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyError, fmt.Sprintf("%s", sdkerrors.Wrapf(types.ErrFailedUndelegation, "%s", err.Error()))), + ), + ) } return false }) diff --git a/x/validator-vesting/types/errors.go b/x/validator-vesting/types/errors.go new file mode 100644 index 00000000..260080fb --- /dev/null +++ b/x/validator-vesting/types/errors.go @@ -0,0 +1,12 @@ +package types + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// DONTCOVER + +var ( + // ErrFailedUndelegation error for delegations that fail to unbond + ErrFailedUndelegation = sdkerrors.Register(ModuleName, 2, "undelegation failed") +) diff --git a/x/validator-vesting/types/events.go b/x/validator-vesting/types/events.go new file mode 100644 index 00000000..3013f870 --- /dev/null +++ b/x/validator-vesting/types/events.go @@ -0,0 +1,9 @@ +package types + +// Event types for validator vesting module +const ( + EventTypeBeginBlockError = "begin_blocker_error" + + AttributeValueCategory = "validator-vesting" + AttributeKeyError = "error_message" +)