diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 876c9ae97df3..13884f06622c 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -70,17 +70,12 @@ type Keeper struct { LastTotalPower collections.Item[math.Int] // DelegationsByValidator key: valAddr+delAddr | value: none used (index key for delegations by validator index) DelegationsByValidator collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte] - UnbondingID collections.Sequence // ValidatorByConsensusAddress key: consAddr | value: valAddr ValidatorByConsensusAddress collections.Map[sdk.ConsAddress, sdk.ValAddress] - // UnbondingType key: unbondingID | value: index of UnbondingType - UnbondingType collections.Map[uint64, uint64] // Redelegations key: AccAddr+SrcValAddr+DstValAddr | value: Redelegation Redelegations collections.Map[collections.Triple[[]byte, []byte, []byte], types.Redelegation] // Delegations key: AccAddr+valAddr | value: Delegation Delegations collections.Map[collections.Pair[sdk.AccAddress, sdk.ValAddress], types.Delegation] - // UnbondingIndex key:UnbondingID | value: ubdKey (ubdKey = [UnbondingDelegationKey(Prefix)+len(delAddr)+delAddr+len(valAddr)+valAddr]) - UnbondingIndex collections.Map[uint64, []byte] // UnbondingQueue key: Timestamp | value: DVPairs [delAddr+valAddr] UnbondingQueue collections.Map[time.Time, types.DVPairs] // Validators key: valAddr | value: Validator @@ -178,14 +173,12 @@ func NewKeeper( ), collections.BytesValue, ), - UnbondingID: collections.NewSequence(sb, types.UnbondingIDKey, "unbonding_id"), ValidatorByConsensusAddress: collections.NewMap( sb, types.ValidatorsByConsAddrKey, "validator_by_cons_addr", sdk.LengthPrefixedAddressKey(sdk.ConsAddressKey).WithName("cons_address"), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility collcodec.KeyToValueCodec(sdk.ValAddressKey), ), - UnbondingType: collections.NewMap(sb, types.UnbondingTypeKey, "unbonding_type", collections.Uint64Key.WithName("unbonding_id"), collections.Uint64Value), // key format is: 52 | lengthPrefixedBytes(AccAddr) | lengthPrefixedBytes(SrcValAddr) | lengthPrefixedBytes(DstValAddr) Redelegations: collections.NewMap( sb, types.RedelegationKey, @@ -200,7 +193,6 @@ func NewKeeper( ), codec.CollValue[types.Redelegation](cdc), ), - UnbondingIndex: collections.NewMap(sb, types.UnbondingIndexKey, "unbonding_index", collections.Uint64Key.WithName("index"), collections.BytesValue.WithName("ubd_key")), UnbondingDelegationByValIndex: collections.NewMap( sb, types.UnbondingDelegationByValIndexKey, "unbonding_delegation_by_val_index", diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index ef758090d359..f3bcfd9acd74 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -545,9 +545,16 @@ func (k Keeper) unbondMatureValidators( return errors.New("unexpected validator in unbonding queue; status was not unbonding") } - val = k.UnbondingToUnbonded(ctx, val) + val, err = k.UnbondingToUnbonded(ctx, val) + if err != nil { + return err + } if val.GetDelegatorShares().IsZero() { - k.RemoveValidator(ctx, val.GetOperator()) + addr, err := k.validatorAddressCodec.StringToBytes(val.OperatorAddress) + if err != nil { + return err + } + k.RemoveValidator(ctx, addr) } } return nil diff --git a/x/staking/migrations/v6/keys.go b/x/staking/migrations/v6/keys.go index 252d7ce50396..5c3b1a913350 100644 --- a/x/staking/migrations/v6/keys.go +++ b/x/staking/migrations/v6/keys.go @@ -3,6 +3,9 @@ package v6 import "cosmossdk.io/collections" var ( + UnbondingTypeKey = collections.NewPrefix(57) // prefix for an index containing the type of unbonding operations + UnbondingIDKey = collections.NewPrefix(55) // key for the counter for the incrementing id for UnbondingOperations + UnbondingIndexKey = collections.NewPrefix(56) // prefix for an index for looking up unbonding operations by their IDs ValidatorUpdatesKey = collections.NewPrefix(97) HistoricalInfoKey = collections.NewPrefix(80) // prefix for the historical info ) diff --git a/x/staking/migrations/v6/store.go b/x/staking/migrations/v6/store.go index 93de43ec51fa..98b4cb446faa 100644 --- a/x/staking/migrations/v6/store.go +++ b/x/staking/migrations/v6/store.go @@ -13,5 +13,8 @@ import ( func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error { store.Delete(ValidatorUpdatesKey) store.Delete(HistoricalInfoKey) + store.Delete(UnbondingIDKey) + store.Delete(UnbondingIndexKey) + store.Delete(UnbondingTypeKey) return nil } diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 03335a9a8372..7228716a7700 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -49,10 +49,6 @@ var ( RedelegationByValSrcIndexKey = collections.NewPrefix(53) // prefix for each key for a redelegation, by source validator operator RedelegationByValDstIndexKey = collections.NewPrefix(54) // prefix for each key for a redelegation, by destination validator operator - UnbondingIDKey = collections.NewPrefix(55) // key for the counter for the incrementing id for UnbondingOperations - UnbondingIndexKey = collections.NewPrefix(56) // prefix for an index for looking up unbonding operations by their IDs - UnbondingTypeKey = collections.NewPrefix(57) // prefix for an index containing the type of unbonding operations - UnbondingQueueKey = collections.NewPrefix(65) // prefix for the timestamps in unbonding queue RedelegationQueueKey = collections.NewPrefix(66) // prefix for the timestamps in redelegations queue ValidatorQueueKey = collections.NewPrefix(67) // prefix for the timestamps in validator queue