-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(anvil): add PreStateTracer support for debug_traceTransaction #11709
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@w1tcher thank you! please rebase and add a test, here are some samples
foundry/crates/anvil/tests/it/traces.rs
Line 161 in 86d5c5b
async fn test_call_tracer_debug_trace_call() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this works, this is mega extra overhead on top of the overhead of recorded traces that we already have
imo we should instead cleanup the existing replay functionality that we use for the js tracer and make this general purpose replay
gas_used: u64, | ||
logs: Vec<Log>, | ||
traces: Vec<CallTraceNode>, | ||
exec_state: ResultAndState<OpHaltReason>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always storing this is quite expensive, even storing the calltracenode is kind of excessive
we now have a way to replay+trace the transactions, although it isnt super pretty (yet)
foundry/crates/anvil/src/eth/backend/mem/mod.rs
Lines 2642 to 2644 in 86d5c5b
/// Traces the transaction with the js tracer | |
#[cfg(feature = "js-tracer")] | |
pub async fn trace_tx_with_js_tracer( |
instead of storing all state outputs like this we should invest a bit more into making this function more resuable for any kind of tracer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced a new function, replay_tx_with_inspector
, whose main purpose is to replay a transaction by its hash and retrieve its execution result, trace, and other related data for generating the corresponding response. Additionally, I removed the previously added extra data.
fn replay_tx_with_inspector<I, F, T>(
&self,
hash: B256,
mut inspector: I,
f: F,
) -> Result<T, BlockchainError>
where
for<'a> I: Inspector<EthEvmContext<WrapDatabaseRef<&'a CacheDB<Box<&'a StateDb>>>>>
+ Inspector<OpContext<WrapDatabaseRef<&'a CacheDB<Box<&'a StateDb>>>>>
+ 'a,
for<'a> F:
FnOnce(ResultAndState<OpHaltReason>, CacheDB<Box<&'a StateDb>>, I, TxEnv, Env) -> T,
{
@grandizzy I have added test cases. |
Motivation
This commit introduces support for the PreStateTracer in anvil's
debug_traceTransaction RPC method. With this change, users can now
obtain detailed pre-state information (accounts, storage, and balances)
when tracing transactions, enabling more advanced debugging and state
analysis workflows.
Solution
By storing the state changes generated during transaction execution in the exec_state variable, the PreStateTracer can later retrieve this data and return the relevant information.
PR Checklist