Skip to content

Commit

Permalink
Merge pull request #1804 from CosmWasm/update-to-wasmvm-2.0
Browse files Browse the repository at this point in the history
Update to wasmvm 2.0.0-rc.1
  • Loading branch information
chipshort authored Mar 6, 2024
2 parents 96e2b91 + 62eaa6e commit ba3a59c
Show file tree
Hide file tree
Showing 75 changed files with 1,180 additions and 610 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- "profiles/*"
- store_artifacts:
path: /tmp/logs

test-system:
executor: golang
parallelism: 1
Expand Down Expand Up @@ -189,15 +189,15 @@ jobs:
command: |
IN_DOCKER=$(docker run --rm "cosmwasm/wasmd:${CIRCLE_SHA1}" /usr/bin/wasmd query wasm libwasmvm-version)
echo "Runtime libwasmvm-version in docker: $IN_DOCKER"
IN_GOMOD=$(go list -m github.com/CosmWasm/wasmvm | cut -d" " -f2 | cut -d"v" -f2)
IN_GOMOD=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d" " -f2 | cut -d"v" -f2)
echo "wasmvm version in go.mod: $IN_GOMOD"
if [[ "$IN_DOCKER" != "$IN_GOMOD" ]]; then
echo "Mismatch of wasmvm versions detected"
exit 1
fi
- when:
condition:
equal: [ main, << pipeline.git.branch >> ]
equal: [main, << pipeline.git.branch >>]
steps:
- run:
name: Push application Docker image to docker hub
Expand Down
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ RUN apk add git
WORKDIR /code
COPY . /code/
# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.5.2/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.5.2/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep e78b224c15964817a3b75a40e59882b4d0e06fd055b39514d61646689cef8c6e
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep e660a38efb2930b34ee6f6b0bb12730adccb040b6ab701b8f82f34453a426ae7

# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
RUN cp /lib/libwasmvm_muslc.${arch}.a /lib/libwasmvm_muslc.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.0.0-rc.2/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.0.0-rc.2/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 6101550283308b4a57694faf558e47ec171c763321157825b48114e9d5a14bd2
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep ec20d6df9c69a0fad61d224648a262d78996f7eb43afaf4775a30064148466b6

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build
Expand All @@ -45,4 +42,4 @@ EXPOSE 26656
# tendermint rpc
EXPOSE 26657

CMD ["/usr/bin/wasmd", "version"]
CMD ["/usr/bin/wasmd", "version"]
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ Also CosmWasm 2.0 contracts remain compatible at the Wasm interface level.
To extend the feature set over time, contracts can specify required [capabilities](https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES.md) through cargo features in cosmwasm-std.
The following table shows which of the [latest capabilities](https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md) are supported by certain wasmd versions.

| capability | >= 0.42 | >= 0.41 | >= 0.31 | >= 0.29 | 0.28 |
| ------------ | ------- | ------- | ------- | ------- | ---- |
| iterator | x | x | x | x | x |
| stargate | x | x | x | x | x |
| staking | x | x | x | x | x |
| cosmwasm_1_1 | x | x | x | x | |
| cosmwasm_1_2 | x | x | x | | |
| cosmwasm_1_3 | x | x | | | |
| cosmwasm_1_4 | x | | | | |
| capability | >= 0.51 | >= 0.42 | >= 0.41 | >= 0.31 | >= 0.29 | 0.28 |
| ------------ | ------- | ------- | ------- | ------- | ------- | ---- |
| iterator | x | x | x | x | x | x |
| stargate | x | x | x | x | x | x |
| staking | x | x | x | x | x | x |
| cosmwasm_1_1 | x | x | x | x | x | |
| cosmwasm_1_2 | x | x | x | x | | |
| cosmwasm_1_3 | x | x | x | | | |
| cosmwasm_1_4 | x | x | | | | |
| cosmwasm_2_0 | x | | | | | |

### For node developers

