From c2114c0abb99bc872e8cb1e6231717a0ca1207be Mon Sep 17 00:00:00 2001 From: Dreamer Date: Wed, 20 Mar 2024 13:50:40 +0800 Subject: [PATCH] when adjusting the upgrade, load the parameters of the ica module --- app/upgrades/v300/constants.go | 41 +--------------------------------- app/upgrades/v300/lsm.go | 30 +++++++++++++------------ app/upgrades/v300/upgrades.go | 10 +++++---- 3 files changed, 23 insertions(+), 58 deletions(-) diff --git a/app/upgrades/v300/constants.go b/app/upgrades/v300/constants.go index b2cac0c83..afb13b632 100644 --- a/app/upgrades/v300/constants.go +++ b/app/upgrades/v300/constants.go @@ -16,44 +16,5 @@ var ( // the portion of a chain's total stake can be liquid GlobalLiquidStakingCap = sdk.MustNewDecFromStr("0.25") // 25% - allowMessages = []string{ - "/cosmos.authz.v1beta1.MsgExec", - "/cosmos.authz.v1beta1.MsgGrant", - "/cosmos.authz.v1beta1.MsgRevoke", - "/cosmos.bank.v1beta1.MsgSend", - "/cosmos.bank.v1beta1.MsgMultiSend", - "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", - "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", - "/cosmos.distribution.v1beta1.MsgFundCommunityPool", - "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", - "/cosmos.feegrant.v1beta1.MsgGrantAllowance", - "/cosmos.feegrant.v1beta1.MsgRevokeAllowance", - "/cosmos.gov.v1beta1.MsgVoteWeighted", - "/cosmos.gov.v1beta1.MsgSubmitProposal", - "/cosmos.gov.v1beta1.MsgDeposit", - "/cosmos.gov.v1beta1.MsgVote", - "/cosmos.gov.v1.MsgVoteWeighted", - "/cosmos.gov.v1.MsgSubmitProposal", - "/cosmos.gov.v1.MsgDeposit", - "/cosmos.gov.v1.MsgVote", - "/cosmos.staking.v1beta1.MsgEditValidator", - "/cosmos.staking.v1beta1.MsgDelegate", - "/cosmos.staking.v1beta1.MsgUndelegate", - "/cosmos.staking.v1beta1.MsgBeginRedelegate", - "/cosmos.staking.v1beta1.MsgCreateValidator", - "/cosmos.vesting.v1beta1.MsgCreateVestingAccount", - "/ibc.applications.transfer.v1.MsgTransfer", - "/irismod.nft.MsgIssueDenom", - "/irismod.nft.MsgTransferDenom", - "/irismod.nft.MsgMintNFT", - "/irismod.nft.MsgEditNFT", - "/irismod.nft.MsgTransferNFT", - "/irismod.nft.MsgBurnNFT", - "/irismod.mt.MsgIssueDenom", - "/irismod.mt.MsgTransferDenom", - "/irismod.mt.MsgMintMT", - "/irismod.mt.MsgEditMT", - "/irismod.mt.MsgTransferMT", - "/irismod.mt.MsgBurnMT", - } + allowMessages = []string{"*"} ) diff --git a/app/upgrades/v300/lsm.go b/app/upgrades/v300/lsm.go index 19d70e478..8f550991d 100644 --- a/app/upgrades/v300/lsm.go +++ b/app/upgrades/v300/lsm.go @@ -21,20 +21,20 @@ type keeper interface { SetParams(ctx sdk.Context, params types.Params) error } -// MigrateParamsStore migrates the params store to the latest version. +// migrateParamsStore migrates the params store to the latest version. // // ctx - sdk context // k - keeper -func MigrateParamsStore(ctx sdk.Context, k keeper) { +func migrateParamsStore(ctx sdk.Context, k keeper) error { params := k.GetParams(ctx) params.ValidatorBondFactor = ValidatorBondFactor params.ValidatorLiquidStakingCap = ValidatorLiquidStakingCap params.GlobalLiquidStakingCap = GlobalLiquidStakingCap - k.SetParams(ctx, params) + return k.SetParams(ctx, params) } -// MigrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0 -func MigrateValidators(ctx sdk.Context, k keeper) { +// migrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0 +func migrateValidators(ctx sdk.Context, k keeper) { for _, validator := range k.GetAllValidators(ctx) { validator.ValidatorBondShares = sdk.ZeroDec() validator.LiquidShares = sdk.ZeroDec() @@ -42,8 +42,8 @@ func MigrateValidators(ctx sdk.Context, k keeper) { } } -// MigrateDelegations Set each delegation's ValidatorBond field to false -func MigrateDelegations(ctx sdk.Context, k keeper) { +// migrateDelegations Set each delegation's ValidatorBond field to false +func migrateDelegations(ctx sdk.Context, k keeper) { for _, delegation := range k.GetAllDelegations(ctx) { delegation.ValidatorBond = false k.SetDelegation(ctx, delegation) @@ -52,7 +52,7 @@ func MigrateDelegations(ctx sdk.Context, k keeper) { // MigrateUBDEntries will remove the ubdEntries with same creation_height // and create a new ubdEntry with updated balance and initial_balance -func MigrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error { +func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error { iterator := sdk.KVStorePrefixIterator(store, types.UnbondingDelegationKey) defer iterator.Close() @@ -108,25 +108,27 @@ func setUBDToStore(_ sdk.Context, store storetypes.KVStore, cdc codec.BinaryCode store.Set(key, bz) } -// MigrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including: +// migrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including: // - Adding params ValidatorBondFactor, GlobalLiquidStakingCap, ValidatorLiquidStakingCap // - Setting each validator's ValidatorBondShares and LiquidShares to 0 // - Setting each delegation's ValidatorBond field to false // - Calculating the total liquid staked by summing the delegations from ICA accounts -func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error { +func migrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error { store := ctx.KVStore(storeKey) ctx.Logger().Info("Staking LSM Migration: Migrating param store") - MigrateParamsStore(ctx, k) + if err := migrateParamsStore(ctx, k); err != nil { + return err + } ctx.Logger().Info("Staking LSM Migration: Migrating validators") - MigrateValidators(ctx, k) + migrateValidators(ctx, k) ctx.Logger().Info("Staking LSM Migration: Migrating delegations") - MigrateDelegations(ctx, k) + migrateDelegations(ctx, k) ctx.Logger().Info("Staking LSM Migration: Migrating UBD entries") - if err := MigrateUBDEntries(ctx, store, cdc); err != nil { + if err := migrateUBDEntries(ctx, store, cdc); err != nil { return err } diff --git a/app/upgrades/v300/upgrades.go b/app/upgrades/v300/upgrades.go index d20cad437..6659f048f 100644 --- a/app/upgrades/v300/upgrades.go +++ b/app/upgrades/v300/upgrades.go @@ -17,7 +17,7 @@ import ( // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal var Upgrade = upgrades.Upgrade{ - UpgradeName: "v3.0", + UpgradeName: "v3", UpgradeHandlerConstructor: upgradeHandlerConstructor, StoreUpgrades: &storetypes.StoreUpgrades{ Added: []string{icahosttypes.StoreKey}, @@ -34,7 +34,9 @@ func upgradeHandlerConstructor( initICAModule(ctx, m, fromVM) // merge liquid staking module - mergeLSModule(ctx, box) + if err := mergeLSModule(ctx, box); err != nil { + return nil, err + } return box.ModuleManager.RunMigrations(ctx, c, fromVM) } } @@ -52,9 +54,9 @@ func initICAModule(ctx sdk.Context, m *module.Manager, fromVM module.VersionMap) icaModule.InitModule(ctx, controllerParams, hostParams) } -func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) { +func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) error { ctx.Logger().Info("start to run lsm module migrations...") storeKey := box.GetKey(stakingtypes.StoreKey) - MigrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper) + return migrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper) }