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

Upgrade wasmvm aka go-cosmwasm #311

Merged
merged 4 commits into from
Nov 17, 2020
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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
golang:
docker:
- image: circleci/golang:1.14
- image: circleci/golang:1.15
working_directory: /go/src/github.com/cosmwasm/wasmd

commands:
Expand Down Expand Up @@ -71,6 +71,7 @@ jobs:
- run:
name: Run tests with coverage
command: |
export GORACE=halt_on_error=1
export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')"
export GO111MODULE=on
mkdir -p /tmp/logs /tmp/workspace/profiles
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (wasmd) [\#163](https://github.com/CosmWasm/wasmd/issues/163) Control who can instantiate code
* (wasmd) [\#164](https://github.com/CosmWasm/wasmd/issues/164) Control who can upload code
* (wasmd) [\#173](https://github.com/CosmWasm/wasmd/issues/173) Gov proposal types and handler
* (wasmd) [\#122](https://github.com/CosmWasm/wasmd/pull/122]) Migrate contract backend functionality with go-cosmwasm stub impl
* (wasmd) [\#122](https://github.com/CosmWasm/wasmd/pull/122]) Migrate contract backend functionality with wasmvm stub impl
* (wasmd)[\#2](https://github.com/cosmwasm/wasmd/pull/22) Improve wasm contract queries (all, raw, smart)
* (wasmd) [\#119](https://github.com/cosmwasm/wasmd/pull/119) Add support for the `--inter-block-cache` CLI
flag and configuration.
Expand Down
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM cosmwasm/go-ext-builder:0.8.2-alpine AS rust-builder
FROM cosmwasm/go-ext-builder:0002-alpine AS rust-builder

RUN apk add git

Expand All @@ -9,17 +9,16 @@ WORKDIR /code
COPY go.* /code/

# download all deps
RUN go mod download github.com/CosmWasm/go-cosmwasm
RUN go mod download github.com/CosmWasm/wasmvm

# build go-cosmwasm *.a and install it
RUN export GO_WASM_DIR=$(go list -f "{{ .Dir }}" -m github.com/CosmWasm/go-cosmwasm) && \
# build wasmvm *.a and install it
RUN export GO_WASM_DIR=$(go list -f "{{ .Dir }}" -m github.com/CosmWasm/wasmvm) && \
cd ${GO_WASM_DIR} && \
cargo build --release --features backtraces --example muslc && \
mv ${GO_WASM_DIR}/target/release/examples/libmuslc.a /lib/libgo_cosmwasm_muslc.a

mv ${GO_WASM_DIR}/target/release/examples/libmuslc.a /lib/libwasmvm_muslc.a

# --------------------------------------------------------
FROM cosmwasm/go-ext-builder:0.8.2-alpine AS go-builder
FROM cosmwasm/go-ext-builder:0002-alpine AS go-builder

RUN apk add git
# NOTE: add these to run with LEDGER_ENABLED=true
Expand All @@ -28,7 +27,7 @@ RUN apk add git
WORKDIR /code
COPY . /code/

COPY --from=rust-builder /lib/libgo_cosmwasm_muslc.a /lib/libgo_cosmwasm_muslc.a
COPY --from=rust-builder /lib/libwasmvm_muslc.a /lib/libwasmvm_muslc.a

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build
Expand Down
39 changes: 0 additions & 39 deletions Dockerfile.old

This file was deleted.

8 changes: 4 additions & 4 deletions INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ hardware it runs on.

We currently only support Intel/AMD64 CPUs and OSX or Linux. For Linux, the standard build
commands work for `glibc` systems (Ubuntu, Debian, CentOS, etc). If you wish to compile
for a `muslc` based system (like alpine), you need to compile a static library go-cosmwasm locally
for a `muslc` based system (like alpine), you need to compile a static library wasmvm locally
and compile go with the `muslc` build tag. Or just use the [Dockerfile](./Dockerfile),
which builds a static go binary in an alpine system.

This limit comes from the Rust dll we use to run the wasm code, which comes
from [`go-cosmwasm`](https://github.com/CosmWasm/go-cosmwasm). There are open issues
for adding [ARM support](https://github.com/CosmWasm/go-cosmwasm/issues/53), and
adding [Windows support](https://github.com/CosmWasm/go-cosmwasm/issues/28).
from [`wasmvm`](https://github.com/CosmWasm/wasmvm). There are open issues
for adding [ARM support](https://github.com/CosmWasm/wasmvm/issues/53), and
adding [Windows support](https://github.com/CosmWasm/wasmvm/issues/28).
However, these issues are not high on the roadmap and unless you are championing
them, please count on the current limits for the near future.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ addition of the `x/wasm` module.

## Supported Systems

The supported systems are limited by the dlls created in [`go-cosmwasm`](https://github.com/CosmWasm/go-cosmwasm). In particular, **we only support MacOS and Linux**.
The supported systems are limited by the dlls created in [`wasmvm`](https://github.com/CosmWasm/wasmvm). In particular, **we only support MacOS and Linux**.
For linux, the default is to build for glibc, and we cross-compile with CentOS 7 to provide
backwards compatibility for `glibc 2.12+`. This includes all known supported distributions
using glibc (CentOS 7 uses 2.12, obsolete Debian Jessy uses 2.19).
Expand Down
12 changes: 1 addition & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -240,12 +239,6 @@ type WasmApp struct {
sm *module.SimulationManager
}

// WasmWrapper allows us to use namespacing in the config file
// This is only used for parsing in the app, x/wasm expects WasmConfig
type WasmWrapper struct {
Wasm wasm.Config `mapstructure:"wasm"`
}

// NewWasmApp returns a reference to an initialized WasmApp.
func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, enabledProposals []wasm.ProposalType,
Expand Down Expand Up @@ -358,13 +351,10 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
var wasmRouter = bApp.Router()
wasmDir := filepath.Join(homePath, "wasm")

wasmWrap := WasmWrapper{Wasm: wasm.DefaultWasmConfig()}
err := viper.Unmarshal(&wasmWrap)
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
}
wasmConfig := wasmWrap.Wasm

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "staking"
Expand Down
2 changes: 2 additions & 0 deletions cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcli "github.com/tendermint/tendermint/libs/cli"
Expand Down Expand Up @@ -115,6 +116,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
wasm.AddModuleInitFlags(startCmd)
alpe marked this conversation as resolved.
Show resolved Hide resolved
}

func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
Expand Down
2 changes: 1 addition & 1 deletion contrib/local/02-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "$RESP"
echo "### Query smart"
wasmcli query wasm contract-state smart "$CONTRACT" '{"verifier":{}}' -o json | jq
echo "### Query raw"
KEY=$(echo "$RESP" | jq -r ".[0].Key")
KEY=$(echo "$RESP" | jq -r ".[0].key")
wasmcli query wasm contract-state raw "$CONTRACT" "$KEY" -o json


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
go 1.15

require (
github.com/CosmWasm/go-cosmwasm v0.11.0
github.com/CosmWasm/wasmvm v0.12.0-alpha1
github.com/cosmos/cosmos-sdk v0.40.0-rc3
github.com/cosmos/iavl v0.15.0-rc4
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/go-cosmwasm v0.11.0 h1:H+7Xzh2tEquJXuP4q1VN7ekdheAQvCjD4FRmlPqcXnQ=
github.com/CosmWasm/go-cosmwasm v0.11.0/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/wasmvm v0.12.0-alpha1 h1:UPaemjM+O/9uQRDCiExXPpcUlMJ5Zo8N/BUvqjheb5A=
github.com/CosmWasm/wasmvm v0.12.0-alpha1/go.mod h1:tbXGE9Jz6sYpiJroGr71OQ5TFOufq/P5LWsruA2u6JE=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/IBC.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Packet callbacks:
```go
package packets

// for reference: this is more like what we pass to go-cosmwasm
// for reference: this is more like what we pass to wasmvm
// func (c *mockContract) OnReceive(params cosmwasm2.Env, msg []byte, store prefix.Store, api cosmwasm.GoAPI,
// querier keeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasm2.OnReceiveIBCResponse, uint64, error) {}
// below is how we want to expose it in x/wasm:
Expand Down
14 changes: 10 additions & 4 deletions x/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ This should be a brief overview of the functionality

## Configuration

You can add the following section to `config/app.toml`. Below is shown with defaults:
You can add the following section to `config/app.toml`:

```toml
[wasm]
# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
query_gas_limit = 300000
# This is the number of wasm vm instances we keep cached in memory for speed-up
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
lru_size = 0
# This defines the memory size for Wasm modules that we can keep cached to speed-up instantiation
# The value is in MiB not bytes
memory_cache_size = 300
```

The values can also be set via CLI flags on with the `start` command:
```shell script
--wasm.memory_cache_size uint32 Sets the size in MiB (NOT bytes) of an in-memory cache for wasm modules. Set to 0 to disable. (default 100)
--wasm.query_gas_limit uint Set the max gas that can be spent on executing a query with a Wasm contract (default 3000000)
```

## Events
Expand Down
48 changes: 1 addition & 47 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"github.com/stretchr/testify/require"
)

type contractState struct {
}

func TestInitGenesis(t *testing.T) {
data := setupTest(t)

Expand All @@ -22,56 +19,13 @@ func TestInitGenesis(t *testing.T) {
h := data.module.Route().Handler()
q := data.module.LegacyQuerierHandler(nil)

t.Log("fail with invalid source url")
msg := MsgStoreCode{
Sender: creator,
WASMByteCode: testContract,
Source: "someinvalidurl",
Builder: "",
}

err := msg.ValidateBasic()
require.Error(t, err)

_, err = h(data.ctx, &msg)
require.Error(t, err)

t.Log("fail with relative source url")
msg = MsgStoreCode{
Sender: creator,
WASMByteCode: testContract,
Source: "./testdata/escrow.wasm",
Builder: "",
}

err = msg.ValidateBasic()
require.Error(t, err)

_, err = h(data.ctx, &msg)
require.Error(t, err)

t.Log("fail with invalid build tag")
msg = MsgStoreCode{
Sender: creator,
WASMByteCode: testContract,
Source: "",
Builder: "somerandombuildtag-0.6.2",
}

err = msg.ValidateBasic()
require.Error(t, err)

_, err = h(data.ctx, &msg)
require.Error(t, err)

t.Log("no error with valid source and build tag")
msg = MsgStoreCode{
Sender: creator,
WASMByteCode: testContract,
Source: "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm",
Builder: "confio/cosmwasm-opt:0.7.0",
}
err = msg.ValidateBasic()
err := msg.ValidateBasic()
require.NoError(t, err)

res, err := h(data.ctx, &msg)
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/keeper/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

import (
"fmt"
cosmwasm "github.com/CosmWasm/go-cosmwasm"
wasmvm "github.com/CosmWasm/wasmvm"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -23,7 +23,7 @@ func canonicalAddress(human string) ([]byte, uint64, error) {
return bz, CostCanonical, err
}

var cosmwasmAPI = cosmwasm.GoAPI{
var cosmwasmAPI = wasmvm.GoAPI{
HumanAddress: humanAddress,
CanonicalAddress: canonicalAddress,
}
Loading