From 9c82c646e451499a2c824fb0ac2e2692d64ed69c Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 12 Apr 2022 21:09:27 +0200 Subject: [PATCH] eth/tracers: make txhash blockhash accessible to native tracers (#24679) --- eth/tracers/native/4byte.go | 2 +- eth/tracers/native/call.go | 2 +- eth/tracers/native/noop.go | 2 +- eth/tracers/native/prestate.go | 2 +- eth/tracers/native/tracer.go | 13 ++++++++----- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/eth/tracers/native/4byte.go b/eth/tracers/native/4byte.go index 5d4057689..92cc70994 100644 --- a/eth/tracers/native/4byte.go +++ b/eth/tracers/native/4byte.go @@ -55,7 +55,7 @@ type fourByteTracer struct { // newFourByteTracer returns a native go tracer which collects // 4 byte-identifiers of a tx, and implements vm.EVMLogger. -func newFourByteTracer() tracers.Tracer { +func newFourByteTracer(ctx *tracers.Context) tracers.Tracer { t := &fourByteTracer{ ids: make(map[string]int), } diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index 843c1a18f..d334e328a 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -56,7 +56,7 @@ type callTracer struct { // newCallTracer returns a native go tracer which tracks // call frames of a tx, and implements vm.EVMLogger. -func newCallTracer() tracers.Tracer { +func newCallTracer(ctx *tracers.Context) tracers.Tracer { // First callframe contains tx context info // and is populated on start and end. return &callTracer{callstack: make([]callFrame, 1)} diff --git a/eth/tracers/native/noop.go b/eth/tracers/native/noop.go index 566a8a652..0849fd74e 100644 --- a/eth/tracers/native/noop.go +++ b/eth/tracers/native/noop.go @@ -35,7 +35,7 @@ func init() { type noopTracer struct{} // newNoopTracer returns a new noop tracer. -func newNoopTracer() tracers.Tracer { +func newNoopTracer(ctx *tracers.Context) tracers.Tracer { return &noopTracer{} } diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index c7b00e5da..4d289ca62 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -51,7 +51,7 @@ type prestateTracer struct { reason error // Textual reason for the interruption } -func newPrestateTracer() tracers.Tracer { +func newPrestateTracer(ctx *tracers.Context) tracers.Tracer { // First callframe contains tx context info // and is populated on start and end. return &prestateTracer{prestate: prestate{}} diff --git a/eth/tracers/native/tracer.go b/eth/tracers/native/tracer.go index 3158654f3..3bab870ea 100644 --- a/eth/tracers/native/tracer.go +++ b/eth/tracers/native/tracer.go @@ -45,6 +45,9 @@ func init() { tracers.RegisterLookup(false, lookup) } +// ctorFn is the constructor signature of a native tracer. +type ctorFn = func(*tracers.Context) tracers.Tracer + /* ctors is a map of package-local tracer constructors. @@ -57,12 +60,12 @@ The go spec (https://golang.org/ref/spec#Package_initialization) says Hence, we cannot make the map in init, but must make it upon first use. */ -var ctors map[string]func() tracers.Tracer +var ctors map[string]ctorFn // register is used by native tracers to register their presence. -func register(name string, ctor func() tracers.Tracer) { +func register(name string, ctor ctorFn) { if ctors == nil { - ctors = make(map[string]func() tracers.Tracer) + ctors = make(map[string]ctorFn) } ctors[name] = ctor } @@ -70,10 +73,10 @@ func register(name string, ctor func() tracers.Tracer) { // lookup returns a tracer, if one can be matched to the given name. func lookup(name string, ctx *tracers.Context) (tracers.Tracer, error) { if ctors == nil { - ctors = make(map[string]func() tracers.Tracer) + ctors = make(map[string]ctorFn) } if ctor, ok := ctors[name]; ok { - return ctor(), nil + return ctor(ctx), nil } return nil, errors.New("no tracer found") }