mirror of https://github.com/certusone/wasmd.git
Update go-cosmwasm and Use new gas limits
This commit is contained in:
parent
9734dfb3c9
commit
b97c87212c
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
|
|||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha2
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha3
|
||||
github.com/cosmos/cosmos-sdk v0.39.1-0.20200727135228-9d00f712e334
|
||||
github.com/golang/mock v1.4.3 // indirect
|
||||
github.com/google/gofuzz v1.0.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -11,6 +11,8 @@ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQ
|
|||
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha2 h1:k069wQF0f24w3A52mjR3AK6AfkuvQ5d0Mdu/rpB5nEk=
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha2/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha3 h1:+LJxN6oHNdHDoB9JT8v6Zh373MvBbFkKoikSnh4GGWM=
|
||||
github.com/CosmWasm/go-cosmwasm v0.10.0-alpha3/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
|
|
|
@ -2,6 +2,7 @@ package keeper
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -17,20 +18,26 @@ type QueryHandler struct {
|
|||
|
||||
var _ wasmTypes.Querier = QueryHandler{}
|
||||
|
||||
func (q QueryHandler) Query(request wasmTypes.QueryRequest) ([]byte, error) {
|
||||
func (q QueryHandler) Query(request wasmTypes.QueryRequest, gasLimit uint64) (res []byte, err error) {
|
||||
sdkGas := gasLimit / GasMultiplier
|
||||
fmt.Printf("Sdk gas %d, wasmer gas: %d\n", sdkGas, gasLimit)
|
||||
subctx := q.Ctx.WithGasMeter(sdk.NewGasMeter(gasLimit / GasMultiplier))
|
||||
res, err = nil, wasmTypes.Unknown{}
|
||||
if request.Bank != nil {
|
||||
return q.Plugins.Bank(q.Ctx, request.Bank)
|
||||
res, err = q.Plugins.Bank(subctx, request.Bank)
|
||||
}
|
||||
if request.Custom != nil {
|
||||
return q.Plugins.Custom(q.Ctx, request.Custom)
|
||||
res, err = q.Plugins.Custom(subctx, request.Custom)
|
||||
}
|
||||
if request.Staking != nil {
|
||||
return q.Plugins.Staking(q.Ctx, request.Staking)
|
||||
res, err = q.Plugins.Staking(subctx, request.Staking)
|
||||
}
|
||||
if request.Wasm != nil {
|
||||
return q.Plugins.Wasm(q.Ctx, request.Wasm)
|
||||
res, err = q.Plugins.Wasm(subctx, request.Wasm)
|
||||
}
|
||||
return nil, wasmTypes.Unknown{}
|
||||
fmt.Printf("charged: %d\n", subctx.GasMeter().GasConsumed())
|
||||
q.Ctx.GasMeter().ConsumeGas(subctx.GasMeter().GasConsumed(), "contract sub-query")
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (q QueryHandler) GasConsumed() uint64 {
|
||||
|
|
|
@ -314,7 +314,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
|
|||
// if we expect out of gas, make sure this panics
|
||||
if tc.expectOutOfGas {
|
||||
require.Panics(t, func() {
|
||||
_, _ = keeper.QuerySmart(ctx, contractAddr, msg)
|
||||
_, err := keeper.QuerySmart(ctx, contractAddr, msg)
|
||||
t.Logf("Got error not panic: %#v", err)
|
||||
})
|
||||
assert.Equal(t, tc.expectQueriesFromContract, totalWasmQueryCounter)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue