Skip to content

Conversation

@mattsse
Copy link
Member

@mattsse mattsse commented Jan 27, 2026

Adds BlockTracer, BlockTracerIter, BlockTracingError, and BlockExecutorFactoryExt to support tracing transactions within block execution context.

Key features

  • BlockTracer: Wraps BlockExecutor and provides tracing methods:
    • trace / trace_many / try_trace_many - similar to TxTracer
    • trace_transaction - traces a single transaction by hash, replaying prior txs with inspector disabled
  • BlockTracerIter: Automatically calls apply_pre_execution_changes on first iteration with inspector disabled
  • BlockTracingError: Separates PreExecution, Evm, and Hook errors for proper error handling
  • BlockExecutorFactoryExt: Extension trait providing create_block_tracer convenience method

Usage

Trace all transactions

let mut tracer = factory.create_block_tracer(&mut state, env, ctx, inspector);
for result in tracer.trace_many(txs, |ctx| { /* ... */ }) {
    match result {
        Ok(output) => { /* handle trace output */ }
        Err(BlockTracingError::PreExecution(e)) => { /* system call failed */ }
        Err(BlockTracingError::Evm(e)) => { /* tx execution failed */ }
        Err(BlockTracingError::Hook(e)) => { /* hook returned error */ }
    }
}
let (evm, block_result) = tracer.finish()?;

Trace a single transaction

let tracer = factory.create_block_tracer(&mut state, env, ctx, inspector);
// Replays prior txs with inspector disabled, then traces target tx (not committed)
if let Some(output) = tracer.trace_transaction(txs, target_hash)? {
    // handle output.result and output.inspector
}

Adds BlockTracer, BlockTracerIter, BlockTracingError, and BlockExecutorFactoryExt
to support tracing transactions within block execution context.

Key features:
- BlockTracer wraps BlockExecutor and provides trace/trace_many methods
- BlockTracerIter automatically calls apply_pre_execution_changes with inspector disabled
- BlockTracingError separates PreExecution, Evm, and Hook errors
- BlockExecutorFactoryExt provides create_block_tracer convenience method

Amp-Thread-ID: https://ampcode.com/threads/T-019c0014-f406-730d-9c85-f3fb1e5faf7c
Co-authored-by: Amp <[email protected]>
@mattsse mattsse requested a review from klkvr as a code owner January 27, 2026 15:59
@mattsse mattsse force-pushed the matt/block-tracer branch 3 times, most recently from 9fc752d to 8bbbfea Compare January 27, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants