Skip to content

Commit

Permalink
fix(upgrade): moved old params load to common flow instead of upgrade…
Browse files Browse the repository at this point in the history
… specific (#1687)
  • Loading branch information
mtsitrin authored and omritoptix committed Dec 30, 2024
1 parent 4bb5986 commit b77a9e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 80 deletions.
28 changes: 13 additions & 15 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
62 changes: 4 additions & 58 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 0 additions & 5 deletions x/sponsorship/types/params.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package types

var (
KeyMinAllocationWeight = []byte("MinAllocationWeight")
KeyMinVotingPower = []byte("MinVotingPower")
)

func DefaultParams() Params {
return Params{
MinAllocationWeight: DefaultMinAllocationWeight,
Expand Down

0 comments on commit b77a9e1

Please sign in to comment.