Skip to content

Commit

Permalink
feat: update upgrade handler sdk & ibc migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Sep 23, 2023
1 parent 1d87a6a commit f4a159f
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
Expand Down

0 comments on commit f4a159f

Please sign in to comment.