diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e433b520ead..72ac3bbb7021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -180,7 +180,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking * [\#10536](https://github.com/cosmos/cosmos-sdk/pull/10536]) Enable `SetSequence` for `ModuleAccount`. -* (x/staking) [#10254](https://github.com/cosmos/cosmos-sdk/pull/10254) Instead of using the shares to determine if a delegation should be removed, use the truncated (token) amount. * (store) [#10247](https://github.com/cosmos/cosmos-sdk/pull/10247) Charge gas for the key length in gas meter. * (store) [#10218](https://github.com/cosmos/cosmos-sdk/pull/10218) Charge gas even when there are no entries while seeking. * (x/auth)[\#9596](https://github.com/cosmos/cosmos-sdk/pull/9596) Enable creating periodic vesting accounts with a transactions instead of requiring them to be created in genesis. diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 7c942aa30216..f911ce047bc3 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -680,11 +680,7 @@ func (k Keeper) Unbond( validator = k.mustGetValidator(ctx, validator.GetOperator()) } - // Remove the delegation if the resulting shares yield a truncated zero amount - // of tokens in the delegation. Note, in this this case, the shares themselves - // may not be zero, but rather a small fractional amount. Otherwise, we update - // the delegation object. - if validator.TokensFromShares(delegation.Shares).TruncateInt().IsZero() || delegation.Shares.IsZero() { + if delegation.Shares.IsZero() { err = k.RemoveDelegation(ctx, delegation) } else { k.SetDelegation(ctx, delegation) diff --git a/x/staking/migrations/v045/keys.go b/x/staking/migrations/v045/keys.go deleted file mode 100644 index 75a51df3cea7..000000000000 --- a/x/staking/migrations/v045/keys.go +++ /dev/null @@ -1,11 +0,0 @@ -package v045 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - v040staking "github.com/cosmos/cosmos-sdk/x/staking/migrations/v040" -) - -func getValidatorKey(operatorAddr sdk.ValAddress) []byte { - return append(v040staking.ValidatorsKey, address.MustLengthPrefix(operatorAddr)...) -} diff --git a/x/staking/migrations/v045/store.go b/x/staking/migrations/v045/store.go index b27d311aeab1..e8c270297ebd 100644 --- a/x/staking/migrations/v045/store.go +++ b/x/staking/migrations/v045/store.go @@ -2,66 +2,23 @@ package v045 import ( "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - v040staking "github.com/cosmos/cosmos-sdk/x/staking/migrations/v040" "github.com/cosmos/cosmos-sdk/x/staking/types" ) // MigrateStore performs in-place store migrations from v0.43/v0.44 to v0.45. // The migration includes: // -// - Removing delegations that have a zero share or token amount. // - Setting the MinCommissionRate param in the paramstore func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, paramstore paramtypes.Subspace) error { - store := ctx.KVStore(storeKey) - migrateParamsStore(ctx, paramstore) - return purgeDelegations(store, cdc) + return nil } func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { paramstore.WithKeyTable(types.ParamKeyTable()) paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) } - -func purgeDelegations(store sdk.KVStore, cdc codec.BinaryCodec) error { - prefixDelStore := prefix.NewStore(store, v040staking.DelegationKey) - - delStoreIter := prefixDelStore.Iterator(nil, nil) - defer delStoreIter.Close() - - valCache := make(map[string]v040staking.Validator) - - for ; delStoreIter.Valid(); delStoreIter.Next() { - var delegation v040staking.Delegation - if err := cdc.Unmarshal(delStoreIter.Value(), &delegation); err != nil { - return err - } - - validator, ok := valCache[delegation.ValidatorAddress] - if !ok { - valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) - if err != nil { - return err - } - - if err := cdc.Unmarshal(store.Get(getValidatorKey(valAddr)), &validator); err != nil { - return err - } - - valCache[delegation.ValidatorAddress] = validator - } - - // TODO: On-chain, we call BeforeDelegationRemoved prior to removing the - // object from state. Do we need to do the same here? - if validator.TokensFromShares(delegation.Shares).TruncateInt().IsZero() || delegation.Shares.IsZero() { - prefixDelStore.Delete(delStoreIter.Key()) - } - } - - return nil -}