Skip to content

Commit

Permalink
update to wasmtime v22
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 25, 2024
1 parent cbfcbd3 commit b67d23f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22

require (
github.com/bits-and-blooms/bitset v1.5.0
github.com/bytecodealliance/wasmtime-go/v12 v12.0.0
github.com/c-bata/go-prompt v0.2.6
github.com/dave/dst v0.27.2
github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c
Expand All @@ -31,6 +30,7 @@ require (

require (
github.com/SaveTheRbtz/mph v0.1.1-0.20240117162131-4166ec7869bc
github.com/bytecodealliance/wasmtime-go/v22 v22.0.0
github.com/k0kubun/pp v3.0.1+incompatible
github.com/kodova/html-to-markdown v1.0.1
github.com/onflow/crypto v0.25.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8=
github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/bytecodealliance/wasmtime-go/v12 v12.0.0 h1:Wga02UaZXYF3p0LIeL5xFp09/RI7UhjfT2uB0mLrwlw=
github.com/bytecodealliance/wasmtime-go/v12 v12.0.0/go.mod h1:a3PRoftJxxUzkQvgjC6sv7pKyJJK0ZsFVmH+eeEKQC4=
github.com/bytecodealliance/wasmtime-go/v22 v22.0.0 h1:QHVD/Ppl3gsaBmrP3tytsiaw/Bs/gGB16kEsO3+0N7o=
github.com/bytecodealliance/wasmtime-go/v22 v22.0.0/go.mod h1:knqkvjTLavLtAXnA5NJUM0qbRiPJCVWPLXfYu75kZSo=
github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI=
github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
28 changes: 7 additions & 21 deletions runtime/webassembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package runtime
import (
"fmt"

"github.com/bytecodealliance/wasmtime-go/v12"
"github.com/bytecodealliance/wasmtime-go/v22"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/errors"
Expand Down Expand Up @@ -187,12 +187,11 @@ func newWasmtimeFunctionWebAssemblyExport(

// Call the function, with metering

fuelConsumedBefore, _ := store.FuelConsumed()

// TODO: get remaining computation and convert to fuel.
// needs e.g. invocation.Interpreter.RemainingComputation()
const todoAvailableFuel = 1000
err := store.AddFuel(todoAvailableFuel)
const todoAvailableFuel uint64 = 1000
fuelBefore := todoAvailableFuel
err := store.SetFuel(fuelBefore)
if err != nil {
// TODO: wrap error
panic(err)
Expand All @@ -204,26 +203,13 @@ func newWasmtimeFunctionWebAssemblyExport(
panic(err)
}

fuelConsumedAfter, _ := store.FuelConsumed()
fuelDelta := fuelConsumedAfter - fuelConsumedBefore

inter.ReportComputation(common.ComputationKindWebAssemblyFuel, uint(fuelDelta))

remainingFuel, err := store.ConsumeFuel(0)
fuelAfter, err := store.GetFuel()
if err != nil {
// TODO: wrap error
panic(err)
}

remainingFuel, err = store.ConsumeFuel(remainingFuel)
if err != nil {
// TODO: wrap error
panic(err)
}

if remainingFuel != 0 {
panic(errors.NewUnreachableError())
}
fuelDelta := fuelBefore - fuelAfter
inter.ReportComputation(common.ComputationKindWebAssemblyFuel, uint(fuelDelta))

// Return the result

Expand Down
2 changes: 2 additions & 0 deletions tools/storage-explorer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,9 @@ github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh
github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM=
github.com/bytecodealliance/wasmtime-go v1.0.0/go.mod h1:jjlqQbWUfVSbehpErw3UoWFndBXRRMvfikYH6KsCwOg=
github.com/bytecodealliance/wasmtime-go/v12 v12.0.0/go.mod h1:a3PRoftJxxUzkQvgjC6sv7pKyJJK0ZsFVmH+eeEKQC4=
github.com/bytecodealliance/wasmtime-go/v22 v22.0.0/go.mod h1:knqkvjTLavLtAXnA5NJUM0qbRiPJCVWPLXfYu75kZSo=
github.com/bytecodealliance/wasmtime-go/v7 v7.0.0/go.mod h1:bu6fic7trDt20w+LMooX7j3fsOwv4/ln6j8gAdP6vmA=
github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY=
Expand Down
2 changes: 1 addition & 1 deletion vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"C"

"github.com/bytecodealliance/wasmtime-go/v12"
"github.com/bytecodealliance/wasmtime-go/v22"

"github.com/onflow/cadence/runtime/interpreter"
)
Expand Down

0 comments on commit b67d23f

Please sign in to comment.