Skip to content

Commit

Permalink
ret error if UnbondingOnHoldRefCount is negative
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Aug 3, 2022
1 parent af6ee93 commit db20718
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions x/staking/keeper/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand Down Expand Up @@ -252,6 +253,14 @@ func (k Keeper) unbondingDelegationEntryCanComplete(ctx sdk.Context, id uint64)
return false, nil
}

if ubd.Entries[i].UnbondingOnHoldRefCount <= 0 {
return true,
sdkerrors.Wrapf(
types.ErrUnbondingOnHoldRefCountNegative,
"undelegation unbondingId(%d), expecting UnbondingOnHoldRefCount > 0, got %T",
id, ubd.Entries[i].UnbondingOnHoldRefCount,
)
}
ubd.Entries[i].UnbondingOnHoldRefCount--

// Check if entry is matured.
Expand Down Expand Up @@ -302,6 +311,14 @@ func (k Keeper) redelegationEntryCanComplete(ctx sdk.Context, id uint64) (found
return false, nil
}

if red.Entries[i].UnbondingOnHoldRefCount <= 0 {
return true,
sdkerrors.Wrapf(
types.ErrUnbondingOnHoldRefCountNegative,
"redelegation unbondingId(%d), expecting UnbondingOnHoldRefCount > 0, got %T",
id, red.Entries[i].UnbondingOnHoldRefCount,
)
}
red.Entries[i].UnbondingOnHoldRefCount--

if !red.Entries[i].OnHold() && red.Entries[i].IsMature(ctx.BlockHeader().Time) {
Expand Down Expand Up @@ -329,6 +346,14 @@ func (k Keeper) validatorUnbondingCanComplete(ctx sdk.Context, id uint64) (found
return false, nil
}

if val.UnbondingOnHoldRefCount <= 0 {
return true,
sdkerrors.Wrapf(
types.ErrUnbondingOnHoldRefCountNegative,
"val(%s), expecting UnbondingOnHoldRefCount > 0, got %T",
val.OperatorAddress, val.UnbondingOnHoldRefCount,
)
}
val.UnbondingOnHoldRefCount--
k.SetValidator(ctx, val)

Expand Down
1 change: 1 addition & 0 deletions x/staking/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ var (
ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 38, "no historical info found")
ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 39, "empty validator public key")
ErrUnbondingNotFound = sdkerrors.Register(ModuleName, 40, "unbonding operation not found")
ErrUnbondingOnHoldRefCountNegative = sdkerrors.Register(ModuleName, 41, "cannot un-hold unbonding operation that is not on hold")
)

0 comments on commit db20718

Please sign in to comment.