Skip to content

Commit

Permalink
Update wasmtime-go (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Oct 31, 2024
1 parent 1015ae1 commit dbcc6c9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/call_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 28 additions & 8 deletions x/contracts/runtime/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/import_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package runtime

import (
"github.com/bytecodealliance/wasmtime-go/v14"
"github.com/bytecodealliance/wasmtime-go/v25"
"golang.org/x/exp/maps"
)

Expand Down
2 changes: 1 addition & 1 deletion x/contracts/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dbcc6c9

Please sign in to comment.