Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading