[R4R] address potential panic in validator vesting (#645)

* emit event instead of panic on undelegation errors
This commit is contained in:
Kevin Davis 2020-09-16 20:44:15 -04:00 committed by GitHub
parent 64aa61d285
commit 641d946ae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -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
})

View File

@ -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")
)

View File

@ -0,0 +1,9 @@
package types
// Event types for validator vesting module
const (
EventTypeBeginBlockError = "begin_blocker_error"
AttributeValueCategory = "validator-vesting"
AttributeKeyError = "error_message"
)