From f4a159f42e7d5e881ffef8da916a9df1c99046fd Mon Sep 17 00:00:00 2001 From: Harish Marri Date: Sun, 24 Sep 2023 00:38:17 +0530 Subject: [PATCH] feat: update upgrade handler sdk & ibc migrations --- app/upgrades/v2/upgrades.go | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/app/upgrades/v2/upgrades.go b/app/upgrades/v2/upgrades.go index 5bee5459..3ccf5e85 100644 --- a/app/upgrades/v2/upgrades.go +++ b/app/upgrades/v2/upgrades.go @@ -3,9 +3,28 @@ package v2 import ( "github.com/OmniFlix/omniflixhub/v2/app/keepers" "github.com/OmniFlix/omniflixhub/v2/app/upgrades" + alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types" + itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types" + marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types" + onfttypes "github.com/OmniFlix/onft/types" + streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types" + "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" + 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" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" ) func CreateV2UpgradeHandler( @@ -17,12 +36,88 @@ func CreateV2UpgradeHandler( return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("running migrations ...") + // https://github.com/cosmos/cosmos-sdk/pull/12363/files + // Set param key table for params module migration + for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { + subspace := subspace + + var keyTable paramstypes.KeyTable + switch subspace.Name() { + case authtypes.ModuleName: + keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + case banktypes.ModuleName: + keyTable = banktypes.ParamKeyTable() //nolint:staticcheck + case stakingtypes.ModuleName: + keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + case minttypes.ModuleName: + keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + case slashingtypes.ModuleName: + keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + case govtypes.ModuleName: + keyTable = govv1.ParamKeyTable() //nolint:staticcheck + case crisistypes.ModuleName: + keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + + // ibc types + case ibctransfertypes.ModuleName: + keyTable = ibctransfertypes.ParamKeyTable() + case icahosttypes.SubModuleName: + keyTable = icahosttypes.ParamKeyTable() + + // omniflix + case alloctypes.ModuleName: + keyTable = alloctypes.ParamKeyTable() + case onfttypes.ModuleName: + keyTable = onfttypes.ParamKeyTable() + case marketplacetypes.ModuleName: + keyTable = marketplacetypes.ParamKeyTable() + case itctypes.ModuleName: + keyTable = itctypes.ParamKeyTable() + case streampaytypes.ModuleName: + keyTable = streampaytypes.ParamKeyTable() + default: + continue + } + + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + + // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. + // The old params module is required to still be imported in your app.go in order to handle this migration. + baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper) + // Run migrations before applying any other state changes. // NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations(). versionMap, err := mm.RunMigrations(ctx, cfg, fromVM) if err != nil { return nil, err } + + // explicitly update the IBC 02-client params, adding the localhost client type + params := keepers.IBCKeeper.ClientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, exported.Localhost) + keepers.IBCKeeper.ClientKeeper.SetParams(ctx, params) + + // set proposal's minimum initial deposit to 20% + govParams := keepers.GovKeeper.GetParams(ctx) + govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String() + if err := keepers.GovKeeper.SetParams(ctx, govParams); err != nil { + return nil, err + } + + // set validator's minimum commission to 5% + stakingParams := keepers.StakingKeeper.GetParams(ctx) + stakingParams.MinCommissionRate = sdk.NewDecWithPrec(5, 2) + err = keepers.StakingKeeper.SetParams(ctx, stakingParams) + if err != nil { + return nil, err + } + ctx.Logger().Info("Upgrade complete") return versionMap, nil }