go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

eth/tracers: trace without passing ctx

Open jsvisa opened this issue 1 year ago • 2 comments

Since the tracers.Context is only utilized by the JS tracer and flatcall tracer, and we've previously introduced tracing hooks, I think we can eliminate passing the context directly. If the context is needed, it can be retrieved within the hooks.

This change will benefit the live tracer, as it is initialized once, whereas the debug tracer is initialized for each transaction.

The changes: in the updated js tracer, txHash and txIndex have been introduced in the OnTxStart and OnTxEnd hooks. Previously, these variables were introduced immediately after the trace was initialized.

@s1na ptal.

jsvisa avatar Aug 21 '24 17:08 jsvisa

Hm good insight that context is not widely used. I guess what I like about your idea is that we don't have to call OnBlockStart everywhere, only where there is actually a block (e.g. traceBlock*, but not traceCall). What I don't like is that it feels weird to have OnBlockStart without OnBlockEnd. And also it is a change to the tracing interface and will break people's code without adding any "feature".

s1na avatar Aug 22 '24 07:08 s1na

What I don't like is that it feels weird to have OnBlockStart without OnBlockEnd.

This is considered to replace the original method of injecting the blockhash, txIndex, txHash fields during initialization. Originally, the context was set for each transaction, but now the VMContext data at OnTxStart is not as full as the context.

And also it is a change to the tracing interface and will break people's code without adding any "feature".

This PR is intended for live tracing(reuse the code in the eth/traces), as live tracing is always running and cannot pass in the context like debug_traceXXX. Therefore, it can only start from the few hooks at OnBlockStart.

jsvisa avatar Aug 22 '24 15:08 jsvisa

This PR is quite stale, going to close for now. Please reopen once you rebase and want to continue pursuing.

lightclient avatar May 02 '25 15:05 lightclient