Skip to content

Commit

Permalink
feat: add ibcwasm upgrade handler for store migrations (cosmos#5327)
Browse files Browse the repository at this point in the history
* feat: add ibcwasm upgrade handler for store migrations

* chore: actually use the const

* make lint fix solves all my problems
  • Loading branch information
damiannolan authored Dec 6, 2023
1 parent 2a39b26 commit 38a46a0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ func NewSimApp(
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)

// registerUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.ModuleManager` and `app.configurator` are set.
app.registerUpgradeHandlers()

// add test gRPC service for testing gRPC queries in isolation
testpb.RegisterQueryServer(app.GRPCQueryRouter(), testpb.QueryImpl{})

Expand Down
45 changes: 45 additions & 0 deletions modules/light-clients/08-wasm/testing/simapp/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package simapp

import (
"context"

storetypes "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/types/module"
)

const (
IBCWasmUpgrade = "ibcwasm-v8"
)

// registerUpgradeHandlers registers all supported upgrade handlers
func (app *SimApp) registerUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
IBCWasmUpgrade,
createWasmStoreUpgradeHandler(app.ModuleManager, app.configurator),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == IBCWasmUpgrade && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
circuittypes.ModuleName,
},
}
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// createWasmStoreUpgradeHandler creates an upgrade handler for the 08-wasm ibc-go/v8 SimApp upgrade.
func createWasmStoreUpgradeHandler(mm *module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler {
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit 38a46a0

Please sign in to comment.