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 to wasmvm v0.14.0-rc1 #508

Merged
merged 3 commits into from
Apr 30, 2021
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ WORKDIR /code
COPY . /code/

# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v0.14.0-beta5/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep 0a90493799f19f95d39910d4ac5b6d9fc70d482dabec1f3ffb7c81428c125d4c
ADD https://github.com/CosmWasm/wasmvm/releases/download/v0.14.0-rc1/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep 46b77410f55b3d70ce77088aa70f8c54c574c19471437d28409cb584c0062c4e

# 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
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/wasmvm v0.14.0-beta5
github.com/CosmWasm/wasmvm v0.14.0-rc1
github.com/cosmos/cosmos-sdk v0.42.4
github.com/cosmos/iavl v0.15.3
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,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/wasmvm v0.14.0-beta5 h1:lYe8tQr/m/utoAPyfp4vbka59CT7GH25QDUA0sZ4xN8=
github.com/CosmWasm/wasmvm v0.14.0-beta5/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
github.com/CosmWasm/wasmvm v0.14.0-rc1 h1:otpTbV93S2J5Fk67LB8On8MV/nFS1m2H4ULn9tGihCg=
github.com/CosmWasm/wasmvm v0.14.0-rc1/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
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 Expand Up @@ -573,7 +573,6 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM
github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ=
github.com/tendermint/tendermint v0.34.9 h1:9P2MXDEPOcPW0NBcHQ/HDSfvczZm+q5nUUw7AZ6f1Vc=
github.com/tendermint/tendermint v0.34.9/go.mod h1:kl4Z1JwGx1I+u1SXIzMDy7Z3T8LiMeCAOnzNn6AIMT4=
github.com/tendermint/tendermint v0.34.10 h1:wBOc/It8sh/pVH9np2V5fBvRmIyFN/bUrGPx+eAHexs=
github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
Expand Down
25 changes: 7 additions & 18 deletions x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,14 @@ func (i IBCHandler) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet)
}

