Skip to content

Commit

Permalink
[v19] 08-Wasm Light Client (#921)
Browse files Browse the repository at this point in the history
* add wasm light client + comments to upstream doc changes

* lint & mod tidy

* cleanup comments

* Add `wasmlctypes.ModuleName` to upgrade

* gci

* 2x NewWasmSnapshotter & InitializePinnedCodes
  • Loading branch information
Reecepbcups authored Dec 20, 2023
1 parent cc6e23e commit 1049ee1
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 95 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/dependency-review.yml

This file was deleted.

13 changes: 12 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
tmos "github.com/cometbft/cometbft/libs/os"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
Expand Down Expand Up @@ -404,7 +405,9 @@ func New(

if manager := app.SnapshotManager(); manager != nil {
err = manager.RegisterExtensions(
// https://github.com/cosmos/ibc-go/pull/5439
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmKeeper),
wasmlckeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmClientKeeper),
)
if err != nil {
panic("failed to register snapshot extension: " + err.Error())
Expand Down Expand Up @@ -438,11 +441,19 @@ func New(
tmos.Exit(err.Error())
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
// Initialize pinned codes in wasmvm as they are not persisted there

// Initialize pinned codes in wasmvm as they are not persisted there.
// We do not use the wasm light client's impl since we do not want ALL to be pinned.
// The WasmKeeper will handle is as expected.
if err := app.AppKeepers.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}

// https://github.com/cosmos/ibc-go/pull/5439
if err := wasmlckeeper.InitializePinnedCodes(ctx, appCodec); err != nil {
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}

// Initialize and seal the capability keeper so all persistent capabilities
// are loaded in-memory and prevent any further modules from creating scoped
// sub-keepers.
Expand Down
44 changes: 42 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package keepers

import (
"fmt"
"math"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
buildertypes "github.com/skip-mev/pob/x/builder/types"
"github.com/spf13/cast"
Expand All @@ -20,6 +22,8 @@ import (
ibc_hooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
Expand Down Expand Up @@ -169,6 +173,7 @@ type AppKeepers struct {
ContractKeeper wasmtypes.ContractOpsKeeper
ClockKeeper clockkeeper.Keeper
CWHooksKeeper cwhookskeeper.Keeper
WasmClientKeeper wasmlckeeper.Keeper

ConsensusParamsKeeper consensusparamkeeper.Keeper

Expand Down Expand Up @@ -490,7 +495,7 @@ func NewAppKeepers(
wasmOpts = append(wasmOpts, tfOpts...)

// Stargate Queries
accepted := wasmkeeper.AcceptedStargateQueries{
acceptedStargateQueries := wasmkeeper.AcceptedStargateQueries{
// ibc
"/ibc.core.client.v1.Query/ClientState": &ibcclienttypes.QueryClientStateResponse{},
"/ibc.core.client.v1.Query/ConsensusState": &ibcclienttypes.QueryConsensusStateResponse{},
Expand Down Expand Up @@ -518,7 +523,7 @@ func NewAppKeepers(

querierOpts := wasmkeeper.WithQueryPlugins(
&wasmkeeper.QueryPlugins{
Stargate: wasmkeeper.AcceptListStargateQuerier(accepted, bApp.GRPCQueryRouter(), appCodec),
Stargate: wasmkeeper.AcceptListStargateQuerier(acceptedStargateQueries, bApp.GRPCQueryRouter(), appCodec),
})
wasmOpts = append(wasmOpts, querierOpts)

Expand All @@ -534,6 +539,14 @@ func NewAppKeepers(

wasmOpts = append(wasmOpts, burnMessageHandler)

// create a shared VM instance (x/wasm <-> wasm light client)
wasmer, err := wasmvm.NewVM(wasmDir, wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize)
if err != nil {
panic(fmt.Sprintf("failed to create juno wasm vm: %s", err))
}

wasmOpts = append(wasmOpts, wasmkeeper.WithWasmEngine(wasmer))

appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
appKeepers.keys[wasmtypes.StoreKey],
Expand All @@ -555,6 +568,33 @@ func NewAppKeepers(
wasmOpts...,
)

// 08-wasm light client
accepted := make([]string, 0)
for k := range acceptedStargateQueries {
accepted = append(accepted, k)
}

wasmLightClientQuerier := wasmlctypes.QueryPlugins{
// Custom: MyCustomQueryPlugin(),
// `myAcceptList` is a `[]string` containing the list of gRPC query paths that the chain wants to allow for the `08-wasm` module to query.
// These queries must be registered in the chain's gRPC query router, be deterministic, and track their gas usage.
// The `AcceptListStargateQuerier` function will return a query plugin that will only allow queries for the paths in the `myAcceptList`.
// The query responses are encoded in protobuf unlike the implementation in `x/wasm`.
Stargate: wasmlctypes.AcceptListStargateQuerier(accepted),
}

wasmQuerierOption := wasmlckeeper.WithQueryPlugins(&wasmLightClientQuerier)

appKeepers.WasmClientKeeper = wasmlckeeper.NewKeeperWithVM(
appCodec,
appKeepers.keys[wasmlctypes.StoreKey],
appKeepers.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmer,
bApp.GRPCQueryRouter(),
wasmQuerierOption,
)

appKeepers.FeePayKeeper = feepaykeeper.NewKeeper(
appKeepers.keys[feepaytypes.StoreKey],
appCodec,
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
Expand Down Expand Up @@ -47,7 +48,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, wasmlctypes.StoreKey,

// non sdk store keys
ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
Expand Down
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"
ibc_hooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
wasmlc "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
Expand Down Expand Up @@ -116,6 +118,7 @@ var ModuleBasics = module.NewBasicManager(
packetforward.AppModuleBasic{},
clock.AppModuleBasic{},
cwhooks.AppModuleBasic{},
wasmlc.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -168,6 +171,7 @@ func appModules(
ibc_hooks.NewAppModule(app.AppKeepers.AccountKeeper),
icq.NewAppModule(app.AppKeepers.ICQKeeper),
packetforward.NewAppModule(app.AppKeepers.PacketForwardKeeper),
wasmlc.NewAppModule(app.AppKeepers.WasmClientKeeper),
}
}

Expand Down Expand Up @@ -243,6 +247,7 @@ func orderBeginBlockers() []string {
ibchookstypes.ModuleName,
clocktypes.ModuleName,
cwhooks.ModuleName,
wasmlctypes.ModuleName,
}
}

Expand Down Expand Up @@ -283,6 +288,7 @@ func orderEndBlockers() []string {
ibchookstypes.ModuleName,
clocktypes.ModuleName,
cwhooks.ModuleName,
wasmlctypes.ModuleName,
}
}

Expand Down Expand Up @@ -323,5 +329,6 @@ func orderInitBlockers() []string {
ibchookstypes.ModuleName,
clocktypes.ModuleName,
cwhooks.ModuleName,
wasmlctypes.ModuleName,
}
}
8 changes: 6 additions & 2 deletions app/upgrades/v19/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v19

import (
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/CosmosContracts/juno/v19/app/upgrades"
Expand All @@ -12,7 +14,9 @@ const UpgradeName = "v19"
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV19UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
// Added: []string{},
StoreUpgrades: store.StoreUpgrades{
Added: []string{
wasmlctypes.ModuleName,
},
},
}
7 changes: 7 additions & 0 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package v19
import (
"fmt"

wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -43,6 +45,11 @@ func CreateV19UpgradeHandler(
}
}

// https://github.com/cosmos/ibc-go/blob/main/docs/docs/03-light-clients/04-wasm/03-integration.md
params := k.IBCKeeper.ClientKeeper.GetParams(ctx)
params.AllowedClients = append(params.AllowedClients, wasmlctypes.Wasm)
k.IBCKeeper.ClientKeeper.SetParams(ctx, params)

return versionMap, err
}
}
28 changes: 15 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.1.2
cosmossdk.io/math v1.2.0
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.45.0
github.com/CosmWasm/wasmvm v1.5.0
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/cosmos-sdk v0.47.6
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.1
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79
// https://github.com/cosmos/ibc-go/releases/tag/modules%2Flight-clients%2F08-wasm%2Fv0.1.0%2Bibc-go-v7.3-wasmvm-v1.5
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1
github.com/cosmos/ibc-go/v7 v7.3.1
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
Expand All @@ -30,16 +32,16 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97
google.golang.org/grpc v1.58.3
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
Expand Down Expand Up @@ -92,7 +94,7 @@ require (
github.com/gogo/googleapis v1.4.1 // indirect
// TODO: migrate to cosmos/gogoproto per SDK v47 upgrade guide
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -102,8 +104,8 @@ require (
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.4 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
Expand All @@ -124,7 +126,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
Expand Down Expand Up @@ -176,10 +178,10 @@ require (
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/api v0.128.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/protobuf v1.31.0
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 1049ee1

Please sign in to comment.