Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix 08-wasm light client documentation #5439

Merged
merged 6 commits into from
Dec 19, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions docs/docs/03-light-clients/04-wasm/03-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,7 +55,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
...
wasmtypes.StoreKey,
)
)

// Instantiate 08-wasm's keeper
// This sample code uses a constructor function that
Expand All @@ -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,
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update this when creating the versioned docs for v7.3.x. Thanks for noticing!

cmtos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}
}
Expand Down Expand Up @@ -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"
...
Expand All @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasmvm does not expose this in any way, just a nice to have to let others know the default

wasmConfig.ContractDebugMode,
Copy link
Member Author

@Reecepbcups Reecepbcups Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is in the If x/wasm is present section, it can be used here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess maybe not using the defaults specified in wasmConfig would be better? Having these as was done previously should force folks to ideally look it up and specify something sensible for their case instead of relying on defaults we specified for the case where we create the VM (i.e not x/wasm present). wdyt?

wasmConfig.MemoryCacheSize,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will also fix this when creating the versioned docs.

app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmConfig,
app.GRPCQueryRouter(),
Expand Down Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this reference is required for both v7 & v8

```

Finally, we pass the option to the `NewKeeperWithConfig` or `NewKeeperWithVM` constructor function during [Keeper instantiation](#keeper-instantiation):
Expand All @@ -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(),
Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! 👍🏻

}
}
```

## 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`.
Expand Down
Loading