func newIBCPacket(packet channeltypes.Packet) wasmvmtypes.IBCPacket {
var timeout wasmvmtypes.IBCTimeout
// detect set/unset
if packet.TimeoutHeight.RevisionHeight != 0 {
if packet.TimeoutTimestamp != 0 {
timeout.Both = &wasmvmtypes.IBCTimeoutBoth{
Block: wasmvmtypes.IBCTimeoutBlock{
Height: packet.TimeoutHeight.RevisionHeight,
Revision: packet.TimeoutHeight.RevisionNumber,
},
Timestamp: packet.TimeoutTimestamp,
}
} else {
timeout.Block = &wasmvmtypes.IBCTimeoutBlock{
Height: packet.TimeoutHeight.RevisionHeight,
Revision: packet.TimeoutHeight.RevisionNumber,
}
timeout := wasmvmtypes.IBCTimeout{
Timestamp: packet.TimeoutTimestamp,
}
if !packet.TimeoutHeight.IsZero() {
timeout.Block = &wasmvmtypes.IBCTimeoutBlock{
Height: packet.TimeoutHeight.RevisionHeight,
Revision: packet.TimeoutHeight.RevisionNumber,
}
} else {
timeout.Timestamp = &packet.TimeoutTimestamp
}

return wasmvmtypes.IBCPacket{
Expand Down
9 changes: 8 additions & 1 deletion x/wasm/ibc_reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import (
)

func TestIBCReflectContract(t *testing.T) {
// scenario:
// chain A: ibc_reflect_send.wasm
// chain B: reflect.wasm + ibc_reflect.wasm
//
// Chain A "ibc_reflect_send" sends a IBC packet "on channel connect" event to chain B "ibc_reflect"
// "ibc_reflect" sends a submessage to "reflect" which is returned as submessage.

var (
coordinator = ibctesting.NewCoordinator(t, 2, nil, nil)
chainA = coordinator.GetChain(ibctesting.GetChainID(0))
Expand Down Expand Up @@ -96,7 +103,7 @@ type AccountQuery struct {
}

type AccountResponse struct {
LastUpdateTime uint64 `json:"last_update_time"`
LastUpdateTime uint64 `json:"last_update_time,string"`
RemoteAddr string `json:"remote_addr"`
RemoteBalance wasmvmtypes.Coins `json:"remote_balance"`
}
10 changes: 5 additions & 5 deletions x/wasm/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMapToWasmVMIBCPacket(t *testing.T) {
src channeltypes.Packet
exp wasmvmtypes.IBCPacket
}{
"with hight timeout": {
"with height timeout": {
src: IBCPacketFixture(),
exp: wasmvmtypes.IBCPacket{
Data: []byte("myData"),
Expand All @@ -34,7 +34,7 @@ func TestMapToWasmVMIBCPacket(t *testing.T) {
Src: wasmvmtypes.IBCEndpoint{PortID: "srcPort", ChannelID: "channel-1"},
Dest: wasmvmtypes.IBCEndpoint{PortID: "destPort", ChannelID: "channel-2"},
Sequence: 1,
Timeout: wasmvmtypes.IBCTimeout{Timestamp: &myTimestamp},
Timeout: wasmvmtypes.IBCTimeout{Timestamp: myTimestamp},
},
}, "with time and height timeout": {
src: IBCPacketFixture(func(p *channeltypes.Packet) {
Expand All @@ -45,10 +45,10 @@ func TestMapToWasmVMIBCPacket(t *testing.T) {
Src: wasmvmtypes.IBCEndpoint{PortID: "srcPort", ChannelID: "channel-1"},
Dest: wasmvmtypes.IBCEndpoint{PortID: "destPort", ChannelID: "channel-2"},
Sequence: 1,
Timeout: wasmvmtypes.IBCTimeout{Both: &wasmvmtypes.IBCTimeoutBoth{
Block: wasmvmtypes.IBCTimeoutBlock{Height: 1, Revision: 2},
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{Height: 1, Revision: 2},
Timestamp: myTimestamp,
}},
},
},
},
}
Expand Down
5 changes: 2 additions & 3 deletions x/wasm/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont
if !ok {
return nil, nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
}
timestamp, height := ConvertWasmIBCTimeout(msg.IBC.SendPacket.Timeout)
packet := channeltypes.NewPacket(
msg.IBC.SendPacket.Data,
sequence,
contractIBCPortID,
contractIBCChannelID,
channelInfo.Counterparty.PortId,
channelInfo.Counterparty.ChannelId,
height,
timestamp,
convertWasmIBCTimeoutHeightToCosmosHeight(msg.IBC.SendPacket.Timeout.Block),
msg.IBC.SendPacket.Timeout.Timestamp,
)
return nil, nil, h.channelKeeper.SendPacket(ctx, channelCap, packet)
}
Expand Down
25 changes: 6 additions & 19 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,39 +265,26 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context
if err != nil {
return nil, sdkerrors.Wrap(err, "amount")
}
timestamp, height := ConvertWasmIBCTimeout(msg.Transfer.Timeout)
msg := &ibctransfertypes.MsgTransfer{
SourcePort: portSource.GetPort(ctx),
SourceChannel: msg.Transfer.ChannelID,
Token: amount,
Sender: sender.String(),
Receiver: msg.Transfer.ToAddress,
TimeoutHeight: height,
TimeoutTimestamp: timestamp,
TimeoutHeight: convertWasmIBCTimeoutHeightToCosmosHeight(msg.Transfer.Timeout.Block),
TimeoutTimestamp: msg.Transfer.Timeout.Timestamp,
}
return []sdk.Msg{msg}, nil
default:
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "Unknown variant of IBC")
}
}
}

// ConvertWasmIBCTimeout converts the wasmvm ibc timeout type to cosmos-sdk height and relative block timeout
func ConvertWasmIBCTimeout(ibcTimeout wasmvmtypes.IBCTimeout) (uint64, ibcclienttypes.Height) {
var timestamp uint64
var height ibcclienttypes.Height

switch {
case ibcTimeout.Timestamp != nil:
timestamp = *ibcTimeout.Timestamp
case ibcTimeout.Block != nil:
height = ibcclienttypes.NewHeight(ibcTimeout.Block.Revision, ibcTimeout.Block.Height)
case ibcTimeout.Both != nil:
timestamp = ibcTimeout.Both.Timestamp
height = ibcclienttypes.NewHeight(ibcTimeout.Both.Block.Revision, ibcTimeout.Both.Block.Height)
func convertWasmIBCTimeoutHeightToCosmosHeight(ibcTimeoutBlock *wasmvmtypes.IBCTimeoutBlock) ibcclienttypes.Height {
if ibcTimeoutBlock == nil {
return ibcclienttypes.NewHeight(0, 0)
}

return timestamp, height
return ibcclienttypes.NewHeight(ibcTimeoutBlock.Revision, ibcTimeoutBlock.Height)
}

func convertWasmCoinsToSdkCoins(coins []wasmvmtypes.Coin) (sdk.Coins, error) {
Expand Down
18 changes: 6 additions & 12 deletions x/wasm/keeper/handler_plugin_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"testing"

"github.com/CosmWasm/wasmd/x/wasm/types"
Expand All @@ -17,7 +18,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -32,7 +32,6 @@ func TestEncoding(t *testing.T) {
valAddr[0] = 12
valAddr2 := make(sdk.ValAddress, sdk.AddrLen)
valAddr2[1] = 123
var timeoutVal uint64 = 100

jsonMsg := json.RawMessage(`{"foo": 123}`)

Expand Down Expand Up @@ -427,7 +426,7 @@ func TestEncoding(t *testing.T) {
Denom: "ALX",
Amount: "1",
},
Timeout: wasmvmtypes.IBCTimeout{Timestamp: &timeoutVal},
Timeout: wasmvmtypes.IBCTimeout{Timestamp: 100},
},
},
},
Expand All @@ -447,7 +446,8 @@ func TestEncoding(t *testing.T) {
TimeoutTimestamp: 100,
},
},
}, "IBC transfer with time and height timeout": {
},
"IBC transfer with time and height timeout": {
sender: addr1,
srcContractIBCPort: "myIBCPort",
srcMsg: wasmvmtypes.CosmosMsg{
Expand All @@ -459,13 +459,7 @@ func TestEncoding(t *testing.T) {
Denom: "ALX",
Amount: "1",
},
Timeout: wasmvmtypes.IBCTimeout{Both: &wasmvmtypes.IBCTimeoutBoth{
Block: wasmvmtypes.IBCTimeoutBlock{
Height: 1,
Revision: 2,
},
Timestamp: timeoutVal,
}},
Timeout: wasmvmtypes.IBCTimeout{Timestamp: 100, Block: &wasmvmtypes.IBCTimeoutBlock{Height: 1, Revision: 2}},
},
},
},
Expand All @@ -483,7 +477,7 @@ func TestEncoding(t *testing.T) {
Sender: addr1.String(),
Receiver: addr2.String(),
TimeoutTimestamp: 100,
TimeoutHeight: clienttypes.Height{RevisionNumber: 2, RevisionHeight: 1},
TimeoutHeight: clienttypes.NewHeight(2, 1),
},
},
},
Expand Down
12 changes: 3 additions & 9 deletions x/wasm/keeper/handler_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ func TestIBCRawPacketHandler(t *testing.T) {
srcMsg: wasmvmtypes.SendPacketMsg{
ChannelID: "channel-1",
Data: []byte("myData"),
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2},
},
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2}},
},
chanKeeper: chanKeeper,
capKeeper: capKeeper,
Expand All @@ -271,9 +269,7 @@ func TestIBCRawPacketHandler(t *testing.T) {
srcMsg: wasmvmtypes.SendPacketMsg{
ChannelID: "channel-1",
Data: []byte("myData"),
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2},
},
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2}},
},
chanKeeper: &wasmtesting.MockChannelKeeper{
GetNextSequenceSendFn: func(ctx sdk.Context, portID, channelID string) (uint64, bool) {
Expand All @@ -285,9 +281,7 @@ func TestIBCRawPacketHandler(t *testing.T) {
srcMsg: wasmvmtypes.SendPacketMsg{
ChannelID: "channel-1",
Data: []byte("myData"),
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2},
},
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 2}},
},
chanKeeper: chanKeeper,
capKeeper: wasmtesting.MockCapabilityKeeper{
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestInstantiate(t *testing.T) {

gasAfter := ctx.GasMeter().GasConsumed()
if types.EnableGasVerification {
require.Equal(t, uint64(0x1229f), gasAfter-gasBefore)
require.Equal(t, uint64(0x122a0), gasAfter-gasBefore)
}

// ensure it is stored properly
Expand Down Expand Up @@ -516,7 +516,7 @@ func TestExecute(t *testing.T) {
// make sure gas is properly deducted from ctx
gasAfter := ctx.GasMeter().GasConsumed()
if types.EnableGasVerification {
require.Equal(t, uint64(0x12916), gasAfter-gasBefore)
require.Equal(t, uint64(0x12917), gasAfter-gasBefore)
}
// ensure bob now exists and got both payments released
bobAcct = accKeeper.GetAccount(ctx, bob)
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/keeper/recurse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func TestGasCostOnQuery(t *testing.T) {
const (
GasNoWork uint64 = 44_072
// Note: about 100 SDK gas (10k wasmer gas) for each round of sha256
GasWork50 uint64 = 49_763 // this is a little shy of 50k gas - to keep an eye on the limit
GasWork50 uint64 = 49_764 // this is a little shy of 50k gas - to keep an eye on the limit

GasReturnUnhashed uint64 = 283
GasReturnHashed uint64 = 258
GasReturnHashed uint64 = 257
)

cases := map[string]struct {
Expand All @@ -80,14 +80,14 @@ func TestGasCostOnQuery(t *testing.T) {
msg: Recurse{
Work: 50, // 50 rounds of sha256 inside the contract
},
expectedGas: GasWork50 + 1,
expectedGas: GasWork50,
},
"recursion 1, no work": {
gasLimit: 400_000,
msg: Recurse{
Depth: 1,
},
expectedGas: 2*GasNoWork + GasReturnUnhashed - 2,
expectedGas: 2*GasNoWork + GasReturnUnhashed,
},
"recursion 1, some work": {
gasLimit: 400_000,
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestLimitRecursiveQueryGas(t *testing.T) {

const (
// Note: about 100 SDK gas (10k wasmer gas) for each round of sha256
GasWork2k uint64 = 273_566 // = InstanceCost + x // we have 6x gas used in cpu than in the instance
GasWork2k uint64 = 273_567 // = InstanceCost + x // we have 6x gas used in cpu than in the instance
// This is overhead for calling into a sub-contract
GasReturnHashed uint64 = 262
)
Expand Down
Binary file modified x/wasm/keeper/testdata/burner.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/hackatom.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/hackatom.wasm.gzip
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/ibc_reflect_send.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/reflect.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/staking.wasm
Binary file not shown.
20 changes: 8 additions & 12 deletions x/wasm/relay_pingpong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ func (p *player) Execute(code wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmt
SendPacket: &wasmvmtypes.SendPacketMsg{
ChannelID: start.ChannelID,
Data: service.GetBytes(),
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{
Revision: doNotTimeout.RevisionNumber,
Height: doNotTimeout.RevisionHeight,
},
},
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{
Revision: doNotTimeout.RevisionNumber,
Height: doNotTimeout.RevisionHeight,
}},
},
},
},
Expand Down Expand Up @@ -273,12 +271,10 @@ func (p player) IBCPacketReceive(codeID wasmvm.Checksum, env wasmvmtypes.Env, pa
respHit := &wasmvmtypes.IBCMsg{SendPacket: &wasmvmtypes.SendPacketMsg{
ChannelID: packet.Src.ChannelID,
Data: newHit.GetBytes(),
Timeout: wasmvmtypes.IBCTimeout{
Block: &wasmvmtypes.IBCTimeoutBlock{
Revision: doNotTimeout.RevisionNumber,
Height: doNotTimeout.RevisionHeight,
},
},
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{
Revision: doNotTimeout.RevisionNumber,
Height: doNotTimeout.RevisionHeight,
}},
}}
p.incrementCounter(sentBallsCountKey, store)
p.t.Logf("[%s] received %d, returning %d: %v\n", p.actor, otherCount, nextValue, newHit)
Expand Down
Loading