Skip to content

Commit bf69322

Browse files
authoredMay 18, 2022
eth/tracers/js: goja tracer (#23773)
This adds a JS tracer runtime environment based on the Goja VM. The new runtime replaces the duktape runtime, which will be removed soon. Goja is implemented in Go and is faster for cases where the Go <-> JS transition overhead dominates overall performance. It is faster because duktape is written in C, and the transition cost includes the cost of using cgo. Another reason for using Goja is that go-duktape is not maintained anymore. We expect the performace of JS tracing to be at least as good or better with this change.
1 parent cc9fb8e commit bf69322

File tree

9 files changed

+1023
-69
lines changed

9 files changed

+1023
-69
lines changed
 

‎console/console_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func TestPrettyError(t *testing.T) {
285285
defer tester.Close(t)
286286
tester.console.Evaluate("throw 'hello'")
287287

288-
want := jsre.ErrorColor("hello") + "\n\tat <eval>:1:7(1)\n\n"
288+
want := jsre.ErrorColor("hello") + "\n\tat <eval>:1:1(1)\n\n"
289289
if output := tester.output.String(); output != want {
290290
t.Fatalf("pretty error mismatch: have %s, want %s", output, want)
291291
}

‎core/vm/runtime/runtime_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func TestRuntimeJSTracer(t *testing.T) {
752752
byte(vm.CREATE),
753753
byte(vm.POP),
754754
},
755-
results: []string{`"1,1,4294935775,6,12"`, `"1,1,4294935775,6,0"`},
755+
results: []string{`"1,1,952855,6,12"`, `"1,1,952855,6,0"`},
756756
},
757757
{
758758
// CREATE2
@@ -768,7 +768,7 @@ func TestRuntimeJSTracer(t *testing.T) {
768768
byte(vm.CREATE2),
769769
byte(vm.POP),
770770
},
771-
results: []string{`"1,1,4294935766,6,13"`, `"1,1,4294935766,6,0"`},
771+
results: []string{`"1,1,952846,6,13"`, `"1,1,952846,6,0"`},
772772
},
773773
{
774774
// CALL
@@ -781,7 +781,7 @@ func TestRuntimeJSTracer(t *testing.T) {
781781
byte(vm.CALL),
782782
byte(vm.POP),
783783
},
784-
results: []string{`"1,1,4294964716,6,13"`, `"1,1,4294964716,6,0"`},
784+
results: []string{`"1,1,981796,6,13"`, `"1,1,981796,6,0"`},
785785
},
786786
{
787787
// CALLCODE
@@ -794,7 +794,7 @@ func TestRuntimeJSTracer(t *testing.T) {
794794
byte(vm.CALLCODE),
795795
byte(vm.POP),
796796
},
797-
results: []string{`"1,1,4294964716,6,13"`, `"1,1,4294964716,6,0"`},
797+
results: []string{`"1,1,981796,6,13"`, `"1,1,981796,6,0"`},
798798
},
799799
{
800800
// STATICCALL
@@ -806,7 +806,7 @@ func TestRuntimeJSTracer(t *testing.T) {
806806
byte(vm.STATICCALL),
807807
byte(vm.POP),
808808
},
809-
results: []string{`"1,1,4294964719,6,12"`, `"1,1,4294964719,6,0"`},
809+
results: []string{`"1,1,981799,6,12"`, `"1,1,981799,6,0"`},
810810
},
811811
{
812812
// DELEGATECALL
@@ -818,7 +818,7 @@ func TestRuntimeJSTracer(t *testing.T) {
818818
byte(vm.DELEGATECALL),
819819
byte(vm.POP),
820820
},
821-
results: []string{`"1,1,4294964719,6,12"`, `"1,1,4294964719,6,0"`},
821+
results: []string{`"1,1,981799,6,12"`, `"1,1,981799,6,0"`},
822822
},
823823
{
824824
// CALL self-destructing contract
@@ -859,7 +859,8 @@ func TestRuntimeJSTracer(t *testing.T) {
859859
t.Fatal(err)
860860
}
861861
_, _, err = Call(main, nil, &Config{
862-
State: statedb,
862+
GasLimit: 1000000,
863+
State: statedb,
863864
EVMConfig: vm.Config{
864865
Debug: true,
865866
Tracer: tracer,

‎eth/tracers/internal/tracetest/calltrace_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func TestCallTracerNative(t *testing.T) {
134134
testCallTracer("callTracer", "call_tracer", t)
135135
}
136136

137+
func TestCallTracerLegacyDuktape(t *testing.T) {
138+
testCallTracer("callTracerLegacyDuktape", "call_tracer_legacy", t)
139+
}
140+
137141
func testCallTracer(tracerName string, dirPath string, t *testing.T) {
138142
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
139143
if err != nil {
@@ -258,7 +262,7 @@ func BenchmarkTracers(b *testing.B) {
258262
if err := json.Unmarshal(blob, test); err != nil {
259263
b.Fatalf("failed to parse testcase: %v", err)
260264
}
261-
benchTracer("callTracerNative", test, b)
265+
benchTracer("callTracer", test, b)
262266
})
263267
}
264268
}

0 commit comments

Comments
 (0)
Please sign in to comment.