Skip to content

Commit

Permalink
remove wasi time override options, default behaviour is good
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Jan 9, 2024
1 parent 7cdcc79 commit 09e4705
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ github.com/streamingfast/dmetering v0.0.0-20230731155453-e1df53e362aa h1:bM6iy5X
github.com/streamingfast/dmetering v0.0.0-20230731155453-e1df53e362aa/go.mod h1:3XggUfQMyciaue133qhbIkFqJQqNzozGpa/gI3sdwac=
github.com/streamingfast/dmetrics v0.0.0-20230516031116-28fcfeb4b9ed h1:b6EFwgne8MSK4kUjvulyyg2GGyvVUgQ+xY6o8eXlFIA=
github.com/streamingfast/dmetrics v0.0.0-20230516031116-28fcfeb4b9ed/go.mod h1:JbxEDbzWRG1dHdNIPrYfuPllEkktZMgm40AwVIBENcw=
github.com/streamingfast/dstore v0.1.1-0.20230620124109-3924b3b36c77 h1:u7FWLqz3Uwff609Ja9M+3aGOWqBCVU7dx9i6R6Qc4qI=
github.com/streamingfast/dstore v0.1.1-0.20230620124109-3924b3b36c77/go.mod h1:ngKU7WzHwVjOFpt2g+Wtob5mX4IvN90HYlnARcTRbmQ=
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 h1:K6mJPvh1jAL+/gBS7Bh9jyzWaTib6N47m06gZOTUPwQ=
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839/go.mod h1:huOJyjMYS6K8upTuxDxaNd+emD65RrXoVBvh8f1/7Ns=
Expand Down
10 changes: 6 additions & 4 deletions wasm/bench/substreams_wasi_go/lib/substreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"encoding/hex"
"fmt"
"log"
"math/rand"
"strings"
"time"

"github.com/streamingfast/substreams/wasm/bench/substreams_wasi_go/pb"
)

func mapBlock(inputs *MapBlockInput) (*pb.MapBlockOutput, error) {
//log.Print(rand.Int())
log.Print(rand.Int())

rocketAddress := strings.ToLower("ae78736Cd615f374D3085123A210448E74Fc6393")

approvalTopic := strings.ToLower("8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")
Expand All @@ -26,9 +28,9 @@ func mapBlock(inputs *MapBlockInput) (*pb.MapBlockOutput, error) {
}
log.Print("got value_123")

log.Print(time.Now())
time.Sleep(1 * time.Second)
log.Print(time.Now())
log.Printf("%s", time.Now())
time.Sleep(5 * time.Second)
log.Printf("%s", time.Now())

trxCount := 0
transferCount := 0
Expand Down
Binary file modified wasm/bench/substreams_wasi_go/main.wasm
Binary file not shown.
30 changes: 3 additions & 27 deletions wasm/wasi/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"log"
"math/rand"
"os"
"sync"
"time"
Expand Down Expand Up @@ -48,23 +49,7 @@ func newModule(ctx context.Context, wasmCode []byte, wasmCodeType string, regist
return nil, fmt.Errorf("creating new module: %w", err)
}

hostModules := []wazero.CompiledModule{}
//loggerModule, err := sfwaz.AddHostFunctions(ctx, runtime, "logger", sfwaz.LoggerFuncs)
//if err != nil {
// return nil, err
//}
//stateModule, err := sfwaz.AddHostFunctions(ctx, runtime, "state", sfwaz.StateFuncs)
//if err != nil {
// return nil, err
//}
//hostModules = append(hostModules, loggerModule, stateModule)

//startFunc := "main"
//switch wasmCodeType {
//case "go/wasi":
// startFunc = "_start"
//}

var hostModules []wazero.CompiledModule
wazConfig := wazero.NewModuleConfig()

s := bytes.NewBuffer(nil)
Expand Down Expand Up @@ -104,16 +89,7 @@ func (m *Module) ExecuteNewCall(ctx context.Context, call *wasm.Call, wasmInstan

ctx = wasm.WithContext(sfwaz.WithInstanceContext(ctx, inst), call)
config := m.wazModuleConfig.
//todo: doc says this Defaults to return a deterministic source, but this does not seem to hold. We need to investigate.
//WithRandSource(rand.New(rand.NewSource(0))).
WithWalltime(func() (sec int64, nsec int32) {
t := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
return t.Unix(), int32(t.Nanosecond())
}, sys.ClockResolution(time.Microsecond.Nanoseconds())).
WithNanotime(func() int64 {
return time.Since(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)).Nanoseconds()
}, sys.ClockResolution(1)).
WithSysNanosleep().
WithRandSource(rand.New(rand.NewSource(42))).
WithStdin(m.send).
WithStdout(m.receive).
WithStderr(NewStdErrLogWriter(ctx)).
Expand Down

0 comments on commit 09e4705

Please sign in to comment.