From 7c74db9c41667d8a5729907c9c1724f411f3a8e4 Mon Sep 17 00:00:00 2001 From: Konstantin Munichev Date: Mon, 9 Dec 2024 22:02:23 +0100 Subject: [PATCH] Final fix for v0.1 to v0.2 migration --- app/app.go | 14 +++++++++----- app/upgrades/0.2/upgrades.go | 22 ++++++++++++---------- proposal.json | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 proposal.json diff --git a/app/app.go b/app/app.go index ab94160..36c46a4 100644 --- a/app/app.go +++ b/app/app.go @@ -101,6 +101,7 @@ import ( "github.com/cosmos/ibc-go/modules/capability" ibccapabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" ibccapabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" "github.com/spf13/cast" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward" @@ -1066,6 +1067,8 @@ func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + keyTable := ibcclienttypes.ParamKeyTable() + keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) paramsKeeper.Subspace(authtypes.ModuleName) paramsKeeper.Subspace(banktypes.ModuleName) paramsKeeper.Subspace(stakingtypes.ModuleName) @@ -1074,10 +1077,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck paramsKeeper.Subspace(crisistypes.ModuleName) - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibcexported.ModuleName) - paramsKeeper.Subspace(icacontrollertypes.SubModuleName) - paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable()) + paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable()) + paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) paramsKeeper.Subspace(sscmoduletypes.ModuleName) paramsKeeper.Subspace(gmpmoduletypes.ModuleName) // this line is used by starport scaffolding # stargate/app/paramSubspace @@ -1096,7 +1099,8 @@ func (app *App) ModuleManager() *module.Manager { } func (app *App) RegisterUpgradeHandlers() { - app.UpgradeKeeper.SetUpgradeHandler(upgrade02.Name, upgrade02.UpgradeHandler(app.mm, app.configurator, app.ParamsKeeper, &app.ConsensusParamsKeeper, app.IBCKeeper.ClientKeeper)) + baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + app.UpgradeKeeper.SetUpgradeHandler(upgrade02.Name, upgrade02.UpgradeHandler(app.mm, app.configurator, app.ParamsKeeper, &app.ConsensusParamsKeeper, app.IBCKeeper.ClientKeeper, baseAppLegacySS)) upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { diff --git a/app/upgrades/0.2/upgrades.go b/app/upgrades/0.2/upgrades.go index acf64c8..88d441c 100644 --- a/app/upgrades/0.2/upgrades.go +++ b/app/upgrades/0.2/upgrades.go @@ -2,29 +2,31 @@ package v02 import ( "context" + "fmt" 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" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" ibcclientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" - "github.com/cosmos/ibc-go/v8/modules/core/exported" ) const Name = "0.1-to-0.2" -func UpgradeHandler(mm *module.Manager, configurator module.Configurator, paramsKeeper paramskeeper.Keeper, consensuskeeper *consensuskeeper.Keeper, clientKeeper ibcclientkeeper.Keeper) upgradetypes.UpgradeHandler { - +func UpgradeHandler(mm *module.Manager, configurator module.Configurator, paramsKeeper paramskeeper.Keeper, consensusKeeper *consensuskeeper.Keeper, clientKeeper ibcclientkeeper.Keeper, baseAppLegacySS paramstypes.Subspace) upgradetypes.UpgradeHandler { return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - newVM, err := mm.RunMigrations(ctx, configurator, vm) + sdkCtx := sdk.UnwrapSDKContext(ctx) + cp := baseapp.GetConsensusParams(sdkCtx, baseAppLegacySS) + if cp == nil { + return nil, fmt.Errorf("consensus parameters are undefined") + } + err := consensusKeeper.ParamsStore.Set(ctx, *cp) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to set consensus params: %w", err) } - sdkCtx := sdk.UnwrapSDKContext(ctx) - params := clientKeeper.GetParams(sdkCtx) - params.AllowedClients = append(params.AllowedClients, exported.Localhost) - clientKeeper.SetParams(sdkCtx, params) - return newVM, nil + return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/proposal.json b/proposal.json new file mode 100644 index 0000000..972053f --- /dev/null +++ b/proposal.json @@ -0,0 +1,19 @@ +{ + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "saga10d07y265gmmuvt4z0w9aw880jnsr700jy32h34", + "plan": { + "name": "0.1-to-0.2", + "time": "0001-01-01T00:00:00Z", + "height": "400", + "info": "TBD", + "upgraded_client_state": null + } + } + ], + "metadata": "ipfs://CID", + "deposit": "10000000stake", + "title": "Upgrade SSC to 0.2.0", + "summary": "Upgrade SSC to 0.2.0" +} \ No newline at end of file