Skip to content

Commit

Permalink
Upgrade wasmvm aka go-cosmwasm
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Nov 12, 2020
1 parent cbda602 commit d22a567
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 195 deletions.
13 changes: 6 additions & 7 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) && \
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
6 changes: 3 additions & 3 deletions INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ and compile go with the `muslc` build tag. Or just use the [Dockerfile](./Docker
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 [`go-cosmwasm`](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 [`go-cosmwasm`](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
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
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,
}
22 changes: 11 additions & 11 deletions x/wasm/internal/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"

wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -26,10 +26,10 @@ func NewMessageHandler(router sdk.Router, customEncoders *MessageEncoders) Messa
}
}

type BankEncoder func(sender sdk.AccAddress, msg *wasmTypes.BankMsg) ([]sdk.Msg, error)
type BankEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)
type CustomEncoder func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
type StakingEncoder func(sender sdk.AccAddress, msg *wasmTypes.StakingMsg) ([]sdk.Msg, error)
type WasmEncoder func(sender sdk.AccAddress, msg *wasmTypes.WasmMsg) ([]sdk.Msg, error)
type StakingEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
type WasmEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)

type MessageEncoders struct {
Bank BankEncoder
Expand Down Expand Up @@ -66,7 +66,7 @@ func (e MessageEncoders) Merge(o *MessageEncoders) MessageEncoders {
return e
}

func (e MessageEncoders) Encode(contractAddr sdk.AccAddress, msg wasmTypes.CosmosMsg) ([]sdk.Msg, error) {
func (e MessageEncoders) Encode(contractAddr sdk.AccAddress, msg wasmvmtypes.CosmosMsg) ([]sdk.Msg, error) {
switch {
case msg.Bank != nil:
return e.Bank(contractAddr, msg.Bank)
Expand All @@ -80,7 +80,7 @@ func (e MessageEncoders) Encode(contractAddr sdk.AccAddress, msg wasmTypes.Cosmo
return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown variant of Wasm")
}

func EncodeBankMsg(sender sdk.AccAddress, msg *wasmTypes.BankMsg) ([]sdk.Msg, error) {
func EncodeBankMsg(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error) {
if msg.Send == nil {
return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown variant of Bank")
}
Expand All @@ -103,7 +103,7 @@ func NoCustomMsg(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Custom variant not supported")
}

func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmTypes.StakingMsg) ([]sdk.Msg, error) {
func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error) {
switch {
case msg.Delegate != nil:
coin, err := convertWasmCoinToSdkCoin(msg.Delegate.Amount)
Expand Down Expand Up @@ -160,7 +160,7 @@ func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmTypes.StakingMsg) ([]sdk.M
}
}

func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmTypes.WasmMsg) ([]sdk.Msg, error) {
func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error) {
switch {
case msg.Execute != nil:
contractAddr, err := sdk.AccAddressFromBech32(msg.Execute.ContractAddr)
Expand Down Expand Up @@ -199,7 +199,7 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmTypes.WasmMsg) ([]sdk.Msg, er
}
}

func (h MessageHandler) Dispatch(ctx sdk.Context, contractAddr sdk.AccAddress, msg wasmTypes.CosmosMsg) error {
func (h MessageHandler) Dispatch(ctx sdk.Context, contractAddr sdk.AccAddress, msg wasmvmtypes.CosmosMsg) error {
sdkMsgs, err := h.encoders.Encode(contractAddr, msg)
if err != nil {
return err
Expand Down Expand Up @@ -243,7 +243,7 @@ func (h MessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Addre
return nil
}

func convertWasmCoinsToSdkCoins(coins []wasmTypes.Coin) (sdk.Coins, error) {
func convertWasmCoinsToSdkCoins(coins []wasmvmtypes.Coin) (sdk.Coins, error) {
var toSend sdk.Coins
for _, coin := range coins {
c, err := convertWasmCoinToSdkCoin(coin)
Expand All @@ -255,7 +255,7 @@ func convertWasmCoinsToSdkCoins(coins []wasmTypes.Coin) (sdk.Coins, error) {
return toSend, nil
}

func convertWasmCoinToSdkCoin(coin wasmTypes.Coin) (sdk.Coin, error) {
func convertWasmCoinToSdkCoin(coin wasmvmtypes.Coin) (sdk.Coin, error) {
amount, ok := sdk.NewIntFromString(coin.Amount)
if !ok {
return sdk.Coin{}, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, coin.Amount+coin.Denom)
Expand Down
92 changes: 46 additions & 46 deletions x/wasm/internal/keeper/handler_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"testing"

wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand All @@ -28,20 +28,20 @@ func TestEncoding(t *testing.T) {

cases := map[string]struct {
sender sdk.AccAddress
input wasmTypes.CosmosMsg
input wasmvmtypes.CosmosMsg
// set if valid
output []sdk.Msg
// set if invalid
isError bool
}{
"simple send": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
FromAddress: addr1.String(),
ToAddress: addr2.String(),
Amount: []wasmTypes.Coin{
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Amount: "12345",
Expand All @@ -67,12 +67,12 @@ func TestEncoding(t *testing.T) {
},
"invalid send amount": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
FromAddress: addr1.String(),
ToAddress: addr2.String(),
Amount: []wasmTypes.Coin{
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Amount: "123.456",
Expand All @@ -85,12 +85,12 @@ func TestEncoding(t *testing.T) {
},
"invalid address": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
FromAddress: addr1.String(),
ToAddress: invalidAddr,
Amount: []wasmTypes.Coin{
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Amount: "7890",
Expand All @@ -112,13 +112,13 @@ func TestEncoding(t *testing.T) {
},
"wasm execute": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Wasm: &wasmTypes.WasmMsg{
Execute: &wasmTypes.ExecuteMsg{
input: wasmvmtypes.CosmosMsg{
Wasm: &wasmvmtypes.WasmMsg{
Execute: &wasmvmtypes.ExecuteMsg{
ContractAddr: addr2.String(),
Msg: jsonMsg,
Send: []wasmTypes.Coin{
wasmTypes.NewCoin(12, "eth"),
Send: []wasmvmtypes.Coin{
wasmvmtypes.NewCoin(12, "eth"),
},
},
},
Expand All @@ -134,13 +134,13 @@ func TestEncoding(t *testing.T) {
},
"wasm instantiate": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Wasm: &wasmTypes.WasmMsg{
Instantiate: &wasmTypes.InstantiateMsg{
input: wasmvmtypes.CosmosMsg{
Wasm: &wasmvmtypes.WasmMsg{
Instantiate: &wasmvmtypes.InstantiateMsg{
CodeID: 7,
Msg: jsonMsg,
Send: []wasmTypes.Coin{
wasmTypes.NewCoin(123, "eth"),
Send: []wasmvmtypes.Coin{
wasmvmtypes.NewCoin(123, "eth"),
},
},
},
Expand All @@ -158,11 +158,11 @@ func TestEncoding(t *testing.T) {
},
"staking delegate": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Delegate: &wasmTypes.DelegateMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Delegate: &wasmvmtypes.DelegateMsg{
Validator: valAddr.String(),
Amount: wasmTypes.NewCoin(777, "stake"),
Amount: wasmvmtypes.NewCoin(777, "stake"),
},
},
},
Expand All @@ -176,11 +176,11 @@ func TestEncoding(t *testing.T) {
},
"staking delegate to non-validator": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Delegate: &wasmTypes.DelegateMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Delegate: &wasmvmtypes.DelegateMsg{
Validator: addr2.String(),
Amount: wasmTypes.NewCoin(777, "stake"),
Amount: wasmvmtypes.NewCoin(777, "stake"),
},
},
},
Expand All @@ -195,11 +195,11 @@ func TestEncoding(t *testing.T) {
},
"staking undelegate": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Undelegate: &wasmTypes.UndelegateMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Undelegate: &wasmvmtypes.UndelegateMsg{
Validator: valAddr.String(),
Amount: wasmTypes.NewCoin(555, "stake"),
Amount: wasmvmtypes.NewCoin(555, "stake"),
},
},
},
Expand All @@ -213,12 +213,12 @@ func TestEncoding(t *testing.T) {
},
"staking redelegate": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Redelegate: &wasmTypes.RedelegateMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Redelegate: &wasmvmtypes.RedelegateMsg{
SrcValidator: valAddr.String(),
DstValidator: valAddr2.String(),
Amount: wasmTypes.NewCoin(222, "stake"),
Amount: wasmvmtypes.NewCoin(222, "stake"),
},
},
},
Expand All @@ -233,9 +233,9 @@ func TestEncoding(t *testing.T) {
},
"staking withdraw (implicit recipient)": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Withdraw: &wasmTypes.WithdrawMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Withdraw: &wasmvmtypes.WithdrawMsg{
Validator: valAddr2.String(),
},
},
Expand All @@ -253,9 +253,9 @@ func TestEncoding(t *testing.T) {
},
"staking withdraw (explicit recipient)": {
sender: addr1,
input: wasmTypes.CosmosMsg{
Staking: &wasmTypes.StakingMsg{
Withdraw: &wasmTypes.WithdrawMsg{
input: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Withdraw: &wasmvmtypes.WithdrawMsg{
Validator: valAddr2.String(),
Recipient: addr2.String(),
},
Expand Down
Loading

0 comments on commit d22a567

Please sign in to comment.