Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tung/add wasm client wasmvm v2.0.0 #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM golang:1.21-alpine3.18 as builder

ARG LIBWASM_VERSION
ARG LIBWASM_CHECKSUM

RUN test -n "${LIBWASM_VERSION}"
RUN test -n "${LIBWASM_CHECKSUM}"

RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make;

ENV GOPATH=""

# Grab the static library and copy it to location that will be found by the linker flag `-lwasmvm_muslc`.
ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep ${LIBWASM_CHECKSUM}
RUN cp /lib/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloading and verifying the libwasmvm_muslc.x86_64.a library directly from GitHub ensures that the specific version of wasmvm is used. This is a secure practice as it uses checksum verification. However, consider handling potential download failures or checksum mismatches more gracefully.


# Copy relevant files before go mod download. Replace directives to local paths break if local
# files are not copied before go mod download.
ADD internal internal
ADD testing testing
ADD modules modules
ADD LICENSE LICENSE

COPY go.mod .
COPY go.sum .

WORKDIR /go/modules/light-clients/08-wasm

RUN go mod download

RUN GOOS=linux GOARCH=amd64 go build -mod=readonly -tags "netgo ledger muslc" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=sim -X github.com/cosmos/cosmos-sdk/version.AppName=simd -X github.com/cosmos/cosmos-sdk/version.Version= -X github.com/cosmos/cosmos-sdk/version.Commit= -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo ledger muslc," -w -s -linkmode=external -extldflags "-Wl,-z,muldefs -static"' -trimpath -o /go/build/ ./...

FROM alpine:3.18

COPY --from=builder /go/build/simd /bin/simd

ENTRYPOINT ["simd"]
55 changes: 53 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
"sort"
"sync"

wasmvm "github.com/CosmWasm/wasmvm/v2"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
wasm08 "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
wasm08keeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
wasm08types "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -146,6 +150,12 @@ import (

const appName = "EveApp"

const (
// ContractMemoryLimit is the memory limit of each contract execution (in MiB)
// constant value so all nodes run with the same limit.
ContractMemoryLimit = uint32(32)
)

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".eved"
Expand Down Expand Up @@ -235,6 +245,7 @@ type EveApp struct {
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
Wasm08Keeper wasm08keeper.Keeper
WasmKeeper wasmkeeper.Keeper
ConsumerKeeper ccvconsumerkeeper.Keeper

Expand Down Expand Up @@ -309,7 +320,7 @@ func NewEveApp(
group.StoreKey,
// non sdk store keys
capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasmtypes.StoreKey, icahosttypes.StoreKey,
wasm08types.StoreKey, wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, tokenfactorytypes.StoreKey,
)

Expand Down Expand Up @@ -492,6 +503,37 @@ func NewEveApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

wasmDir := filepath.Join(homePath, "wasm")
wasmer, err := wasmvm.NewVM(
wasmDir,
AllCapabilities(),
ContractMemoryLimit,
wasmtypes.DefaultWasmConfig().ContractDebugMode,
wasmtypes.DefaultWasmConfig().MemoryCacheSize,
)
if err != nil {
panic(err)
}

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
&app.ConsumerKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.Wasm08Keeper = wasm08keeper.NewKeeperWithVM(
appCodec,
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmer,
bApp.GRPCQueryRouter(),
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
Expand Down Expand Up @@ -636,7 +678,6 @@ func NewEveApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
Expand Down Expand Up @@ -735,6 +776,7 @@ func NewEveApp(
circuit.NewAppModule(appCodec, app.CircuitKeeper),
// non sdk modules
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
wasm08.NewAppModule(app.Wasm08Keeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
Expand All @@ -760,6 +802,8 @@ func NewEveApp(
paramsclient.ProposalHandler,
},
),
// wasm08types.ModuleName: wasm08.AppModuleBasic{},
// wasmtypes.ModuleName: wasm.AppModuleBasic{},
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -790,6 +834,7 @@ func NewEveApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasm08types.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
)
Expand All @@ -808,6 +853,7 @@ func NewEveApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasm08types.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
)
Expand Down Expand Up @@ -848,6 +894,7 @@ func NewEveApp(
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasm08types.ModuleName,
// wasm after ibc transfer
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
Expand Down Expand Up @@ -909,6 +956,7 @@ func NewEveApp(
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
wasm08keeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.Wasm08Keeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
Expand Down Expand Up @@ -947,6 +995,9 @@ func NewEveApp(
if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
panic(fmt.Sprintf("failed initialize pinned codes %s", err))
}
// if err := wasm08keeper.InitializePinnedCodes(ctx); err != nil {
// panic(fmt.Sprintf("failed initialize pinned codes %s", err))
// }
}

return app
Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/CosmWasm/wasmd v0.51.0-rc.1
github.com/CosmWasm/wasmvm/v2 v2.0.0-rc.2 // indirect
github.com/CosmWasm/wasmvm/v2 v2.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect
github.com/cosmos/cosmos-sdk v0.50.5
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand All @@ -26,7 +26,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/grpc v1.62.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

Expand All @@ -48,6 +48,7 @@ require (
github.com/cometbft/cometbft v0.38.5
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc
github.com/cosmos/ibc-go/v8 v8.1.0
github.com/osmosis-labs/tokenfactory v0.0.0-20240310155926-981fbeb0fe42
github.com/spf13/viper v1.18.2
Expand Down Expand Up @@ -130,7 +131,7 @@ require (
github.com/hashicorp/go-getter v1.7.3 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.2 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand Down Expand Up @@ -217,8 +218,8 @@ replace (
// core v0.12 was tagged wrong (sdk51)
cosmossdk.io/core => cosmossdk.io/core v0.11.0
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/cosmos/interchain-security => /Users/hoank/resource/notional/interchain-security

github.com/cosmos/ibc-go/modules/light-clients/08-wasm => github.com/notional-labs/ibc-go/modules/light-clients/08-wasm v0.0.0-20240314043527-f53cabfd50c0
// github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240310203317-cf4b9b9ad758
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// See: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
Expand Down
Loading
Loading