Expand Down
4 changes: 1 addition & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"sort"
"strings"
"sync"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -629,7 +628,6 @@ func NewWasmApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
Expand All @@ -646,7 +644,7 @@ func NewWasmApp(
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
AllCapabilities(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)
Expand Down
5 changes: 4 additions & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

appOptions[flags.FlagHome] = t.TempDir() // ensure a unique folder for the new app

newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", newApp.Name())

Expand Down Expand Up @@ -318,7 +320,6 @@ func TestAppStateDeterminism(t *testing.T) {
appOptions.SetDefault(key, value)
}
}
appOptions.SetDefault(flags.FlagHome, t.TempDir()) // ensure a unique folder
appOptions.SetDefault(server.FlagInvCheckPeriod, simcli.FlagPeriodValue)

for i := 0; i < numSeeds; i++ {
Expand All @@ -331,6 +332,8 @@ func TestAppStateDeterminism(t *testing.T) {
logger = log.NewNopLogger()
}

appOptions.SetDefault(flags.FlagHome, t.TempDir()) // ensure a unique folder per run

db := dbm.NewMemDB()
app := NewWasmApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

Expand Down
1 change: 1 addition & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ func AllCapabilities() []string {
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
"cosmwasm_2_0",
}
}
4 changes: 2 additions & 2 deletions 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.21

require (
github.com/CosmWasm/wasmvm v1.5.2
github.com/CosmWasm/wasmvm/v2 v2.0.0-rc.2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.1
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand Down Expand Up @@ -188,7 +188,7 @@ require (
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag=
github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
github.com/CosmWasm/wasmvm/v2 v2.0.0-rc.2 h1:2rAO0MpNmKHKsrX/lsyo7lLjKoGDOWwMk+40hTNVfdE=
github.com/CosmWasm/wasmvm/v2 v2.0.0-rc.2/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down Expand Up @@ -1340,8 +1340,8 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -61,25 +61,25 @@ func TestGovVoteByContract(t *testing.T) {
}{
"yes": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.Yes,
Option: wasmvmtypes.Yes,
},
expPass: true,
},
"no": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.No,
Option: wasmvmtypes.No,
},
expPass: false,
},
"abstain": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.Abstain,
Option: wasmvmtypes.Abstain,
},
expPass: true,
},
"no with veto": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.NoWithVeto,
Option: wasmvmtypes.NoWithVeto,
},
expPass: false,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvm "github.com/CosmWasm/wasmvm/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
56 changes: 55 additions & 1 deletion tests/e2e/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestGroupWithContract(t *testing.T) {

coord := ibctesting.NewCoordinator(t, 1)
chain := coord.GetChain(ibctesting.GetChainID(1))
contractAddr := e2e.InstantiateReflectContract(t, chain)
contractAddr := e2e.InstantiateStargateReflectContract(t, chain)
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))

members := []group.MemberRequest{
Expand Down Expand Up @@ -74,3 +74,57 @@ func TestGroupWithContract(t *testing.T) {
expBalanceAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.OneInt())
assert.Equal(t, expBalanceAmount.String(), recipientBalance.String())
}

func TestGroupWithNewReflectContract(t *testing.T) {
// Given a group with a contract as only member
// When contract submits a proposal with try_execute
// Then the payload msg is executed

coord := ibctesting.NewCoordinator(t, 1)
chain := coord.GetChain(ibctesting.GetChainID(1))
contractAddr := e2e.InstantiateReflectContract(t, chain)
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))

members := []group.MemberRequest{
{
Address: contractAddr.String(),
Weight: "1",
Metadata: "my contract",
},
}
msg, err := group.NewMsgCreateGroupWithPolicy(
chain.SenderAccount.GetAddress().String(),
members,
"my group",
"my metadata",
false,
group.NewPercentageDecisionPolicy("1", time.Second, 0),
)
require.NoError(t, err)
rsp, err := chain.SendMsgs(msg)
require.NoError(t, err)

var createRsp group.MsgCreateGroupWithPolicyResponse
chain.UnwrapExecTXResult(rsp, &createRsp)
groupID, policyAddr := createRsp.GroupId, sdk.MustAccAddressFromBech32(createRsp.GroupPolicyAddress)
require.NotEmpty(t, groupID)
chain.Fund(policyAddr, sdkmath.NewIntFromUint64(1_000_000_000))
// and a proposal submitted
recipientAddr := sdk.AccAddress(rand.Bytes(address.Len))

payload := []sdk.Msg{banktypes.NewMsgSend(policyAddr, recipientAddr, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.OneInt())))}
propMsg, err := group.NewMsgSubmitProposal(policyAddr.String(), []string{contractAddr.String()}, payload, "my proposal", group.Exec_EXEC_TRY, "my title", "my description")
require.NoError(t, err)

rsp = e2e.MustExecViaAnyReflectContract(t, chain, contractAddr, propMsg)
var execRsp types.MsgExecuteContractResponse
chain.UnwrapExecTXResult(rsp, &execRsp)

var groupRsp group.MsgSubmitProposalResponse
require.NoError(t, chain.Codec.Unmarshal(execRsp.Data, &groupRsp))

// and coins received
recipientBalance := chain.Balance(recipientAddr, sdk.DefaultBondDenom)
expBalanceAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.OneInt())
assert.Equal(t, expBalanceAmount.String(), recipientBalance.String())
}
42 changes: 38 additions & 4 deletions tests/e2e/reflect_helper.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package e2e

import (
"encoding/base64"
"encoding/json"
"fmt"
"testing"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
Expand All @@ -16,9 +18,18 @@ import (
"github.com/CosmWasm/wasmd/x/wasm/types"
)

// InstantiateReflectContract store and instantiate a reflect contract instance
// InstantiateStargateReflectContract stores and instantiates the reflect contract shipped with CosmWasm 1.5.3.
// This instance still expects the old CosmosMsg.Stargate variant instead of the new CosmosMsg.Any.
func InstantiateStargateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress {
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_5.wasm").CodeID
contractAddr := chain.InstantiateContract(codeID, []byte(`{}`))
require.NotEmpty(t, contractAddr)
return contractAddr
}

// InstantiateReflectContract stores and instantiates a 2.0 reflect contract instance.
func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress {
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_1.wasm").CodeID
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_2_0.wasm").CodeID
contractAddr := chain.InstantiateContract(codeID, []byte(`{}`))
require.NotEmpty(t, contractAddr)
return contractAddr
Expand All @@ -37,12 +48,35 @@ type sdkMessageType interface {
}

func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
require.NotEmpty(t, msgs)
// convert messages to stargate variant
vmMsgs := make([]string, len(msgs))
for i, m := range msgs {
bz, err := chain.Codec.Marshal(m)
require.NoError(t, err)
// json is built manually because the wasmvm CosmosMsg does not have the `Stargate` variant anymore
vmMsgs[i] = fmt.Sprintf("{\"stargate\":{\"type_url\":\"%s\",\"value\":\"%s\"}}", sdk.MsgTypeURL(m), base64.StdEncoding.EncodeToString(bz))
}
// build the complete reflect message
reflectSendBz := []byte(fmt.Sprintf("{\"reflect_msg\":{\"msgs\":%s}}", vmMsgs))

execMsg := &types.MsgExecuteContract{
Sender: chain.SenderAccount.GetAddress().String(),
Contract: contractAddr.String(),
Msg: reflectSendBz,
}
rsp, err := chain.SendMsgs(execMsg)
require.NoError(t, err)
return rsp
}

func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs))
for i, m := range msgs {
bz, err := chain.Codec.Marshal(m)
require.NoError(t, err)
vmMsgs[i] = wasmvmtypes.CosmosMsg{
Stargate: &wasmvmtypes.StargateMsg{
Any: &wasmvmtypes.AnyMsg{
TypeURL: sdk.MsgTypeURL(m),
Value: bz,
},
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvm "github.com/CosmWasm/wasmvm/v2"
"github.com/distribution/reference"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
"strconv"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvm "github.com/CosmWasm/wasmvm/v2"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

Expand Down
2 changes: 1 addition & 1 deletion x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package wasm
import (
"math"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
Expand Down
Loading

0 comments on commit ba3a59c

Please sign in to comment.