Skip to content

feat: add tx_index, block env, and tx env access to TracingCtx - #296

Open
stevencartavia wants to merge 3 commits into
alloy-rs:mainfrom
stevencartavia:TracingCtx-ext
Open

feat: add tx_index, block env, and tx env access to TracingCtx#296
stevencartavia wants to merge 3 commits into
alloy-rs:mainfrom
stevencartavia:TracingCtx-ext

Conversation

@stevencartavia

@stevencartavia stevencartavia commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Motivation

TracingCtx currently exposes tx, result, state, inspector, and db. Callers that need the transaction's position in the block or access to the EVM environment must track these externally (e.g. manual idx counters, capturing block_number/base_fee from outer scope).

Solution

Add three fields to TracingCtx:

  • tx_index: usize — tracked via a counter in TracerIter, starts at 0 and increments each iteration
  • block_env: &E::BlockEnv — cloned once at TracerIter construction and passed by reference to each callback
  • tx_env: E::Tx — the resolved transaction environment used for execution

No breaking changes to the Evm trait. No unsafe code.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Comment thread crates/evm/src/tracing.rs Outdated
Comment on lines +163 to +166
let tx_env = tx.clone().into_tx_env();
let tx_index = self.tx_index;
self.tx_index += 1;
let result = self.inner.evm.transact_raw(tx_env.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is too expensive, this does more clones now

ideally we find a better solution for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed the tx_env field, added it as a method

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