From b54e788759d0c5083a4bbb591d76063a0e20be67 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Wed, 2 Oct 2024 13:24:01 +0200 Subject: [PATCH] move live constructor to core/tracing --- core/tracing/hooks.go | 10 ++++++++++ eth/tracers/live.go | 16 ++++------------ eth/tracers/live/noop.go | 2 +- eth/tracers/live/supply.go | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 560b27bf00..4e40441da1 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -18,6 +18,7 @@ package tracing import ( "context" + "encoding/json" "math/big" "github.com/ethereum/go-ethereum/common" @@ -80,7 +81,16 @@ type Backend interface { GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error) } +// Node is the interface providing access to node-level +// infra such as APIs and DBs. +type Node interface { + RegisterAPIs(apis []rpc.API) +} + type ( + // LiveConstructor is the constructor for a live tracer. + LiveConstructor = func(config json.RawMessage, stack Node, backend Backend) (*Hooks, error) + /* - VM events - */ diff --git a/eth/tracers/live.go b/eth/tracers/live.go index 2678d4d17f..f4e47ed3ae 100644 --- a/eth/tracers/live.go +++ b/eth/tracers/live.go @@ -5,31 +5,23 @@ import ( "errors" "github.com/ethereum/go-ethereum/core/tracing" - "github.com/ethereum/go-ethereum/rpc" ) -// LiveApiRegister is the interface that used to register JSON-RPC APIs -type LiveApiRegister interface { - RegisterAPIs(apis []rpc.API) -} - -type ctorFunc func(config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error) - // LiveDirectory is the collection of tracers which can be used // during normal block import operations. -var LiveDirectory = liveDirectory{elems: make(map[string]ctorFunc)} +var LiveDirectory = liveDirectory{elems: make(map[string]tracing.LiveConstructor)} type liveDirectory struct { - elems map[string]ctorFunc + elems map[string]tracing.LiveConstructor } // Register registers a tracer constructor by name. -func (d *liveDirectory) Register(name string, f ctorFunc) { +func (d *liveDirectory) Register(name string, f tracing.LiveConstructor) { d.elems[name] = f } // New instantiates a tracer by name. -func (d *liveDirectory) New(name string, config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error) { +func (d *liveDirectory) New(name string, config json.RawMessage, stack tracing.Node, backend tracing.Backend) (*tracing.Hooks, error) { if f, ok := d.elems[name]; ok { return f(config, stack, backend) } diff --git a/eth/tracers/live/noop.go b/eth/tracers/live/noop.go index f7001060ae..f70bbd1e29 100644 --- a/eth/tracers/live/noop.go +++ b/eth/tracers/live/noop.go @@ -21,7 +21,7 @@ func init() { // as soon as we have a real live tracer. type noop struct{} -func newNoopTracer(_ json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) { +func newNoopTracer(_ json.RawMessage, _ tracing.Node, _ tracing.Backend) (*tracing.Hooks, error) { t := &noop{} return &tracing.Hooks{ OnTxStart: t.OnTxStart, diff --git a/eth/tracers/live/supply.go b/eth/tracers/live/supply.go index fb1c479139..fd745675d9 100644 --- a/eth/tracers/live/supply.go +++ b/eth/tracers/live/supply.go @@ -74,7 +74,7 @@ type supplyTracerConfig struct { MaxSize int `json:"maxSize"` // MaxSize is the maximum size in megabytes of the tracer log file before it gets rotated. It defaults to 100 megabytes. } -func newSupply(cfg json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) { +func newSupply(cfg json.RawMessage, _ tracing.Node, _ tracing.Backend) (*tracing.Hooks, error) { var config supplyTracerConfig if cfg != nil { if err := json.Unmarshal(cfg, &config); err != nil {