From 5ce245c1eddcbbe150ce2db97ce6cfcde936a35e Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:40:38 +0200 Subject: [PATCH] fix(upgrade): moved old params load to common flow instead of upgrade specific (#1687) --- app/keepers/keepers.go | 28 ++++++++-------- app/keepers/modules.go | 4 +-- app/upgrades/v4/upgrade.go | 62 +++-------------------------------- x/sponsorship/types/params.go | 5 --- 4 files changed, 19 insertions(+), 80 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 4afd30ba2..2d87508a3 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -661,34 +661,32 @@ func (a *AppKeepers) GetStakingKeeper() ibctestingtypes.StakingKeeper { func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - paramsKeeper.Subspace(authtypes.ModuleName) - paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(minttypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) + // deprecated subspaces. loaded manually as the keeper doens't load it + paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable()) + paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable()) + paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) + paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) + paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) + paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) + paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(rollappmoduletypes.ModuleName) - paramsKeeper.Subspace(sequencermoduletypes.ModuleName) - paramsKeeper.Subspace(sponsorshiptypes.ModuleName) paramsKeeper.Subspace(streamermoduletypes.ModuleName) - paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName) paramsKeeper.Subspace(delayedacktypes.ModuleName) paramsKeeper.Subspace(eibcmoduletypes.ModuleName) paramsKeeper.Subspace(dymnstypes.ModuleName) - paramsKeeper.Subspace(grouptypes.ModuleName) - // ethermint subspaces - paramsKeeper.Subspace(evmtypes.ModuleName) - paramsKeeper.Subspace(feemarkettypes.ModuleName) + // ethermint subspaces (keeper doesn't load key table so we do it manually) + paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) + paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable()) // osmosis subspaces paramsKeeper.Subspace(lockuptypes.ModuleName) - paramsKeeper.Subspace(epochstypes.ModuleName) paramsKeeper.Subspace(gammtypes.ModuleName) paramsKeeper.Subspace(incentivestypes.ModuleName) paramsKeeper.Subspace(txfeestypes.ModuleName) diff --git a/app/keepers/modules.go b/app/keepers/modules.go index 83d894504..89f5f133d 100644 --- a/app/keepers/modules.go +++ b/app/keepers/modules.go @@ -217,8 +217,8 @@ func (a *AppKeepers) SetupModules( groupmodule.NewAppModule(appCodec, a.GroupKeeper, a.AccountKeeper, a.BankKeeper, encodingConfig.InterfaceRegistry), // Ethermint app modules - evm.NewAppModule(a.EvmKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())), - feemarket.NewAppModule(a.FeeMarketKeeper, a.GetSubspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())), + evm.NewAppModule(a.EvmKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(evmtypes.ModuleName)), + feemarket.NewAppModule(a.FeeMarketKeeper, a.GetSubspace(feemarkettypes.ModuleName)), // osmosis modules lockup.NewAppModule(*a.LockupKeeper), diff --git a/app/upgrades/v4/upgrade.go b/app/upgrades/v4/upgrade.go index dff708e69..feec90071 100644 --- a/app/upgrades/v4/upgrade.go +++ b/app/upgrades/v4/upgrade.go @@ -11,22 +11,10 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibcchannelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper" - evmtypes "github.com/evmos/ethermint/x/evm/types" - feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper" "github.com/dymensionxyz/dymension/v3/app/keepers" @@ -55,8 +43,6 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) - setKeyTables(keepers) - // Run migrations before applying any other state changes. // NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations(). // (This is how osmosis do it) @@ -121,53 +107,13 @@ func CreateUpgradeHandler( } } -func setKeyTables(keepers *keepers.AppKeepers) { - for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { - var keyTable paramstypes.KeyTable - switch subspace.Name() { - // Cosmos SDK modules - case authtypes.ModuleName: - keyTable = authtypes.ParamKeyTable() - case banktypes.ModuleName: - keyTable = banktypes.ParamKeyTable() - case stakingtypes.ModuleName: - keyTable = stakingtypes.ParamKeyTable() - case minttypes.ModuleName: - keyTable = minttypes.ParamKeyTable() - case distrtypes.ModuleName: - keyTable = distrtypes.ParamKeyTable() - case slashingtypes.ModuleName: - keyTable = slashingtypes.ParamKeyTable() - case govtypes.ModuleName: - keyTable = govv1.ParamKeyTable() - case crisistypes.ModuleName: - keyTable = crisistypes.ParamKeyTable() - - // Dymension modules - case rollapptypes.ModuleName: - keyTable = rollapptypes.ParamKeyTable() - case sequencertypes.ModuleName: - continue - - // Ethermint modules - case evmtypes.ModuleName: - keyTable = evmtypes.ParamKeyTable() - case feemarkettypes.ModuleName: - keyTable = feemarkettypes.ParamKeyTable() - default: - continue - } - - if !subspace.HasKeyTable() { - subspace.WithKeyTable(keyTable) - } - } -} - //nolint:staticcheck - note this is a cosmos SDK supplied function specifically for upgrading consensus params func migrateModuleParams(ctx sdk.Context, keepers *keepers.AppKeepers) { // Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module. - baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseAppLegacySS, ok := keepers.ParamsKeeper.GetSubspace(baseapp.Paramspace) + if !ok { + panic("failed to get consensus params subspace from params keeper") + } baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper) } diff --git a/x/sponsorship/types/params.go b/x/sponsorship/types/params.go index 1109e58e0..7fd221863 100644 --- a/x/sponsorship/types/params.go +++ b/x/sponsorship/types/params.go @@ -1,10 +1,5 @@ package types -var ( - KeyMinAllocationWeight = []byte("MinAllocationWeight") - KeyMinVotingPower = []byte("MinVotingPower") -) - func DefaultParams() Params { return Params{ MinAllocationWeight: DefaultMinAllocationWeight,