diff --git a/go.mod b/go.mod index 2ef0060796..432ea52696 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 - github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 + github.com/bytecodealliance/wasmtime-go/v25 v25.0.0 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 github.com/gorilla/rpc v1.2.0 github.com/gorilla/websocket v1.5.0 diff --git a/go.sum b/go.sum index 71faf7f722..20c7b30435 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,8 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= -github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 h1:ur7S3P+PAeJmgllhSrKnGQOAmmtUbLQxb/nw2NZiaEM= -github.com/bytecodealliance/wasmtime-go/v14 v14.0.0/go.mod h1:tqOVEUjnXY6aGpSfM9qdVRR6G//Yc513fFYUdzZb/DY= +github.com/bytecodealliance/wasmtime-go/v25 v25.0.0 h1:ZTn4Ho+srrk0466ugqPfTDCITczsWdT48A0ZMA/TpRU= +github.com/bytecodealliance/wasmtime-go/v25 v25.0.0/go.mod h1:8mMIYQ92CpVDwXPIb6udnhtFGI3vDZ/937cGeQr5I68= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/x/contracts/runtime/call_context_test.go b/x/contracts/runtime/call_context_test.go index 98262a32e0..a040fef77b 100644 --- a/x/contracts/runtime/call_context_test.go +++ b/x/contracts/runtime/call_context_test.go @@ -9,7 +9,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" "github.com/stretchr/testify/require" "github.com/ava-labs/hypersdk/codec" diff --git a/x/contracts/runtime/config.go b/x/contracts/runtime/config.go index 9ac2449a00..1d27333c31 100644 --- a/x/contracts/runtime/config.go +++ b/x/contracts/runtime/config.go @@ -5,7 +5,7 @@ package runtime import ( "github.com/ava-labs/avalanchego/utils/units" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" ) type CompileStrategy uint8 diff --git a/x/contracts/runtime/contract.go b/x/contracts/runtime/contract.go index 8b9341630b..f7dea229ef 100644 --- a/x/contracts/runtime/contract.go +++ b/x/contracts/runtime/contract.go @@ -10,7 +10,7 @@ import ( "errors" "github.com/ava-labs/avalanchego/ids" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" "github.com/ava-labs/hypersdk/codec" ) @@ -63,21 +63,36 @@ type CallInfo struct { } func (c *CallInfo) RemainingFuel() uint64 { - remaining := c.Fuel - usedFuel, fuelEnabled := c.inst.store.FuelConsumed() - if fuelEnabled { - remaining -= usedFuel + remaining, err := c.inst.store.GetFuel() + if err != nil { + return c.Fuel } + return remaining } func (c *CallInfo) AddFuel(fuel uint64) { // only errors if fuel isn't enable, which it always will be - _ = c.inst.store.AddFuel(fuel) + remaining, err := c.inst.store.GetFuel() + if err != nil { + return + } + + _ = c.inst.store.SetFuel(remaining + fuel) } func (c *CallInfo) ConsumeFuel(fuel uint64) error { - _, err := c.inst.store.ConsumeFuel(fuel) + remaining, err := c.inst.store.GetFuel() + if err != nil { + return err + } + + if remaining < fuel { + return errors.New("out of fuel") + } + + err = c.inst.store.SetFuel(remaining - fuel) + return err } @@ -88,7 +103,12 @@ type ContractInstance struct { } func (p *ContractInstance) call(ctx context.Context, callInfo *CallInfo) ([]byte, error) { - if err := p.store.AddFuel(callInfo.Fuel); err != nil { + remaining, err := p.store.GetFuel() + if err != nil { + return nil, err + } + + if err := p.store.SetFuel(remaining + callInfo.Fuel); err != nil { return nil, err } diff --git a/x/contracts/runtime/errors.go b/x/contracts/runtime/errors.go index 90bd2db774..4c6b35f477 100644 --- a/x/contracts/runtime/errors.go +++ b/x/contracts/runtime/errors.go @@ -6,7 +6,7 @@ package runtime import ( "errors" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" ) func convertToTrap(err error) *wasmtime.Trap { diff --git a/x/contracts/runtime/import_contract.go b/x/contracts/runtime/import_contract.go index 18616a9eb3..41eaba4cef 100644 --- a/x/contracts/runtime/import_contract.go +++ b/x/contracts/runtime/import_contract.go @@ -8,7 +8,7 @@ import ( "errors" "slices" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" "github.com/ava-labs/hypersdk/codec" ) diff --git a/x/contracts/runtime/imports.go b/x/contracts/runtime/imports.go index fe2ded3bc4..3fcabf8225 100644 --- a/x/contracts/runtime/imports.go +++ b/x/contracts/runtime/imports.go @@ -4,7 +4,7 @@ package runtime import ( - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" "golang.org/x/exp/maps" ) diff --git a/x/contracts/runtime/runtime.go b/x/contracts/runtime/runtime.go index 7936b5d652..a870c0d409 100644 --- a/x/contracts/runtime/runtime.go +++ b/x/contracts/runtime/runtime.go @@ -9,7 +9,7 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/bytecodealliance/wasmtime-go/v14" + "github.com/bytecodealliance/wasmtime-go/v25" "github.com/ava-labs/hypersdk/codec" "github.com/ava-labs/hypersdk/state"