|
1 | 1 | package app |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
| 4 | + "fmt" |
| 5 | + |
| 6 | + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" |
| 7 | + icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" |
| 8 | + ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" |
| 9 | + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck |
| 10 | + ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" |
| 11 | + ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" |
5 | 12 |
|
6 | | - storetypes "cosmossdk.io/store/types" |
7 | 13 | upgradetypes "cosmossdk.io/x/upgrade/types" |
8 | 14 |
|
9 | | - "github.com/cosmos/cosmos-sdk/types/module" |
| 15 | + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" |
| 16 | + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" |
| 17 | + |
| 18 | + "github.com/CosmWasm/wasmd/app/upgrades" |
| 19 | + "github.com/CosmWasm/wasmd/app/upgrades/noop" |
| 20 | + v050 "github.com/CosmWasm/wasmd/app/upgrades/v050" |
10 | 21 | ) |
11 | 22 |
|
12 | | -// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade |
13 | | -// from v047 to v050. |
14 | | -// |
15 | | -// NOTE: This upgrade defines a reference implementation of what an upgrade |
16 | | -// could look like when an application is migrating from Cosmos SDK version |
17 | | -// v0.47.x to v0.50.x. |
18 | | -const UpgradeName = "v047-to-v050" |
| 23 | +// Upgrades list of chain upgrades |
| 24 | +var Upgrades = []upgrades.Upgrade{v050.Upgrade} |
19 | 25 |
|
| 26 | +// RegisterUpgradeHandlers registers the chain upgrade handlers |
20 | 27 | func (app WasmApp) RegisterUpgradeHandlers() { |
21 | | - app.UpgradeKeeper.SetUpgradeHandler( |
22 | | - UpgradeName, |
23 | | - func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { |
24 | | - return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) |
25 | | - }, |
26 | | - ) |
| 28 | + setupLegacyKeyTables(app.ParamsKeeper) |
| 29 | + if len(Upgrades) == 0 { |
| 30 | + // always have a unique upgrade registered for the current version to test in system tests |
| 31 | + Upgrades = append(Upgrades, noop.NewUpgrade(app.Version())) |
| 32 | + } |
| 33 | + |
| 34 | + keepers := upgrades.AppKeepers{AccountKeeper: app.AccountKeeper} |
| 35 | + // register all upgrade handlers |
| 36 | + for _, upgrade := range Upgrades { |
| 37 | + app.UpgradeKeeper.SetUpgradeHandler( |
| 38 | + upgrade.UpgradeName, |
| 39 | + upgrade.CreateUpgradeHandler( |
| 40 | + app.ModuleManager, |
| 41 | + app.configurator, |
| 42 | + &keepers, |
| 43 | + ), |
| 44 | + ) |
| 45 | + } |
27 | 46 |
|
28 | 47 | upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() |
29 | 48 | if err != nil { |
30 | | - panic(err) |
| 49 | + panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) |
31 | 50 | } |
32 | 51 |
|
33 | | - if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { |
34 | | - storeUpgrades := storetypes.StoreUpgrades{} |
| 52 | + if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { |
| 53 | + return |
| 54 | + } |
| 55 | + |
| 56 | + // register store loader for current upgrade |
| 57 | + for _, upgrade := range Upgrades { |
| 58 | + if upgradeInfo.Name == upgrade.UpgradeName { |
| 59 | + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) // nolint:gosec |
| 60 | + break |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +func setupLegacyKeyTables(k paramskeeper.Keeper) { |
| 66 | + // Set param key table for params module migration |
| 67 | + for _, subspace := range k.GetSubspaces() { |
| 68 | + subspace := subspace |
| 69 | + |
| 70 | + var keyTable paramstypes.KeyTable |
| 71 | + switch subspace.Name() { |
| 72 | + // ibc types |
| 73 | + case ibcexported.ModuleName: |
| 74 | + keyTable = ibcclienttypes.ParamKeyTable() |
| 75 | + keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) |
| 76 | + case ibctransfertypes.ModuleName: |
| 77 | + keyTable = ibctransfertypes.ParamKeyTable() |
| 78 | + case icahosttypes.SubModuleName: |
| 79 | + keyTable = icahosttypes.ParamKeyTable() |
| 80 | + case icacontrollertypes.SubModuleName: |
| 81 | + keyTable = icacontrollertypes.ParamKeyTable() |
| 82 | + default: |
| 83 | + continue |
| 84 | + } |
35 | 85 |
|
36 | | - // configure store loader that checks if version == upgradeHeight and applies store upgrades |
37 | | - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) |
| 86 | + if !subspace.HasKeyTable() { |
| 87 | + subspace.WithKeyTable(keyTable) |
| 88 | + } |
38 | 89 | } |
39 | 90 | } |
0 commit comments