refactor: revert 10254 (#10777)
## Description Revert #10254 Closes: #10750 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
6f58963e7f
commit
45cad1df0a
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)...)
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue