Skip to content

Commit 957b38e

Browse files
alpejhernandezb
andauthored
Integrate wasmvm v1.2.0 (#1161)
* Bump wasmvm version * Bump wasm test contracts * Encode weighted votes * Encode instantiate2 * Handle code info query; better wasmvm errors * Fix readme * Make linter happy * add non cgo build * Review comments * Bump wasmvm to release version Co-authored-by: jhernandezb <contact@jhernandez.me>
1 parent a925a9e commit 957b38e

26 files changed

+688
-142
lines changed

Dockerfile

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ RUN apk add git
1414

1515
WORKDIR /code
1616
COPY . /code/
17-
1817
# See https://github.com/CosmWasm/wasmvm/releases
19-
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
20-
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
21-
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 9ecb037336bd56076573dc18c26631a9d2099a7f2b40dc04b6cae31ffb4c8f9a
22-
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6e4de7ba9bad4ae9679c7f9ecf7e283dd0160e71567c6a7be6ae47c81ebe7f32
18+
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.2.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
19+
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.2.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
20+
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep cba4b334893456c64df177939cbdd09afe4812432c02ae37d60d69a111b1b50d
21+
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6f87082f7a62602f9725d529677f330b9c4dd4607887be52a86328c6c919495b
2322

2423
# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
2524
RUN cp /lib/libwasmvm_muslc.${arch}.a /lib/libwasmvm_muslc.a

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Wasm Zone
23

34
[![CircleCI](https://circleci.com/gh/CosmWasm/wasmd/tree/main.svg?style=shield)](https://circleci.com/gh/CosmWasm/wasmd/tree/main)
@@ -26,6 +27,7 @@ compatibility list:
2627

2728
| wasmd | wasmvm | cosmwasm-vm | cosmwasm-std |
2829
|-------|--------------|-------------|--------------|
30+
| 0.31 | v1.2.0 | | 1.0-1.2 |
2931
| 0.30 | v1.1.0 | | 1.0-1.1 |
3032
| 0.29 | v1.1.0 | | 1.0-1.1 |
3133
| 0.28 | v1.0.0 | | 1.0-1.1 |

app/app.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ func NewWasmApp(
513513

514514
// The last arguments can contain custom message handlers, and custom query handlers,
515515
// if we want to allow any custom callbacks
516-
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1"
516+
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
517+
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"
517518
app.WasmKeeper = wasm.NewKeeper(
518519
appCodec,
519520
keys[wasm.StoreKey],

go.mod

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

55
require (
6-
github.com/CosmWasm/wasmvm v1.1.1
6+
github.com/CosmWasm/wasmvm v1.2.0
77
github.com/cosmos/cosmos-proto v1.0.0-beta.1
88
github.com/cosmos/cosmos-sdk v0.45.11
99
github.com/cosmos/gogoproto v1.4.3
@@ -24,7 +24,6 @@ require (
2424
github.com/spf13/cast v1.5.0
2525
github.com/spf13/cobra v1.6.0
2626
github.com/spf13/pflag v1.0.5
27-
github.com/spf13/viper v1.14.0
2827
github.com/stretchr/testify v1.8.1
2928
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
3029
github.com/tendermint/tendermint v0.34.23
@@ -111,6 +110,7 @@ require (
111110
github.com/sasha-s/go-deadlock v0.3.1 // indirect
112111
github.com/spf13/afero v1.9.2 // indirect
113112
github.com/spf13/jwalterweatherman v1.1.0 // indirect
113+
github.com/spf13/viper v1.14.0 // indirect
114114
github.com/subosito/gotenv v1.4.1 // indirect
115115
github.com/tendermint/btcd v0.1.1 // indirect
116116
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
5959
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
6060
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
6161
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
62-
github.com/CosmWasm/wasmvm v1.1.1 h1:0xtdrmmsP9fibe+x42WcMkp5aQ738BICgcH3FNVLzm4=
63-
github.com/CosmWasm/wasmvm v1.1.1/go.mod h1:ei0xpvomwSdONsxDuONzV7bL1jSET1M8brEx0FCXc+A=
62+
github.com/CosmWasm/wasmvm v1.2.0 h1:pNCp175id+r/dSa4Ii5zoTkmauOoeipkvepvEJM1bao=
63+
github.com/CosmWasm/wasmvm v1.2.0/go.mod h1:OIhXFPi9BbcEL1USBj4OIrBTtSSds+9eEql56fsdyfE=
6464
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
6565
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
6666
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=

x/wasm/client/cli/gov_tx_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestParseCodeInfoFlags(t *testing.T) {
104104
wasmBin, err := os.ReadFile("../../keeper/testdata/hackatom.wasm")
105105
require.NoError(t, err)
106106

107-
checksumStr := "13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5"
107+
checksumStr := "beb3de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b"
108108

109109
specs := map[string]struct {
110110
args []string

x/wasm/keeper/handler_plugin_encoders.go

+53-8
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg,
237237
Funds: coins,
238238
}
239239
return []sdk.Msg{&sdkMsg}, nil
240+
case msg.Instantiate2 != nil:
241+
coins, err := ConvertWasmCoinsToSdkCoins(msg.Instantiate2.Funds)
242+
if err != nil {
243+
return nil, err
244+
}
245+
246+
sdkMsg := types.MsgInstantiateContract2{
247+
Sender: sender.String(),
248+
Admin: msg.Instantiate2.Admin,
249+
CodeID: msg.Instantiate2.CodeID,
250+
Label: msg.Instantiate2.Label,
251+
Msg: msg.Instantiate2.Msg,
252+
Funds: coins,
253+
Salt: msg.Instantiate2.Salt,
254+
// FixMsg is discouraged, see: https://medium.com/cosmwasm/dev-note-3-limitations-of-instantiate2-and-how-to-deal-with-them-a3f946874230
255+
FixMsg: false,
256+
}
257+
return []sdk.Msg{&sdkMsg}, nil
240258
case msg.Migrate != nil:
241259
sdkMsg := types.MsgMigrateContract{
242260
Sender: sender.String(),
@@ -288,14 +306,44 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context
288306
}
289307
return []sdk.Msg{msg}, nil
290308
default:
291-
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "Unknown variant of IBC")
309+
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of IBC")
292310
}
293311
}
294312
}
295313

296314
func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, error) {
315+
switch {
316+
case msg.Vote != nil:
317+
voteOption, err := convertVoteOption(msg.Vote.Vote)
318+
if err != nil {
319+
return nil, sdkerrors.Wrap(err, "vote option")
320+
}
321+
m := govtypes.NewMsgVote(sender, msg.Vote.ProposalId, voteOption)
322+
return []sdk.Msg{m}, nil
323+
case msg.VoteWeighted != nil:
324+
opts := make([]govtypes.WeightedVoteOption, len(msg.VoteWeighted.Options))
325+
for i, v := range msg.VoteWeighted.Options {
326+
weight, err := sdk.NewDecFromStr(v.Weight)
327+
if err != nil {
328+
return nil, sdkerrors.Wrapf(err, "weight for vote %d", i+1)
329+
}
330+
voteOption, err := convertVoteOption(v.Option)
331+
if err != nil {
332+
return nil, sdkerrors.Wrap(err, "vote option")
333+
}
334+
opts[i] = govtypes.WeightedVoteOption{Option: voteOption, Weight: weight}
335+
}
336+
m := govtypes.NewMsgVoteWeighted(sender, msg.VoteWeighted.ProposalId, opts)
337+
return []sdk.Msg{m}, nil
338+
339+
default:
340+
return nil, types.ErrUnknownMsg.Wrap("unknown variant of gov")
341+
}
342+
}
343+
344+
func convertVoteOption(s interface{}) (govtypes.VoteOption, error) {
297345
var option govtypes.VoteOption
298-
switch msg.Vote.Vote {
346+
switch s {
299347
case wasmvmtypes.Yes:
300348
option = govtypes.OptionYes
301349
case wasmvmtypes.No:
@@ -304,13 +352,10 @@ func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, er
304352
option = govtypes.OptionNoWithVeto
305353
case wasmvmtypes.Abstain:
306354
option = govtypes.OptionAbstain
355+
default:
356+
return govtypes.OptionEmpty, types.ErrInvalid
307357
}
308-
vote := &govtypes.MsgVote{
309-
ProposalId: msg.Vote.ProposalId,
310-
Voter: sender.String(),
311-
Option: option,
312-
}
313-
return []sdk.Msg{vote}, nil
358+
return option, nil
314359
}
315360

316361
// ConvertWasmIBCTimeoutHeightToCosmosHeight converts a wasmvm type ibc timeout height to ibc module type height

0 commit comments

Comments
 (0)