move live constructor to core/tracing

This commit is contained in:
Sina Mahmoodi 2024-10-02 13:24:01 +02:00
parent 8a92d5aeac
commit b54e788759
4 changed files with 16 additions and 14 deletions

View file

@ -18,6 +18,7 @@ package tracing
import ( import (
"context" "context"
"encoding/json"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "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) 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 ( type (
// LiveConstructor is the constructor for a live tracer.
LiveConstructor = func(config json.RawMessage, stack Node, backend Backend) (*Hooks, error)
/* /*
- VM events - - VM events -
*/ */

View file

@ -5,31 +5,23 @@ import (
"errors" "errors"
"github.com/ethereum/go-ethereum/core/tracing" "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 // LiveDirectory is the collection of tracers which can be used
// during normal block import operations. // 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 { type liveDirectory struct {
elems map[string]ctorFunc elems map[string]tracing.LiveConstructor
} }
// Register registers a tracer constructor by name. // 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 d.elems[name] = f
} }
// New instantiates a tracer by name. // 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 { if f, ok := d.elems[name]; ok {
return f(config, stack, backend) return f(config, stack, backend)
} }

View file

@ -21,7 +21,7 @@ func init() {
// as soon as we have a real live tracer. // as soon as we have a real live tracer.
type noop struct{} 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{} t := &noop{}
return &tracing.Hooks{ return &tracing.Hooks{
OnTxStart: t.OnTxStart, OnTxStart: t.OnTxStart,

View file

@ -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. 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 var config supplyTracerConfig
if cfg != nil { if cfg != nil {
if err := json.Unmarshal(cfg, &config); err != nil { if err := json.Unmarshal(cfg, &config); err != nil {