Skip to content

Commit

Permalink
Add params migration logic to v1.15 upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
iKapitonau committed Sep 6, 2024
1 parent 5e0754a commit 28f85a6
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion app/upgrades/v1.15/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ import (
"cosmossdk.io/log"
store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/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"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/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"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"

Check failure on line 28 in app/upgrades/v1.15/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" is deprecated: The legacy v1beta1 gov types maintained in this file are deprecated and will be removed in a future release. Please use MsgIBCSoftwareUpgrade and MsgRecoverClient in favour of the legacy v1beta1 gov proposal types. (staticcheck)
ibcconntypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

"github.com/scrtlabs/SecretNetwork/app/keepers"
"github.com/scrtlabs/SecretNetwork/app/upgrades"
)
Expand All @@ -30,7 +47,7 @@ var Upgrade = upgrades.Upgrade{
},
}

func createUpgradeHandler(mm *module.Manager, _ *keepers.SecretAppKeepers, configurator module.Configurator,
func createUpgradeHandler(mm *module.Manager, appKeepers *keepers.SecretAppKeepers, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := log.NewLogger(os.Stderr)
Expand All @@ -41,6 +58,49 @@ func createUpgradeHandler(mm *module.Manager, _ *keepers.SecretAppKeepers, confi
logger.Info(`| |__| | | | |__| | | \ \ / ____ \| |__| | |____ `)
logger.Info(` \____/|_| \_____|_| \_\/_/ \_\_____/|______|`)

// Set param key table for params module migration
for _, subspace := range appKeepers.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
case ibcexported.ModuleName:
keyTable = ibcclienttypes.ParamKeyTable() //nolint:staticcheck

Check failure on line 84 in app/upgrades/v1.15/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:staticcheck` is unused for linter "staticcheck" (nolintlint)
keyTable.RegisterParamSet(&ibcconntypes.Params{})
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck

Check failure on line 87 in app/upgrades/v1.15/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:staticcheck` is unused for linter "staticcheck" (nolintlint)
case icacontrollertypes.SubModuleName:
keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck

Check failure on line 89 in app/upgrades/v1.15/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:staticcheck` is unused for linter "staticcheck" (nolintlint)
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck
default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

baseAppLegacySS := appKeepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(sdk.UnwrapSDKContext(ctx), baseAppLegacySS, appKeepers.ConsensusParamsKeeper.ParamsStore)

Check failure on line 102 in app/upgrades/v1.15/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `baseapp.MigrateParams` is not checked (errcheck)

logger.Info(fmt.Sprintf("Running module migrations for %s...", upgradeName))

return mm.RunMigrations(ctx, configurator, vm)
Expand Down

0 comments on commit 28f85a6

Please sign in to comment.