Skip to content

Commit

Permalink
add wasm light client + comments to upstream doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Dec 19, 2023
1 parent cc6e23e commit 20e0492
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 44 deletions.
13 changes: 11 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strconv"
"strings"

wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"

wasm "github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -404,7 +406,9 @@ func New(

if manager := app.SnapshotManager(); manager != nil {
err = manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmKeeper),
// TODO: is this okay? (may not matter since we are sharing the VM instance)
// 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,8 +442,13 @@ func New(
tmos.Exit(err.Error())
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})

// Initialize pinned codes in wasmvm as they are not persisted there
if err := app.AppKeepers.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
// TODO: check if this must match docs
// if err := app.AppKeepers.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
// tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
// }
if err := wasmlckeeper.InitializePinnedCodes(ctx, appCodec); err != nil { // TODO: fix for the v7 docs
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}

Expand Down
46 changes: 44 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 Down Expand Up @@ -101,6 +103,9 @@ import (
"github.com/CosmosContracts/juno/v19/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/CosmosContracts/juno/v19/x/tokenfactory/keeper"
tokenfactorytypes "github.com/CosmosContracts/juno/v19/x/tokenfactory/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"
)

var (
Expand Down Expand Up @@ -169,6 +174,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 +496,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 All @@ -516,9 +522,14 @@ func NewAppKeepers(
"/osmosis.tokenfactory.v1beta1.Query/DenomsFromCreator": &tokenfactorytypes.QueryDenomsFromCreatorResponse{},
}

accepted := make([]string, 0)
for k := range acceptedStargateQueries {
accepted = append(accepted, k)
}

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 +545,14 @@ func NewAppKeepers(

wasmOpts = append(wasmOpts, burnMessageHandler)

// create a shared VM instance
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 +574,29 @@ func NewAppKeepers(
wasmOpts...,
)

// 08-wasm light client
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) // TODO: update in IBC documentation, uses the keeper & ref not types.

appKeepers.WasmClientKeeper = wasmlckeeper.NewKeeperWithVM(
appCodec,
// runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), // TODO: Remove from v7 docs, this is a v8 / SDK v50 thing
appKeepers.keys[evidencetypes.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 @@ -39,6 +39,7 @@ import (
globalfeetypes "github.com/CosmosContracts/juno/v19/x/globalfee/types"
minttypes "github.com/CosmosContracts/juno/v19/x/mint/types"
tokenfactorytypes "github.com/CosmosContracts/juno/v19/x/tokenfactory/types"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

Check failure on line 42 in app/keepers/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -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
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ import (
minttypes "github.com/CosmosContracts/juno/v19/x/mint/types"
"github.com/CosmosContracts/juno/v19/x/tokenfactory"
tokenfactorytypes "github.com/CosmosContracts/juno/v19/x/tokenfactory/types"

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

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -116,6 +119,7 @@ var ModuleBasics = module.NewBasicManager(
packetforward.AppModuleBasic{},
clock.AppModuleBasic{},
cwhooks.AppModuleBasic{},
wasmlc.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -168,6 +172,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 +248,7 @@ func orderBeginBlockers() []string {
ibchookstypes.ModuleName,
clocktypes.ModuleName,
cwhooks.ModuleName,
wasmlctypes.ModuleName,
}
}

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

Expand Down Expand Up @@ -323,5 +330,6 @@ func orderInitBlockers() []string {
ibchookstypes.ModuleName,
clocktypes.ModuleName,
cwhooks.ModuleName,
wasmlctypes.ModuleName,
}
}
6 changes: 6 additions & 0 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
decorators "github.com/CosmosContracts/juno/v19/app/decorators"
"github.com/CosmosContracts/juno/v19/app/keepers"
"github.com/CosmosContracts/juno/v19/app/upgrades"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
)

func CreateV19UpgradeHandler(
Expand Down Expand Up @@ -43,6 +44,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 20e0492

Please sign in to comment.