-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/tx-fees-null-guard
- Loading branch information
Showing
9 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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" | ||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/migrations/v040" | ||
) | ||
|
||
// 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. | ||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { | ||
store := ctx.KVStore(storeKey) | ||
|
||
return purgeDelegations(store, cdc) | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters