Skip to content

Commit

Permalink
Final fix for v0.1 to v0.2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
luckychess committed Dec 9, 2024
1 parent 94002cb commit 7c74db9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
14 changes: 9 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand Down
22 changes: 12 additions & 10 deletions app/upgrades/0.2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
19 changes: 19 additions & 0 deletions proposal.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 7c74db9

Please sign in to comment.