Skip to content

Commit

Permalink
deps: bump wasmvm v2.0.0 (#5909)
Browse files Browse the repository at this point in the history
* deps: bump wasmvm v2.0.0

* indentation

* remove empty lines

* linter

* more linting

* add test and fix test

* append random string to data directory + address review comments

* added comment about random string added to data dir

* fix typo

* code ID -> checksum

* deps: bump wasmvm v2.0.0

* add changelog

* address review comment and fix merge conflicts

* fix broken link

* linter

* address review comment

---------

Co-authored-by: DimitrisJim <[email protected]>
(cherry picked from commit 30d56fc)

# Conflicts:
#	docs/docs/03-light-clients/04-wasm/03-integration.md
#	docs/docs/03-light-clients/04-wasm/09-migrations.md
#	e2e/go.mod
#	e2e/go.sum
#	modules/light-clients/08-wasm/CHANGELOG.md
#	modules/light-clients/08-wasm/go.mod
#	modules/light-clients/08-wasm/go.sum
#	modules/light-clients/08-wasm/light_client_module_test.go
#	modules/light-clients/08-wasm/testing/simapp/app.go
#	modules/light-clients/08-wasm/wasm_test.go
  • Loading branch information
Carlos Rodriguez authored and mergify[bot] committed Mar 19, 2024
1 parent 0cccd07 commit 28e45c2
Show file tree
Hide file tree
Showing 35 changed files with 3,183 additions and 328 deletions.
26 changes: 20 additions & 6 deletions docs/docs/03-light-clients/04-wasm/03-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ When it comes to instantiating `08-wasm`'s keeper there are two recommended ways

### If `x/wasm` is present

If the chain where the module is integrated uses `x/wasm` then we recommend that both `08-wasm` and `x/wasm` share the same Wasm VM instance. Having two separate Wasm VM instances is still possible, but care should be taken to make sure that both instances do not share the directory when the VM stores blobs and various caches, otherwise unexpected behaviour is likely to happen.
If the chain where the module is integrated uses `x/wasm` then we recommend that both `08-wasm` and `x/wasm` share the same Wasm VM instance. Having two separate Wasm VM instances is still possible, but care should be taken to make sure that both instances do not share the directory when the VM stores blobs and various caches, otherwise unexpected behaviour is likely to happen (from `x/wasm` v0.51 and `08-wasm` v0.2.0.0+ibc-go-v8.2-wasmvm-v2.0 this will be forbidden anyway, since wasmvm v2.0.0 and above will not allow two different Wasm VM instances to shared the same data folder).

In order to share the Wasm VM instance please follow the guideline below. Please note that this requires `x/wasm`v0.41 or above.
In order to share the Wasm VM instance please follow the guideline below. Please note that this requires `x/wasm` v0.41 or above.

- Instantiate the Wasm VM in `app.go` with the parameters of your choice.
- [Create an `Option` with this Wasm VM instance](https://github.com/CosmWasm/wasmd/blob/db93d7b6c7bb6f4a340d74b96a02cec885729b59/x/wasm/keeper/options.go#L21-L25).
Expand All @@ -150,8 +150,13 @@ The code to set this up would look something like this:
import (
...
"github.com/cosmos/cosmos-sdk/runtime"
<<<<<<< HEAD

wasmvm "github.com/CosmWasm/wasmvm"
=======

wasmvm "github.com/CosmWasm/wasmvm/v2"
>>>>>>> 30d56fc8 (deps: bump wasmvm v2.0.0 (#5909))
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
...
)
Expand Down Expand Up @@ -219,10 +224,10 @@ app.WasmClientKeeper = wasmkeeper.NewKeeperWithVM(
If the chain does not use [`x/wasm`](https://github.com/CosmWasm/wasmd/tree/main/x/wasm), even though it is still possible to use the method above from the previous section
(e.g. instantiating a Wasm VM in app.go an pass it to 08-wasm's [`NewKeeperWithVM` constructor function](https://github.com/cosmos/ibc-go/blob/c95c22f45cb217d27aca2665af9ac60b0d2f3a0c/modules/light-clients/08-wasm/keeper/keeper.go#L33-L38), since there would be no need in this case to share the Wasm VM instance with another module, you can use the [`NewKeeperWithConfig`` constructor function](https://github.com/cosmos/ibc-go/blob/c95c22f45cb217d27aca2665af9ac60b0d2f3a0c/modules/light-clients/08-wasm/keeper/keeper.go#L52-L57) and provide the Wasm VM configuration parameters of your choice instead. A Wasm VM instance will be created in`NewKeeperWithConfig`. The parameters that can set are:

- `DataDir` is the [directory for Wasm blobs and various caches](https://github.com/CosmWasm/wasmvm/blob/1638725b25d799f078d053391945399cb35664b1/lib.go#L25). In `wasmd` this is set to the [`wasm` folder under the home directory](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L578).
- `SupportedCapabilities` is a comma separated [list of capabilities supported by the chain](https://github.com/CosmWasm/wasmvm/blob/1638725b25d799f078d053391945399cb35664b1/lib.go#L26). [`wasmd` sets this to all the available capabilities](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L586), but 08-wasm only requires `iterator`.
- `MemoryCacheSize` sets [the size in MiB of an in-memory cache for e.g. module caching](https://github.com/CosmWasm/wasmvm/blob/1638725b25d799f078d053391945399cb35664b1/lib.go#L29C16-L29C104). It is not consensus-critical and should be defined on a per-node basis, often in the range 100 to 1000 MB. [`wasmd` reads this value of](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L579). Default value is 256.
- `ContractDebugMode` is a [flag to enable/disable printing debug logs from the contract to STDOUT](https://github.com/CosmWasm/wasmvm/blob/1638725b25d799f078d053391945399cb35664b1/lib.go#L28). This should be false in production environments. Default value is false.
- `DataDir` is the [directory for Wasm blobs and various caches](https://github.com/CosmWasm/wasmvm/blob/v2.0.0/lib.go#L25). As an example, in `wasmd` this is set to the [`wasm` folder under the home directory](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L578). In the code snippet below we set this field to the `ibc_08-wasm_client_data` folder under the home directory.
- `SupportedCapabilities` is a [list of capabilities supported by the chain](https://github.com/CosmWasm/wasmvm/blob/v2.0.0/lib.go#L26). [`wasmd` sets this to all the available capabilities](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L586), but 08-wasm only requires `iterator`.
- `MemoryCacheSize` sets [the size in MiB of an in-memory cache for e.g. module caching](https://github.com/CosmWasm/wasmvm/blob/v2.0.0/lib.go#L29C16-L29C104). It is not consensus-critical and should be defined on a per-node basis, often in the range 100 to 1000 MB. [`wasmd` reads this value of](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/app/app.go#L579). Default value is 256.
- `ContractDebugMode` is a [flag to enable/disable printing debug logs from the contract to STDOUT](https://github.com/CosmWasm/wasmvm/blob/v2.0.0/lib.go#L28). This should be false in production environments. Default value is false.

Another configuration parameter of the Wasm VM is the contract memory limit (in MiB), which is [set to 32](https://github.com/cosmos/ibc-go/blob/c95c22f45cb217d27aca2665af9ac60b0d2f3a0c/modules/light-clients/08-wasm/types/config.go#L5), [following the example of `wasmd`](https://github.com/CosmWasm/wasmd/blob/36416def20effe47fb77f29f5ba35a003970fdba/x/wasm/keeper/keeper.go#L32-L34). This parameter is not configurable by users of `08-wasm`.

Expand All @@ -239,9 +244,18 @@ import (
...
)
...
<<<<<<< HEAD
wasmConfig := wasmtypes.WasmConfig{
DataDir: "ibc_08-wasm_client_data",
SupportedCapabilities: "iterator",
=======

// homePath is the path to the directory where the data
// directory for Wasm blobs and caches will be created
wasmConfig := ibcwasmtypes.WasmConfig{
DataDir: filepath.Join(homePath, "ibc_08-wasm_client_data"),
SupportedCapabilities: []string{"iterator"},
>>>>>>> 30d56fc8 (deps: bump wasmvm v2.0.0 (#5909))
ContractDebugMode: false,
}
app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig(
Expand Down
103 changes: 103 additions & 0 deletions docs/docs/03-light-clients/04-wasm/09-migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Migrations
sidebar_label: Migrations
sidebar_position: 9
slug: /ibc/light-clients/wasm/migrations
---

# Migrations

This guide provides instructions for migrating 08-wasm versions.

## From ibc-go v7.3.x to ibc-go v8.0.x

### Chains

In the 08-wasm versions compatible with ibc-go v7.3.x and above from the v7 release line, the checksums of the uploaded Wasm bytecodes are all stored under a single key. From ibc-go v8.0.x the checksums are stored using [`collections.KeySet`](https://docs.cosmos.network/v0.50/build/packages/collections#keyset), whose full functionality became available in Cosmos SDK v0.50. There is therefore an [automatic migration handler](https://github.com/cosmos/ibc-go/blob/57fcdb9a9a9db9b206f7df2f955866dc4e10fef4/modules/light-clients/08-wasm/module.go#L115-L118) configured in the 08-wasm module to migrate the stored checksums to `collections.KeySet`.

## From v0.1.0+ibc-go-v8.0-wasmvm-v1.5 to v0.2.0-ibc-go-v8.2-wasmvm-v2.0

The `WasmEngine` interface has been updated to reflect changes in the function signatures of Wasm VM:

```diff
type WasmEngine interface {
- StoreCode(code wasmvm.WasmCode) (wasmvm.Checksum, error)
+ StoreCode(code wasmvm.WasmCode, gasLimit uint64) (wasmvmtypes.Checksum, uint64, error)

StoreCodeUnchecked(code wasmvm.WasmCode) (wasmvm.Checksum, error)

Instantiate(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
info wasmvmtypes.MessageInfo,
initMsg []byte,
store wasmvm.KVStore,
goapi wasmvm.GoAPI,
querier wasmvm.Querier,
gasMeter wasmvm.GasMeter,
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
- ) (*wasmvmtypes.Response, uint64, error)
+ ) (*wasmvmtypes.ContractResult, uint64, error)

Query(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
queryMsg []byte,
store wasmvm.KVStore,
goapi wasmvm.GoAPI,
querier wasmvm.Querier,
gasMeter wasmvm.GasMeter,
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
- ) ([]byte, uint64, error)
+ ) (*wasmvmtypes.QueryResult, uint64, error)

Migrate(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
migrateMsg []byte,
store wasmvm.KVStore,
goapi wasmvm.GoAPI,
querier wasmvm.Querier,
gasMeter wasmvm.GasMeter,
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
- ) (*wasmvmtypes.Response, uint64, error)
+ ) (*wasmvmtypes.ContractResult, uint64, error)

Sudo(
checksum wasmvm.Checksum,
env wasmvmtypes.Env,
sudoMsg []byte,
store wasmvm.KVStore,
goapi wasmvm.GoAPI,
querier wasmvm.Querier,
gasMeter wasmvm.GasMeter,
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
- ) (*wasmvmtypes.Response, uint64, error)
+ ) (*wasmvmtypes.ContractResult, uint64, error)

GetCode(checksum wasmvm.Checksum) (wasmvm.WasmCode, error)

Pin(checksum wasmvm.Checksum) error

Unpin(checksum wasmvm.Checksum) error
}
```

Similar changes were required in the functions of `MockWasmEngine` interface.

### Chains

The `SupportedCapabilities` field of `WasmConfig` is now of type `[]string`:

```diff
type WasmConfig struct {
DataDir string
- SupportedCapabilities string
+ SupportedCapabilities []string
ContractDebugMode bool
}
```
Loading

0 comments on commit 28e45c2

Please sign in to comment.