mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
[R4R] address potential panic in validator vesting (#645)
* emit event instead of panic on undelegation errors
This commit is contained in:
parent
64aa61d285
commit
641d946ae7
@ -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
|
||||
})
|
||||
|
12
x/validator-vesting/types/errors.go
Normal file
12
x/validator-vesting/types/errors.go
Normal 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")
|
||||
)
|
9
x/validator-vesting/types/events.go
Normal file
9
x/validator-vesting/types/events.go
Normal file
@ -0,0 +1,9 @@
|
||||
package types
|
||||
|
||||
// Event types for validator vesting module
|
||||
const (
|
||||
EventTypeBeginBlockError = "begin_blocker_error"
|
||||
|
||||
AttributeValueCategory = "validator-vesting"
|
||||
AttributeKeyError = "error_message"
|
||||
)
|
Loading…
Reference in New Issue
Block a user