Upgrade wasmvm to v0.13.0
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/CosmWasm/wasmvm v0.12.0
|
||||
github.com/CosmWasm/wasmvm v0.13.0
|
||||
github.com/cosmos/cosmos-sdk v0.40.0-rc6
|
||||
github.com/cosmos/iavl v0.15.3
|
||||
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b
|
||||
|
||||
4
go.sum
4
go.sum
@@ -18,8 +18,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.12.0 h1:L9ez6fCg2Co1SgCm0YHjbnewZ8myemu2cm/QL0qR1OE=
|
||||
github.com/CosmWasm/wasmvm v0.12.0/go.mod h1:tbXGE9Jz6sYpiJroGr71OQ5TFOufq/P5LWsruA2u6JE=
|
||||
github.com/CosmWasm/wasmvm v0.13.0 h1:AP8LVcCxI3KLtHY24qLhzVe+ChOXwcR8MNm8Jxkuhwk=
|
||||
github.com/CosmWasm/wasmvm v0.13.0/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=
|
||||
|
||||
@@ -42,6 +42,10 @@ const InstanceCost uint64 = 40_000
|
||||
// CompileCost is how much SDK gas we charge *per byte* for compiling WASM code.
|
||||
const CompileCost uint64 = 2
|
||||
|
||||
// contractMemoryLimit is the memory limit of each contract execution (in MiB)
|
||||
// constant value so all nodes run with the same limit.
|
||||
const contractMemoryLimit = 32
|
||||
|
||||
// Keeper will have a reference to Wasmer with it's own data directory.
|
||||
type Keeper struct {
|
||||
storeKey sdk.StoreKey
|
||||
@@ -75,7 +79,7 @@ func NewKeeper(
|
||||
customEncoders *MessageEncoders,
|
||||
customPlugins *QueryPlugins,
|
||||
) Keeper {
|
||||
wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), supportedFeatures, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize)
|
||||
wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), supportedFeatures, contractMemoryLimit, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func TestInstantiate(t *testing.T) {
|
||||
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractAddr.String())
|
||||
|
||||
gasAfter := ctx.GasMeter().GasConsumed()
|
||||
require.Equal(t, uint64(0x11974), gasAfter-gasBefore)
|
||||
require.Equal(t, uint64(0x118c2), gasAfter-gasBefore)
|
||||
|
||||
// ensure it is stored properly
|
||||
info := keeper.GetContractInfo(ctx, contractAddr)
|
||||
@@ -507,7 +507,7 @@ func TestExecute(t *testing.T) {
|
||||
|
||||
// make sure gas is properly deducted from ctx
|
||||
gasAfter := ctx.GasMeter().GasConsumed()
|
||||
require.Equal(t, uint64(0x11ec9), gasAfter-gasBefore)
|
||||
require.Equal(t, uint64(0x11d8c), gasAfter-gasBefore)
|
||||
|
||||
// ensure bob now exists and got both payments released
|
||||
bobAcct = accKeeper.GetAccount(ctx, bob)
|
||||
@@ -639,7 +639,7 @@ func TestExecuteWithPanic(t *testing.T) {
|
||||
_, err = keeper.Execute(ctx, addr, fred, []byte(`{"panic":{}}`), topUp)
|
||||
require.Error(t, err)
|
||||
require.True(t, errors.Is(err, types.ErrExecuteFailed))
|
||||
require.Equal(t, "Out of gas: execute wasm contract failed", err.Error())
|
||||
require.Equal(t, "Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: unreachable: execute wasm contract failed", err.Error())
|
||||
}
|
||||
|
||||
func TestExecuteWithCpuLoop(t *testing.T) {
|
||||
|
||||
@@ -56,12 +56,12 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.Acc
|
||||
|
||||
func TestGasCostOnQuery(t *testing.T) {
|
||||
const (
|
||||
GasNoWork uint64 = 43229
|
||||
GasNoWork uint64 = 43091
|
||||
// Note: about 100 SDK gas (10k wasmer gas) for each round of sha256
|
||||
GasWork50 uint64 = 48937 // this is a little shy of 50k gas - to keep an eye on the limit
|
||||
GasWork50 uint64 = 48752 // this is a little shy of 50k gas - to keep an eye on the limit
|
||||
|
||||
GasReturnUnhashed uint64 = 393
|
||||
GasReturnHashed uint64 = 342
|
||||
GasReturnUnhashed uint64 = 295
|
||||
GasReturnHashed uint64 = 264
|
||||
)
|
||||
|
||||
cases := map[string]struct {
|
||||
@@ -222,9 +222,9 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
|
||||
|
||||
const (
|
||||
// Note: about 100 SDK gas (10k wasmer gas) for each round of sha256
|
||||
GasWork2k uint64 = 273_851 // = InstanceCost + x // we have 6x gas used in cpu than in the instance
|
||||
GasWork2k uint64 = 271_454 // = InstanceCost + x // we have 6x gas used in cpu than in the instance
|
||||
// This is overhead for calling into a sub-contract
|
||||
GasReturnHashed uint64 = 349
|
||||
GasReturnHashed uint64 = 268
|
||||
)
|
||||
|
||||
cases := map[string]struct {
|
||||
@@ -250,8 +250,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
|
||||
Work: 2000,
|
||||
},
|
||||
expectQueriesFromContract: 5,
|
||||
// FIXME: why -2... confused a bit by calculations, seems like rounding issues
|
||||
expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) - 2,
|
||||
// FIXME: why -4... confused a bit by calculations, seems like rounding issues
|
||||
expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) - 4,
|
||||
},
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user