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

Use native call tracer instead of BN tracer. #166

Closed
wants to merge 1 commit into from
Closed
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
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
Loading