Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/tracers: make txhash blockhash accessible to native tracers #24679

Merged
merged 1 commit into from
Apr 12, 2022
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 eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}}
Expand Down
13 changes: 8 additions & 5 deletions eth/tracers/native/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -57,23 +60,23 @@ 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
}

// 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")
}