mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
eth/tracers: pass stack into live tracer
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
efbdfbbda3
commit
561c43d873
6 changed files with 18 additions and 19 deletions
|
|
@ -2192,7 +2192,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
|
|||
if ctx.IsSet(VMTraceJsonConfigFlag.Name) {
|
||||
config = json.RawMessage(ctx.String(VMTraceJsonConfigFlag.Name))
|
||||
}
|
||||
t, _, err := tracers.LiveDirectory.New(name, config)
|
||||
t, err := tracers.LiveDirectory.New(name, config, stack)
|
||||
if err != nil {
|
||||
Fatalf("Failed to create tracer %q: %v", name, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
StateScheme: scheme,
|
||||
}
|
||||
liveTracer *tracing.Hooks
|
||||
liveAPIs []rpc.API
|
||||
)
|
||||
if config.VMTrace != "" {
|
||||
var traceConfig json.RawMessage
|
||||
|
|
@ -205,7 +204,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
traceConfig = json.RawMessage(config.VMTraceJsonConfig)
|
||||
}
|
||||
var err error
|
||||
liveTracer, liveAPIs, err = tracers.LiveDirectory.New(config.VMTrace, traceConfig)
|
||||
liveTracer, err = tracers.LiveDirectory.New(config.VMTrace, traceConfig, stack)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create tracer %s: %v", config.VMTrace, err)
|
||||
}
|
||||
|
|
@ -275,9 +274,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
// Set live tracer's backend and register the live tracer APIs
|
||||
if liveTracer != nil {
|
||||
liveTracer.SetBackend(eth.APIBackend)
|
||||
if liveAPIs != nil {
|
||||
stack.RegisterAPIs(liveAPIs)
|
||||
}
|
||||
}
|
||||
|
||||
// Successful startup; push a marker and check previous unclean shutdowns.
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
|
|||
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")
|
||||
|
||||
// Load supply tracer
|
||||
tracer, _, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)))
|
||||
tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)), nil)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to create call tracer: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
type ctorFunc func(config json.RawMessage) (*tracing.Hooks, []rpc.API, error)
|
||||
// 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) (*tracing.Hooks, error)
|
||||
|
||||
// LiveDirectory is the collection of tracers which can be used
|
||||
// during normal block import operations.
|
||||
|
|
@ -24,9 +29,9 @@ func (d *liveDirectory) Register(name string, f ctorFunc) {
|
|||
}
|
||||
|
||||
// New instantiates a tracer by name.
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage) (*tracing.Hooks, []rpc.API, error) {
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage, stack LiveApiRegister) (*tracing.Hooks, error) {
|
||||
if f, ok := d.elems[name]; ok {
|
||||
return f(config)
|
||||
return f(config, stack)
|
||||
}
|
||||
return nil, nil, errors.New("not found")
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -22,7 +21,7 @@ func init() {
|
|||
// as soon as we have a real live tracer.
|
||||
type noop struct{}
|
||||
|
||||
func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, []rpc.API, error) {
|
||||
func newNoopTracer(_ json.RawMessage, _ tracers.LiveApiRegister) (*tracing.Hooks, error) {
|
||||
t := &noop{}
|
||||
return &tracing.Hooks{
|
||||
OnTxStart: t.OnTxStart,
|
||||
|
|
@ -42,7 +41,7 @@ func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, []rpc.API, error) {
|
|||
OnCodeChange: t.OnCodeChange,
|
||||
OnStorageChange: t.OnStorageChange,
|
||||
OnLog: t.OnLog,
|
||||
}, nil, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
|
|
@ -75,15 +74,15 @@ 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) (*tracing.Hooks, []rpc.API, error) {
|
||||
func newSupply(cfg json.RawMessage, _ tracers.LiveApiRegister) (*tracing.Hooks, error) {
|
||||
var config supplyTracerConfig
|
||||
if cfg != nil {
|
||||
if err := json.Unmarshal(cfg, &config); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to parse config: %v", err)
|
||||
return nil, fmt.Errorf("failed to parse config: %v", err)
|
||||
}
|
||||
}
|
||||
if config.Path == "" {
|
||||
return nil, nil, errors.New("supply tracer output path is required")
|
||||
return nil, errors.New("supply tracer output path is required")
|
||||
}
|
||||
|
||||
// Store traces in a rotating file
|
||||
|
|
@ -107,7 +106,7 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, []rpc.API, error) {
|
|||
OnEnter: t.OnEnter,
|
||||
OnExit: t.OnExit,
|
||||
OnClose: t.OnClose,
|
||||
}, nil, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newSupplyInfo() supplyInfo {
|
||||
|
|
|
|||
Loading…
Reference in a new issue