From a1ffefcb9a8f526cabb01d926f808a04ebbaa7ae Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Mon, 18 Dec 2023 19:05:12 -0600 Subject: [PATCH 1/5] tweaks per Juno's integration --- .../04-wasm/03-integration.md | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/docs/03-light-clients/04-wasm/03-integration.md b/docs/docs/03-light-clients/04-wasm/03-integration.md index 5e32d8a3522..07153ad42b5 100644 --- a/docs/docs/03-light-clients/04-wasm/03-integration.md +++ b/docs/docs/03-light-clients/04-wasm/03-integration.md @@ -18,7 +18,7 @@ The sample code below shows the relevant integration points in `app.go` required import ( ... "github.com/cosmos/cosmos-sdk/runtime" - + cmtos "github.com/cometbft/cometbft/libs/os" wasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" @@ -55,7 +55,7 @@ func NewSimApp( keys := sdk.NewKVStoreKeys( ... wasmtypes.StoreKey, - ) + ) // Instantiate 08-wasm's keeper // This sample code uses a constructor function that @@ -70,22 +70,22 @@ func NewSimApp( authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmVM, app.GRPCQueryRouter(), - ) + ) app.ModuleManager = module.NewManager( // SDK app modules ... wasm.NewAppModule(app.WasmClientKeeper), - ) + ) app.ModuleManager.SetOrderBeginBlockers( ... wasmtypes.ModuleName, ... - ) + ) app.ModuleManager.SetOrderEndBlockers( ... wasmtypes.ModuleName, ... - ) + ) genesisModuleOrder := []string{ ... wasmtypes.ModuleName, @@ -116,7 +116,7 @@ func NewSimApp( ctx := app.BaseApp.NewUncachedContext(true, cmtproto.Header{}) // Initialize pinned codes in wasmvm as they are not persisted there - if err := wasmkeeper.InitializePinnedCodes(ctx); err != nil { + if err := wasmkeeper.InitializePinnedCodes(ctx); err != nil { // appCodec is required in v7 cmtos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) } } @@ -145,7 +145,7 @@ The code to set this up would look something like this: import ( ... "github.com/cosmos/cosmos-sdk/runtime" - + wasmvm "github.com/CosmWasm/wasmvm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" ... @@ -155,11 +155,11 @@ import ( // instantiate the Wasm VM with the chosen parameters wasmer, err := wasmvm.NewVM( - dataDir, - availableCapabilities, - contractMemoryLimit, - contractDebugMode, - memoryCacheSize, + dataDir, + availableCapabilities, + contractMemoryLimit, // default of 32 + wasmConfig.ContractDebugMode, + wasmConfig.MemoryCacheSize, ) if err != nil { panic(err) @@ -237,8 +237,8 @@ wasmConfig := wasmtypes.WasmConfig{ } app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig( appCodec, - runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), - app.IBCKeeper.ClientKeeper, + runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), // v7 use app.keys[wasmtypes.StoreKey] + app.IBCKeeper.ClientKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmConfig, app.GRPCQueryRouter(), @@ -276,7 +276,7 @@ You may leave any of the fields in the `QueryPlugins` object as `nil` if you do Then, we pass the `QueryPlugins` object to the `WithQueryPlugins` option: ```go -querierOption := ibcwasmtypes.WithQueryPlugins(queryPlugins) +querierOption := ibcwasmkeeper.WithQueryPlugins(&queryPlugins) ``` Finally, we pass the option to the `NewKeeperWithConfig` or `NewKeeperWithVM` constructor function during [Keeper instantiation](#keeper-instantiation): @@ -285,7 +285,7 @@ Finally, we pass the option to the `NewKeeperWithConfig` or `NewKeeperWithVM` co app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig( appCodec, runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), - app.IBCKeeper.ClientKeeper, + app.IBCKeeper.ClientKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmConfig, app.GRPCQueryRouter(), From d771f93d4ed8d4ad899445c9d5d5f5fcb2b3f42c Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Mon, 18 Dec 2023 19:41:54 -0600 Subject: [PATCH 2/5] add `RegisterUpgradeHandlers` requirement --- .../04-wasm/03-integration.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/docs/03-light-clients/04-wasm/03-integration.md b/docs/docs/03-light-clients/04-wasm/03-integration.md index 07153ad42b5..8c6eee0585d 100644 --- a/docs/docs/03-light-clients/04-wasm/03-integration.md +++ b/docs/docs/03-light-clients/04-wasm/03-integration.md @@ -337,6 +337,29 @@ func CreateWasmUpgradeHandler( Or alternatively the parameter can be updated via a governance proposal (see at the bottom of section [`Creating clients`](../01-developer-guide/09-setup.md#creating-clients) for an example of how to do this). +## Adding the module to the store + +As part of the upgrade migration you must also add the module to the upgrades store. + +```go +func (app SimApp) RegisterUpgradeHandlers() { + + ... + + if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{ + ibcwasmtypes.ModuleName, + }, + } + + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } +} +``` + ## Adding snapshot support In order to use the `08-wasm` module chains are required to register the `WasmSnapshotter` extension in the snapshot manager. This snapshotter takes care of persisting the external state, in the form of contract code, of the Wasm VM instance to disk when the chain is snapshotted. [This code](https://github.com/cosmos/ibc-go/blob/2bd29c08fd1fe50b461fc33a25735aa792dc896e/modules/light-clients/08-wasm/testing/simapp/app.go#L768-L776) should be placed in `NewSimApp` function in `app.go`. From 660012aa7bd6acf342e278e48226b4e92a7aae44 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 19 Dec 2023 12:47:15 +0100 Subject: [PATCH 3/5] code alignment --- .../03-light-clients/04-wasm/03-integration.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/docs/03-light-clients/04-wasm/03-integration.md b/docs/docs/03-light-clients/04-wasm/03-integration.md index 8c6eee0585d..9e4c1431ce5 100644 --- a/docs/docs/03-light-clients/04-wasm/03-integration.md +++ b/docs/docs/03-light-clients/04-wasm/03-integration.md @@ -347,16 +347,15 @@ func (app SimApp) RegisterUpgradeHandlers() { ... if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{ - ibcwasmtypes.ModuleName, - }, - } - - - // configure store loader that checks if version == upgradeHeight and applies store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{ + ibcwasmtypes.ModuleName, + }, } + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } } ``` From fd3477befba0b0ede2aa3928fc4fa969bb634db3 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 19 Dec 2023 12:49:47 +0100 Subject: [PATCH 4/5] review comment --- docs/docs/03-light-clients/04-wasm/03-integration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/03-light-clients/04-wasm/03-integration.md b/docs/docs/03-light-clients/04-wasm/03-integration.md index 9e4c1431ce5..aec34df97f4 100644 --- a/docs/docs/03-light-clients/04-wasm/03-integration.md +++ b/docs/docs/03-light-clients/04-wasm/03-integration.md @@ -95,7 +95,7 @@ func NewSimApp( app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) ... - // initialize BaseApp + // initialize BaseApp app.SetInitChainer(app.InitChainer) ... @@ -158,8 +158,8 @@ wasmer, err := wasmvm.NewVM( dataDir, availableCapabilities, contractMemoryLimit, // default of 32 - wasmConfig.ContractDebugMode, - wasmConfig.MemoryCacheSize, + contractDebugMode, + memoryCacheSize, ) if err != nil { panic(err) From ddaca755cc4359b0074b802983ac52d87117481f Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 19 Dec 2023 12:51:10 +0100 Subject: [PATCH 5/5] remove v7 comments --- docs/docs/03-light-clients/04-wasm/03-integration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/03-light-clients/04-wasm/03-integration.md b/docs/docs/03-light-clients/04-wasm/03-integration.md index aec34df97f4..bfb0716698e 100644 --- a/docs/docs/03-light-clients/04-wasm/03-integration.md +++ b/docs/docs/03-light-clients/04-wasm/03-integration.md @@ -116,7 +116,7 @@ func NewSimApp( ctx := app.BaseApp.NewUncachedContext(true, cmtproto.Header{}) // Initialize pinned codes in wasmvm as they are not persisted there - if err := wasmkeeper.InitializePinnedCodes(ctx); err != nil { // appCodec is required in v7 + if err := wasmkeeper.InitializePinnedCodes(ctx); err != nil { cmtos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) } } @@ -237,7 +237,7 @@ wasmConfig := wasmtypes.WasmConfig{ } app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig( appCodec, - runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), // v7 use app.keys[wasmtypes.StoreKey] + runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), app.IBCKeeper.ClientKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmConfig,