-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: adding 08-wasm build opts with libwasmvm linking disabled (backp…
…ort #5923) (#6548) * imp: adding 08-wasm build opts with libwasmvm linking disabled (#5923) * wip: messing with build options for wasm cgo * chore: mv type assertion to wasm_cgo with build flags * chore: mv make target to build section * chore: revert cgo enabled 0 build opt for testing * chore: rm unneeded file * update build tag * linter * update panic message * add Codec back * refactor: adapt build tags to match wasmvm * Update modules/light-clients/08-wasm/doc.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update modules/light-clients/08-wasm/keeper/keeper_vm.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: make lint-fix * chore: make lint-fix --------- Co-authored-by: Charly <[email protected]> Co-authored-by: Charly <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cian Hatton <[email protected]> (cherry picked from commit 031c2b8) # Conflicts: # Makefile # modules/light-clients/08-wasm/keeper/keeper.go * chore: resolve merge conflicts from backport * chore: update changelog --------- Co-authored-by: Damian Nolan <[email protected]>
- Loading branch information
1 parent
4ea883f
commit bf158a5
Showing
10 changed files
with
186 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build cgo && !nolink_libwasmvm | ||
|
||
package ibcwasm | ||
|
||
import wasmvm "github.com/CosmWasm/wasmvm/v2" | ||
|
||
var _ WasmEngine = (*wasmvm.VM)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build !cgo || nolink_libwasmvm | ||
|
||
package keeper | ||
|
||
import ( | ||
storetypes "cosmossdk.io/core/store" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
|
||
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/internal/ibcwasm" | ||
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" | ||
) | ||
|
||
// NewKeeperWithVM creates a new Keeper instance with the provided Wasm VM. | ||
// This constructor function is used when binaries are compiled with cgo disabled or the | ||
// custom build directive: nolink_libwasmvm. | ||
// This function is intended to panic and notify users that 08-wasm keeper functionality is not available. | ||
func NewKeeperWithVM( | ||
_ codec.BinaryCodec, | ||
_ storetypes.KVStoreService, | ||
_ types.ClientKeeper, | ||
_ string, | ||
_ ibcwasm.WasmEngine, | ||
_ ibcwasm.QueryRouter, | ||
_ ...Option, | ||
) Keeper { | ||
panic("not implemented, please build with cgo enabled or nolink_libwasmvm disabled") | ||
} | ||
|
||
// NewKeeperWithConfig creates a new Keeper instance with the provided Wasm configuration. | ||
// This constructor function is used when binaries are compiled with cgo disabled or the | ||
// custom build directive: nolink_libwasmvm. | ||
// This function is intended to panic and notify users that 08-wasm keeper functionality is not available. | ||
func NewKeeperWithConfig( | ||
_ codec.BinaryCodec, | ||
_ storetypes.KVStoreService, | ||
_ types.ClientKeeper, | ||
_ string, | ||
_ types.WasmConfig, | ||
_ ibcwasm.QueryRouter, | ||
_ ...Option, | ||
) Keeper { | ||
panic("not implemented, please build with cgo enabled or nolink_libwasmvm disabled") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//go:build cgo && !nolink_libwasmvm | ||
|
||
package keeper | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
wasmvm "github.com/CosmWasm/wasmvm/v2" | ||
|
||
"cosmossdk.io/core/store" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
|
||
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/internal/ibcwasm" | ||
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" | ||
) | ||
|
||
// NewKeeperWithVM creates a new Keeper instance with the provided Wasm VM. | ||
// This constructor function is meant to be used when the chain uses x/wasm | ||
// and the same Wasm VM instance should be shared with it. | ||
func NewKeeperWithVM( | ||
cdc codec.BinaryCodec, | ||
storeService store.KVStoreService, | ||
clientKeeper types.ClientKeeper, | ||
authority string, | ||
vm ibcwasm.WasmEngine, | ||
queryRouter ibcwasm.QueryRouter, | ||
opts ...Option, | ||
) Keeper { | ||
if clientKeeper == nil { | ||
panic(errors.New("client keeper must not be nil")) | ||
} | ||
|
||
if queryRouter == nil { | ||
panic(errors.New("query router must not be nil")) | ||
} | ||
|
||
if vm == nil { | ||
panic(errors.New("wasm VM must not be nil")) | ||
} | ||
|
||
if storeService == nil { | ||
panic(errors.New("store service must not be nil")) | ||
} | ||
|
||
if strings.TrimSpace(authority) == "" { | ||
panic(errors.New("authority must be non-empty")) | ||
} | ||
|
||
keeper := &Keeper{ | ||
cdc: cdc, | ||
storeService: storeService, | ||
clientKeeper: clientKeeper, | ||
authority: authority, | ||
} | ||
|
||
// set query plugins to ensure there is a non-nil query plugin | ||
// regardless of what options the user provides | ||
ibcwasm.SetQueryPlugins(types.NewDefaultQueryPlugins()) | ||
for _, opt := range opts { | ||
opt.apply(keeper) | ||
} | ||
|
||
ibcwasm.SetVM(vm) | ||
ibcwasm.SetQueryRouter(queryRouter) | ||
ibcwasm.SetupWasmStoreService(storeService) | ||
|
||
return *keeper | ||
} | ||
|
||
// NewKeeperWithConfig creates a new Keeper instance with the provided Wasm configuration. | ||
// This constructor function is meant to be used when the chain does not use x/wasm | ||
// and a Wasm VM needs to be instantiated using the provided parameters. | ||
func NewKeeperWithConfig( | ||
cdc codec.BinaryCodec, | ||
storeService store.KVStoreService, | ||
clientKeeper types.ClientKeeper, | ||
authority string, | ||
wasmConfig types.WasmConfig, | ||
queryRouter ibcwasm.QueryRouter, | ||
opts ...Option, | ||
) Keeper { | ||
vm, err := wasmvm.NewVM(wasmConfig.DataDir, wasmConfig.SupportedCapabilities, types.ContractMemoryLimit, wasmConfig.ContractDebugMode, types.MemoryCacheSize) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to instantiate new Wasm VM instance: %v", err)) | ||
} | ||
|
||
return NewKeeperWithVM(cdc, storeService, clientKeeper, authority, vm, queryRouter, opts...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
set -eou pipefail | ||
|
||
# build_wasm_image extracts the correct libwasm version and checksum | ||
# based on the go.mod and builds a docker image with the provided tag. | ||
function build_wasm_image(){ | ||
local version="$(scripts/get-libwasm-version.py --get-version)" | ||
local checksum="$(scripts/get-libwasm-version.py --get-checksum)" | ||
docker build . -t "${1}" -f modules/light-clients/08-wasm/Dockerfile --build-arg LIBWASM_VERSION=${version} --build-arg LIBWASM_CHECKSUM=${checksum} | ||
} | ||
|
||
# default to latest if no tag is specified. | ||
TAG="${1:-ibc-go-wasm-simd:latest}" | ||
|
||
build_wasm_image "${TAG}" |