Skip to content

Commit dbcc6c9

Browse files
Update wasmtime-go (#1705)
1 parent 1015ae1 commit dbcc6c9

File tree

9 files changed

+37
-17
lines changed

9 files changed

+37
-17
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.8
44

55
require (
66
github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0
7-
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0
7+
github.com/bytecodealliance/wasmtime-go/v25 v25.0.0
88
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
99
github.com/gorilla/rpc v1.2.0
1010
github.com/gorilla/websocket v1.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
9191
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
9292
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
9393
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
94-
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 h1:ur7S3P+PAeJmgllhSrKnGQOAmmtUbLQxb/nw2NZiaEM=
95-
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0/go.mod h1:tqOVEUjnXY6aGpSfM9qdVRR6G//Yc513fFYUdzZb/DY=
94+
github.com/bytecodealliance/wasmtime-go/v25 v25.0.0 h1:ZTn4Ho+srrk0466ugqPfTDCITczsWdT48A0ZMA/TpRU=
95+
github.com/bytecodealliance/wasmtime-go/v25 v25.0.0/go.mod h1:8mMIYQ92CpVDwXPIb6udnhtFGI3vDZ/937cGeQr5I68=
9696
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
9797
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
9898
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

x/contracts/runtime/call_context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/ava-labs/avalanchego/ids"
1111
"github.com/ava-labs/avalanchego/utils/logging"
12-
"github.com/bytecodealliance/wasmtime-go/v14"
12+
"github.com/bytecodealliance/wasmtime-go/v25"
1313
"github.com/stretchr/testify/require"
1414

1515
"github.com/ava-labs/hypersdk/codec"

x/contracts/runtime/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package runtime
55

66
import (
77
"github.com/ava-labs/avalanchego/utils/units"
8-
"github.com/bytecodealliance/wasmtime-go/v14"
8+
"github.com/bytecodealliance/wasmtime-go/v25"
99
)
1010

1111
type CompileStrategy uint8

x/contracts/runtime/contract.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"errors"
1111

1212
"github.com/ava-labs/avalanchego/ids"
13-
"github.com/bytecodealliance/wasmtime-go/v14"
13+
"github.com/bytecodealliance/wasmtime-go/v25"
1414

1515
"github.com/ava-labs/hypersdk/codec"
1616
)
@@ -63,21 +63,36 @@ type CallInfo struct {
6363
}
6464

6565
func (c *CallInfo) RemainingFuel() uint64 {
66-
remaining := c.Fuel
67-
usedFuel, fuelEnabled := c.inst.store.FuelConsumed()
68-
if fuelEnabled {
69-
remaining -= usedFuel
66+
remaining, err := c.inst.store.GetFuel()
67+
if err != nil {
68+
return c.Fuel
7069
}
70+
7171
return remaining
7272
}
7373

7474
func (c *CallInfo) AddFuel(fuel uint64) {
7575
// only errors if fuel isn't enable, which it always will be
76-
_ = c.inst.store.AddFuel(fuel)
76+
remaining, err := c.inst.store.GetFuel()
77+
if err != nil {
78+
return
79+
}
80+
81+
_ = c.inst.store.SetFuel(remaining + fuel)
7782
}
7883

7984
func (c *CallInfo) ConsumeFuel(fuel uint64) error {
80-
_, err := c.inst.store.ConsumeFuel(fuel)
85+
remaining, err := c.inst.store.GetFuel()
86+
if err != nil {
87+
return err
88+
}
89+
90+
if remaining < fuel {
91+
return errors.New("out of fuel")
92+
}
93+
94+
err = c.inst.store.SetFuel(remaining - fuel)
95+
8196
return err
8297
}
8398

@@ -88,7 +103,12 @@ type ContractInstance struct {
88103
}
89104

90105
func (p *ContractInstance) call(ctx context.Context, callInfo *CallInfo) ([]byte, error) {
91-
if err := p.store.AddFuel(callInfo.Fuel); err != nil {
106+
remaining, err := p.store.GetFuel()
107+
if err != nil {
108+
return nil, err
109+
}
110+
111+
if err := p.store.SetFuel(remaining + callInfo.Fuel); err != nil {
92112
return nil, err
93113
}
94114

x/contracts/runtime/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package runtime
66
import (
77
"errors"
88

9-
"github.com/bytecodealliance/wasmtime-go/v14"
9+
"github.com/bytecodealliance/wasmtime-go/v25"
1010
)
1111

1212
func convertToTrap(err error) *wasmtime.Trap {

x/contracts/runtime/import_contract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"errors"
99
"slices"
1010

11-
"github.com/bytecodealliance/wasmtime-go/v14"
11+
"github.com/bytecodealliance/wasmtime-go/v25"
1212

1313
"github.com/ava-labs/hypersdk/codec"
1414
)

x/contracts/runtime/imports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package runtime
55

66
import (
7-
"github.com/bytecodealliance/wasmtime-go/v14"
7+
"github.com/bytecodealliance/wasmtime-go/v25"
88
"golang.org/x/exp/maps"
99
)
1010

x/contracts/runtime/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/ava-labs/avalanchego/cache"
1111
"github.com/ava-labs/avalanchego/utils/logging"
12-
"github.com/bytecodealliance/wasmtime-go/v14"
12+
"github.com/bytecodealliance/wasmtime-go/v25"
1313

1414
"github.com/ava-labs/hypersdk/codec"
1515
"github.com/ava-labs/hypersdk/state"

0 commit comments

Comments
 (0)