Skip to content

Commit

Permalink
Use native call tracer in trace streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-smith committed Mar 12, 2024
1 parent b3e34da commit bf79351
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions eth/filters/trace_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,11 @@ func (api *FilterAPI) NewFullBlocksWithTrace(ctx context.Context, tracerOptsJSON
return rpcSub, nil
}

var txTraceOpts = []byte(`{"withLog": true}`)

// traceTx traces a transaction with the given contexts.
func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContext, chainConfig *params.ChainConfig, statedb *state.StateDB, tracerOpts blocknative.TracerOpts) (*blocknative.Trace, error) {
tracer, err := blocknative.NewTracerWithOpts(tracerOpts)
tracer, err := tracers.DefaultDirectory.New("callTracer", txCtx, txTraceOpts)
if err != nil {
return nil, err
}
Expand All @@ -248,7 +250,13 @@ func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContex
if _, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.GasLimit)); err != nil {
return nil, fmt.Errorf("tracing failed: %w", err)
}
trace, err := tracer.GetTrace()
traceJSON, err := tracer.GetResult()
if err != nil {
return nil, err
}

trace := &blocknative.Trace{}
err = json.Unmarshal(traceJSON, trace)
if err != nil {
return nil, err
}
Expand All @@ -258,9 +266,7 @@ func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContex

// traceBlockTx traces a transaction with the given contexts.
func traceBlockTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContext, chainConfig *params.ChainConfig, statedb *state.StateDB, tracerOpts blocknative.TracerOpts) (*core.ExecutionResult, *blocknative.Trace, error) {

tracerOpts.DisableBlockContext = false
tracer, err := blocknative.NewTracerWithOpts(tracerOpts)
tracer, err := tracers.DefaultDirectory.New("callTracer", txCtx, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -272,7 +278,13 @@ func traceBlockTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockC
if err != nil {
return result, nil, fmt.Errorf("tracing failed: %w", err)
}
trace, err := tracer.GetTrace()
traceJSON, err := tracer.GetResult()
if err != nil {
return nil, nil, err
}

trace := &blocknative.Trace{}
err = json.Unmarshal(traceJSON, trace)
if err != nil {
return nil, nil, err
}
Expand Down
1 change: 1 addition & 0 deletions eth/tracers/blocknative/blocknative.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type CallFrame struct {
ErrorReason string `json:"errorReason,omitempty"`
Calls []CallFrame `json:"calls,omitempty"`
Decoded *decoder.CallFrame `json:"decoded,omitempty"`
Logs []CallLog `json:"logs,omitempty"`
}

// CallLog represents a single log entry from the receipt of a transaction.
Expand Down

0 comments on commit bf79351

Please sign in to comment.