Anvil - trace_transaction for transactions executed before fork
Component
Anvil
Describe the feature you would like
The main use case I have for using Anvil is to trace transactions from Mainnet or other chains like Polygon and Arbitrum.
Not all Ethereum node providers support tracing and the ones that do required paid plans to call trace_transaction or debug_traceTransaction. By connecting Anvil to an archive node, I can trace a transaction connected to an archive node provider. eg Alchemy
Ideally, I'd like to fork from a block and then trace a transaction from that block or earlier.
This is not how Anvil currently works, though. If the transaction was not executed on Anvil, it will send the trace_transaction request to the node provider. This will fail as only a limited number of providers support trace_transaction and they require paid plans. For example
"trace_transaction is not available on the Free tier - upgrade to Growth or Enterprise for access.
The workaround is to fork the previous block and then send a copy of the transaction to Anvil. trace_transaction will then work as the tx was executed on Anvil.
Additional context
FYI, Hardhat node can run debug_traceTransaction against transactions from before it was forked. The problem is it's extremely slow and doesn't support the tracer option for debug_traceTransaction or trace_transaction.
linking this to https://github.com/foundry-rs/foundry/issues/2673 as this should use the same code.
we already can replay entire blocks, the logic should moved to evm crate so it can be used as cmd and by anvil
Closing as duplicate of #2673 since the underlying code will be the same