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

feat(anvil): add support for trace logging in Anvil #9895

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

zerosnacks
Copy link
Member

Motivation

Closes: #9887

Solution

Work in progress

Current output looks as follows:

Traces:
  [96345] → new <unknown>@0x5FbDB2315678afecb367f032d93F642f64180aa3
    └─ ← [Return] 481 bytes of code

...

Traces:
  [22418] 0x5FbDB2315678afecb367f032d93F642f64180aa3::d09de08a()
    ├─  storage changes:
    │   @ 0: 0 → 1
    └─ ← [Stop]

...

Traces:
  [5392] 0x5FbDB2315678afecb367f032d93F642f64180aa3::3fb5c1cb(000000000000000000000000000000000000000000000000000000000000002a)
    ├─  storage changes:
    │   @ 0: 1 → 42
    └─ ← [Stop]

It is likely possible to decode the traces to some extend using cached selectors but there is some complexity involved as all of these functions are not async.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@zerosnacks zerosnacks added T-feature Type: feature C-anvil Command: anvil labels Feb 14, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good,

what we need some feedback on is when to actually print them, always or in the non success case, especially estimate could be a bit noisy because this call multiple times

Comment on lines +92 to +100
fn print_traces(tracer: TracingInspector) {
let arena = tokio::task::block_in_place(move || {
tokio::runtime::Handle::current().block_on(async move {
let mut arena = tracer.into_traces();
let decoder = CallTraceDecoder::new();
decoder.populate_traces(arena.nodes_mut()).await;
arena
})
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially enhance this to decode the traces by using the local Foundry cache if Anvil is aware of the context it is running in. We already do something similar for Cast.

Current output looks as follows:

Traces:
  [96345] → new <unknown>@0x5FbDB2315678afecb367f032d93F642f64180aa3
    └─ ← [Return] 481 bytes of code


    Transaction: 0xfe54630a47e967d67c729e38f22942235228fc01521f4db04597c9177be18e1c
    Contract created: 0x5FbDB2315678afecb367f032d93F642f64180aa3
    Gas used: 156813

    Block Number: 1
    Block Hash: 0x25012fdbcb7c25948454ec6b8cfad6ac788b309e1637e30504f29220b12997b4
    Block Time: "Tue, 25 Mar 2025 16:28:30 +0000"

Traces:
  [22418] 0x5FbDB2315678afecb367f032d93F642f64180aa3::d09de08a()
    ├─  storage changes:
    │   @ 0: 0 → 1
    └─ ← [Stop]

Traces:
eth_getTransactionReceipt
  [5392] 0x5FbDB2315678afecb367f032d93F642f64180aa3::3fb5c1cb(000000000000000000000000000000000000000000000000000000000000002a)
    ├─  storage changes:
    │   @ 0: 1 → 42
    └─ ← [Stop]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil T-feature Type: feature
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add support for trace logging in anvil
2 participants