Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega committed Nov 9, 2023
1 parent cbeb309 commit 65d6d4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
24 changes: 16 additions & 8 deletions docs/docs/03-light-clients/04-wasm/03-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The sample code below shows the relevant integration points in `app.go` required
// app.go
import (
...
"github.com/cosmos/cosmos-sdk/runtime"

wasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
Expand Down Expand Up @@ -61,7 +63,8 @@ func NewSimApp(
// See the section below for more information.
app.WasmClientKeeper = wasmkeeper.NewKeeperWithVM(
appCodec,
keys[wasmtypes.StoreKey],
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmVM,
)
Expand Down Expand Up @@ -127,6 +130,8 @@ The code to set this up would look something like this:
// app.go
import (
...
"github.com/cosmos/cosmos-sdk/runtime"

wasmvm "github.com/CosmWasm/wasmvm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
...
Expand Down Expand Up @@ -177,7 +182,8 @@ app.WasmKeeper = wasmkeeper.NewKeeper(

app.WasmClientKeeper = wasmkeeper.NewKeeperWithVM(
appCodec,
keys[wasmtypes.StoreKey],
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmer, // pass the Wasm VM instance to `08-wasm` keeper constructor
)
Expand All @@ -190,7 +196,7 @@ If the chain does not use [`x/wasm`](https://github.com/CosmWasm/wasmd/tree/main
(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 bi 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).
- `SupportedFeatures` 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`.
- `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.

Expand All @@ -202,20 +208,22 @@ The following sample code shows how the keeper would be constructed using this m
// app.go
import (
...
"github.com/cosmos/cosmos-sdk/runtime"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
...
)
...
wasmConfig := wasmtypes.WasmConfig{
DataDir: "ibc_08-wasm_client_data",
SupportedFeatures: "iterator",
MemoryCacheSize: uint32(math.Pow(2, 8)),
ContractDebugMode: false,
DataDir: "ibc_08-wasm_client_data",
SupportedCapabilities: "iterator",
ContractDebugMode: false,
}
app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig(
appCodec,
keys[wasmtypes.StoreKey],
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmConfig,
)
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/03-light-clients/04-wasm/04-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type MsgMigrateContract struct {
Signer string
// the client id of the contract
ClientId string
// the code hash of the new wasm byte code for the contract
// the SHA-256 hash of the new wasm byte code for the contract
CodeHash []byte
// the json-encoded migrate msg to be passed to the contract on migration
Msg []byte
Expand All @@ -56,7 +56,7 @@ When a Wasm light client contract is migrated to a new Wasm byte code the code h

## `MsgRemoveCodeHash`

Removing a code hash from the allow list is achieved by means of `MsgRemoveCodeHash`:
Removing a code hash from the list of allowed code hashes is achieved by means of `MsgRemoveCodeHash`:

```go
type MsgRemoveCodeHash struct {
Expand All @@ -72,5 +72,5 @@ This message is expected to fail if:
- `Signer` is an invalid Bech32 address, or it does not match the designated authority address.
- `CodeHash` is not exactly 32 bytes long or it is not found in the list of allowed code hashes (a new code hash is added to the list when executing `MsgStoreCode`).

When a code hash is removed from the allow list, then the corresponding Wasm byte code will not be available for instantiation in [08-wasm's implementation of `Initialize` function](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34).
When a code hash is removed from the list of allowed code hashes, then the corresponding Wasm byte code will not be available for instantiation in [08-wasm's implementation of `Initialize` function](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34).

4 changes: 2 additions & 2 deletions docs/docs/03-light-clients/04-wasm/05-governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ To learn more about the `submit-proposal` CLI command, please check out [the rel

## Removing an existing code hash

If governance is the allowed authority, the governance v1 proposal that needs to be submitted to remove a specific code hash from the allow list should contain the message [`MsgRemoveCodeHash`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L38-L46) with the code hash (of a corresponding Wasm byte code). Use the following CLI command and JSON as an example:
If governance is the allowed authority, the governance v1 proposal that needs to be submitted to remove a specific code hash from the -list of allowed code hashes should contain the message [`MsgRemoveCodeHash`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L38-L46) with the code hash (of a corresponding Wasm byte code). Use the following CLI command and JSON as an example:

```shell
%s tx gov submit-proposal <path/to/proposal.json> --from <key_or_address>
Expand All @@ -114,7 +114,7 @@ where `proposal.json` contains:
{
"@type": "/ibc.lightclients.wasm.v1.MsgRemoveCodeHash",
"signer": "cosmos1...", // the authority address (e.g. the gov module account address)
"code_hash": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code that should be removed from the allow list
"code_hash": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code that should be removed from the list of allowed code hashes
}
],
"metadata": "AQ==",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/03-light-clients/04-wasm/08-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ simd query ibc-wasm --help

#### `code-hashes`

The `code-hashes` command allows users to query the list of code hashes of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`.
The `code-hashes` command allows users to query the list of code hashes of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`. The code hashes are hex-encoded.

```shell
simd query ibc-wasm code-hashes [flags]
Expand Down

0 comments on commit 65d6d4e

Please sign in to comment.