Skip to content

Commit

Permalink
Use different wasm VMs for standalone and the LC (#946)
Browse files Browse the repository at this point in the history
* remove double `InitializePinnedCodes` since wasmkeeper already does it

* attmpt 2

* re-add NewWasmSnapshotter and InitializePinnedCodes

* new `lcWasmer`

* wasmvm v1.5.2

* fix upgrade

* ictest mod tidy
  • Loading branch information
Reecepbcups committed Jan 20, 2024
1 parent 55ec22a commit 168e76d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
16 changes: 7 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ 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),
// https://github.com/cosmos/ibc-go/pull/5439
wasmlckeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmClientKeeper),
)
if err != nil {
Expand Down Expand Up @@ -442,18 +442,16 @@ func New(
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})

// 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))
tmos.Exit(fmt.Sprintf("wasmlckeeper failed initialize pinned codes %s", err))
}

// we already load in with the wasmlc (all)
// if err := app.AppKeepers.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
// tmos.Exit(fmt.Sprintf("app.AppKeepers.WasmKeeper 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
17 changes: 9 additions & 8 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ func NewAppKeepers(
)

wasmDir := filepath.Join(homePath, "data")
lcWasmDir := filepath.Join(homePath, "data", "light-client-wasm")

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -541,13 +542,15 @@ 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)
mainWasmer, 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))
lcWasmer, err := wasmvm.NewVM(lcWasmDir, wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize)
if err != nil {
panic(fmt.Sprintf("failed to create juno wasm vm for 08-wasm: %s", err))
}

appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
Expand All @@ -567,7 +570,7 @@ func NewAppKeepers(
wasmConfig,
wasmCapabilities,
govModAddress,
wasmOpts...,
append(wasmOpts, wasmkeeper.WithWasmEngine(mainWasmer))...,
)

// 08-wasm light client
Expand All @@ -585,16 +588,14 @@ func NewAppKeepers(
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,
lcWasmer,
bApp.GRPCQueryRouter(),
wasmQuerierOption,
wasmlckeeper.WithQueryPlugins(&wasmLightClientQuerier),
)

appKeepers.FeePayKeeper = feepaykeeper.NewKeeper(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
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.2-rc.0
github.com/CosmWasm/wasmvm v1.5.2
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQ
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/wasmd v0.45.0 h1:9zBqrturKJwC2kVsfHvbrA++EN0PS7UTXCffCGbg6JI=
github.com/CosmWasm/wasmd v0.45.0/go.mod h1:RnSAiqbNIZu4QhO+0pd7qGZgnYAMBPGmXpzTADag944=
github.com/CosmWasm/wasmvm v1.5.2-rc.0 h1:pbW8vBlz7Qb+Ghjd5ia4uqaXKeBu3YumZ/2DKVKv4e4=
github.com/CosmWasm/wasmvm v1.5.2-rc.0/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag=
github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down
2 changes: 1 addition & 1 deletion interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000 // indirect
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
github.com/CosmWasm/wasmvm v1.5.2-rc.0 // indirect
github.com/CosmWasm/wasmvm v1.5.2 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 h1:oknQF/iIhf5lVjbwjsVDzDByu
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420/go.mod h1:KYkiMX5AbOlXXYfxkrYPrRPV6EbVUALTQh5ptUOJzu8=
github.com/CosmWasm/wasmd v0.45.0 h1:9zBqrturKJwC2kVsfHvbrA++EN0PS7UTXCffCGbg6JI=
github.com/CosmWasm/wasmd v0.45.0/go.mod h1:RnSAiqbNIZu4QhO+0pd7qGZgnYAMBPGmXpzTADag944=
github.com/CosmWasm/wasmvm v1.5.2-rc.0 h1:pbW8vBlz7Qb+Ghjd5ia4uqaXKeBu3YumZ/2DKVKv4e4=
github.com/CosmWasm/wasmvm v1.5.2-rc.0/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag=
github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
Expand Down

0 comments on commit 168e76d

Please sign in to comment.