Skip to content

Commit 93761ea

Browse files
alpewebmaster128
andauthored
Upgrade wasmvm aka go-cosmwasm (#311)
* Upgrade wasmvm aka go-cosmwasm * Update x/wasm/README.md Co-authored-by: Simon Warta <[email protected]> * Review feedback * CircleCI: export GORACE Co-authored-by: Simon Warta <[email protected]>
1 parent cbda602 commit 93761ea

27 files changed

+322
-307
lines changed

.circleci/config.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
executors:
44
golang:
55
docker:
6-
- image: circleci/golang:1.14
6+
- image: circleci/golang:1.15
77
working_directory: /go/src/github.com/cosmwasm/wasmd
88

99
commands:
@@ -71,6 +71,7 @@ jobs:
7171
- run:
7272
name: Run tests with coverage
7373
command: |
74+
export GORACE=halt_on_error=1
7475
export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')"
7576
export GO111MODULE=on
7677
mkdir -p /tmp/logs /tmp/workspace/profiles

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4444
* (wasmd) [\#163](https://github.com/CosmWasm/wasmd/issues/163) Control who can instantiate code
4545
* (wasmd) [\#164](https://github.com/CosmWasm/wasmd/issues/164) Control who can upload code
4646
* (wasmd) [\#173](https://github.com/CosmWasm/wasmd/issues/173) Gov proposal types and handler
47-
* (wasmd) [\#122](https://github.com/CosmWasm/wasmd/pull/122]) Migrate contract backend functionality with go-cosmwasm stub impl
47+
* (wasmd) [\#122](https://github.com/CosmWasm/wasmd/pull/122]) Migrate contract backend functionality with wasmvm stub impl
4848
* (wasmd)[\#2](https://github.com/cosmwasm/wasmd/pull/22) Improve wasm contract queries (all, raw, smart)
4949
* (wasmd) [\#119](https://github.com/cosmwasm/wasmd/pull/119) Add support for the `--inter-block-cache` CLI
5050
flag and configuration.

Dockerfile

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# docker build . -t cosmwasm/wasmd:latest
22
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
3-
FROM cosmwasm/go-ext-builder:0.8.2-alpine AS rust-builder
3+
FROM cosmwasm/go-ext-builder:0002-alpine AS rust-builder
44

55
RUN apk add git
66

@@ -9,17 +9,16 @@ WORKDIR /code
99
COPY go.* /code/
1010

1111
# download all deps
12-
RUN go mod download github.com/CosmWasm/go-cosmwasm
12+
RUN go mod download github.com/CosmWasm/wasmvm
1313

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

2120
# --------------------------------------------------------
22-
FROM cosmwasm/go-ext-builder:0.8.2-alpine AS go-builder
21+
FROM cosmwasm/go-ext-builder:0002-alpine AS go-builder
2322

2423
RUN apk add git
2524
# NOTE: add these to run with LEDGER_ENABLED=true
@@ -28,7 +27,7 @@ RUN apk add git
2827
WORKDIR /code
2928
COPY . /code/
3029

31-
COPY --from=rust-builder /lib/libgo_cosmwasm_muslc.a /lib/libgo_cosmwasm_muslc.a
30+
COPY --from=rust-builder /lib/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
3231

3332
# force it to use static lib (from above) not standard libgo_cosmwasm.so file
3433
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build

Dockerfile.old

-39
This file was deleted.

INTEGRATION.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ hardware it runs on.
1919

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

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

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ addition of the `x/wasm` module.
1717

1818
## Supported Systems
1919

20-
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**.
20+
The supported systems are limited by the dlls created in [`wasmvm`](https://github.com/CosmWasm/wasmvm). In particular, **we only support MacOS and Linux**.
2121
For linux, the default is to build for glibc, and we cross-compile with CentOS 7 to provide
2222
backwards compatibility for `glibc 2.12+`. This includes all known supported distributions
2323
using glibc (CentOS 7 uses 2.12, obsolete Debian Jessy uses 2.19).

app/app.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/gorilla/mux"
1111
"github.com/rakyll/statik/fs"
1212
"github.com/spf13/cast"
13-
"github.com/spf13/viper"
1413
abci "github.com/tendermint/tendermint/abci/types"
1514
tmjson "github.com/tendermint/tendermint/libs/json"
1615
"github.com/tendermint/tendermint/libs/log"
@@ -240,12 +239,6 @@ type WasmApp struct {
240239
sm *module.SimulationManager
241240
}
242241

243-
// WasmWrapper allows us to use namespacing in the config file
244-
// This is only used for parsing in the app, x/wasm expects WasmConfig
245-
type WasmWrapper struct {
246-
Wasm wasm.Config `mapstructure:"wasm"`
247-
}
248-
249242
// NewWasmApp returns a reference to an initialized WasmApp.
250243
func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
251244
skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, enabledProposals []wasm.ProposalType,
@@ -358,13 +351,10 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
358351
var wasmRouter = bApp.Router()
359352
wasmDir := filepath.Join(homePath, "wasm")
360353

361-
wasmWrap := WasmWrapper{Wasm: wasm.DefaultWasmConfig()}
362-
err := viper.Unmarshal(&wasmWrap)
354+
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
363355
if err != nil {
364356
panic("error while reading wasm config: " + err.Error())
365357
}
366-
wasmConfig := wasmWrap.Wasm
367-
368358
// The last arguments can contain custom message handlers, and custom query handlers,
369359
// if we want to allow any custom callbacks
370360
supportedFeatures := "staking"

cmd/wasmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88

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

116117
func addModuleInitFlags(startCmd *cobra.Command) {
117118
crisis.AddModuleInitFlags(startCmd)
119+
wasm.AddModuleInitFlags(startCmd)
118120
}
119121

120122
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {

contrib/local/02-contracts.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo "$RESP"
3333
echo "### Query smart"
3434
wasmcli query wasm contract-state smart "$CONTRACT" '{"verifier":{}}' -o json | jq
3535
echo "### Query raw"
36-
KEY=$(echo "$RESP" | jq -r ".[0].Key")
36+
KEY=$(echo "$RESP" | jq -r ".[0].key")
3737
wasmcli query wasm contract-state raw "$CONTRACT" "$KEY" -o json
3838

3939

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
33
go 1.15
44

55
require (
6-
github.com/CosmWasm/go-cosmwasm v0.11.0
6+
github.com/CosmWasm/wasmvm v0.12.0-alpha1
77
github.com/cosmos/cosmos-sdk v0.40.0-rc3
88
github.com/cosmos/iavl v0.15.0-rc4
99
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
1818
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
1919
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
2020
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
21-
github.com/CosmWasm/go-cosmwasm v0.11.0 h1:H+7Xzh2tEquJXuP4q1VN7ekdheAQvCjD4FRmlPqcXnQ=
22-
github.com/CosmWasm/go-cosmwasm v0.11.0/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
21+
github.com/CosmWasm/wasmvm v0.12.0-alpha1 h1:UPaemjM+O/9uQRDCiExXPpcUlMJ5Zo8N/BUvqjheb5A=
22+
github.com/CosmWasm/wasmvm v0.12.0-alpha1/go.mod h1:tbXGE9Jz6sYpiJroGr71OQ5TFOufq/P5LWsruA2u6JE=
2323
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
2424
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
2525
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=

x/wasm/IBC.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Packet callbacks:
183183
```go
184184
package packets
185185

186-
// for reference: this is more like what we pass to go-cosmwasm
186+
// for reference: this is more like what we pass to wasmvm
187187
// func (c *mockContract) OnReceive(params cosmwasm2.Env, msg []byte, store prefix.Store, api cosmwasm.GoAPI,
188188
// querier keeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasm2.OnReceiveIBCResponse, uint64, error) {}
189189
// below is how we want to expose it in x/wasm:

x/wasm/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ This should be a brief overview of the functionality
44

55
## Configuration
66

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

99
```toml
1010
[wasm]
1111
# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
1212
query_gas_limit = 300000
13-
# This is the number of wasm vm instances we keep cached in memory for speed-up
14-
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
15-
lru_size = 0
13+
# This defines the memory size for Wasm modules that we can keep cached to speed-up instantiation
14+
# The value is in MiB not bytes
15+
memory_cache_size = 300
16+
```
17+
18+
The values can also be set via CLI flags on with the `start` command:
19+
```shell script
20+
--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)
21+
--wasm.query_gas_limit uint Set the max gas that can be spent on executing a query with a Wasm contract (default 3000000)
1622
```
1723

1824
## Events

x/wasm/genesis_test.go

+1-47
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
type contractState struct {
12-
}
13-
1411
func TestInitGenesis(t *testing.T) {
1512
data := setupTest(t)
1613

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

25-
t.Log("fail with invalid source url")
2622
msg := MsgStoreCode{
27-
Sender: creator,
28-
WASMByteCode: testContract,
29-
Source: "someinvalidurl",
30-
Builder: "",
31-
}
32-
33-
err := msg.ValidateBasic()
34-
require.Error(t, err)
35-
36-
_, err = h(data.ctx, &msg)
37-
require.Error(t, err)
38-
39-
t.Log("fail with relative source url")
40-
msg = MsgStoreCode{
41-
Sender: creator,
42-
WASMByteCode: testContract,
43-
Source: "./testdata/escrow.wasm",
44-
Builder: "",
45-
}
46-
47-
err = msg.ValidateBasic()
48-
require.Error(t, err)
49-
50-
_, err = h(data.ctx, &msg)
51-
require.Error(t, err)
52-
53-
t.Log("fail with invalid build tag")
54-
msg = MsgStoreCode{
55-
Sender: creator,
56-
WASMByteCode: testContract,
57-
Source: "",
58-
Builder: "somerandombuildtag-0.6.2",
59-
}
60-
61-
err = msg.ValidateBasic()
62-
require.Error(t, err)
63-
64-
_, err = h(data.ctx, &msg)
65-
require.Error(t, err)
66-
67-
t.Log("no error with valid source and build tag")
68-
msg = MsgStoreCode{
6923
Sender: creator,
7024
WASMByteCode: testContract,
7125
Source: "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm",
7226
Builder: "confio/cosmwasm-opt:0.7.0",
7327
}
74-
err = msg.ValidateBasic()
28+
err := msg.ValidateBasic()
7529
require.NoError(t, err)
7630

7731
res, err := h(data.ctx, &msg)

x/wasm/internal/keeper/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package keeper
22

33
import (
44
"fmt"
5-
cosmwasm "github.com/CosmWasm/go-cosmwasm"
5+
wasmvm "github.com/CosmWasm/wasmvm"
66
sdk "github.com/cosmos/cosmos-sdk/types"
77
)
88

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

26-
var cosmwasmAPI = cosmwasm.GoAPI{
26+
var cosmwasmAPI = wasmvm.GoAPI{
2727
HumanAddress: humanAddress,
2828
CanonicalAddress: canonicalAddress,
2929
}

0 commit comments

Comments
 (0)