Skip to content

feat(anvil): add --max-tx-inclusion-time-in-slot option#13402

Draft
spalladino wants to merge 1 commit intofoundry-rs:masterfrom
spalladino:feat/max-tx-inclusion-time-in-slot
Draft

feat(anvil): add --max-tx-inclusion-time-in-slot option#13402
spalladino wants to merge 1 commit intofoundry-rs:masterfrom
spalladino:feat/max-tx-inclusion-time-in-slot

Conversation

@spalladino
Copy link
Contributor

@spalladino spalladino commented Feb 9, 2026

To simulate real-world inclusion, it'd be handy to have Anvil include txs in the next block only if these txs were sent with enough time in advance to be picked up. I asked Claude to add this to Anvil as a flag, and here's the work it produced.

The PR is flagged as draft since I still want to make another pass myself at Claude's code, but before I do so, I'm curious if this feature would be in scope for Anvil, or it's not something you'd be interested in merging.


Summary

  • Adds a new --max-tx-inclusion-time-in-slot CLI option to anvil that simulates a validator transaction inclusion cutoff during interval mining
  • When configured, transactions submitted after slot_start + max_tx_inclusion_time_in_slot are excluded from the current block and reconsidered in the next one
  • Allows testing timing-sensitive logic (e.g. MEV, auction deadlines) more realistically against anvil

Semantics

  • Option: --max-tx-inclusion-time-in-slot <SECONDS> (requires --block-time)
  • Slot: [block_timestamp - block_time, block_timestamp)
  • Inclusion rule: tx included if tx.submission_timestamp <= slot_start + max_tx_inclusion_time_in_slot
  • Excluded txs remain in the pool and are reconsidered for the next block
  • Default: None (disabled, preserving current behavior)

Changes

File Change
crates/anvil/src/eth/pool/transactions.rs Add timestamp: u64 to PoolTransaction
crates/anvil/src/eth/backend/time.rs Add current_time() method to TimeManager
crates/anvil/src/eth/api.rs Stamp transactions with current time at submission
crates/anvil/src/eth/backend/mem/mod.rs Store config in Backend, filter in do_mine_block
crates/anvil/src/cmd.rs Add --max-tx-inclusion-time-in-slot CLI arg
crates/anvil/src/config.rs Add NodeConfig field and builder method
crates/anvil/tests/it/anvil.rs 4 new tests for inclusion, exclusion, carry-over, and default behavior

Test plan

  • All 281 existing anvil tests pass
  • 4 new tests covering:
    • Early tx included in block
    • Late tx excluded from block (remains in pool)
    • Excluded tx gets included in the next block
    • Default behavior (no option) includes all txs
  • Manual test: anvil --block-time 12 --max-tx-inclusion-time-in-slot 4

🤖 Generated with Claude Code

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.

I feel like this is kinda similar to sendRawTransactionConditional

so I wonder if we should just adopt this as meta info on the pooled tx type instead?

then we could still layer the cli arg behaviour on top later and make this the default for all incoming txs?

does that make sense?

@spalladino
Copy link
Contributor Author

Interesting! I didn't know ERC7796, but I think it makes sense. So, to double check I understood you correctly:

  • We remove the timestamp field of the PoolTransaction in favor of a conditions struct, with a timestampMin or blockNumberMin (to be extended to all fields of sendRawTransactionConditional eventually)
  • We check these fields when picking the txs to include on the next block
  • We keep the max-tx-inclusion-time-in-slot CLI argument, and use it to manually populate the blockNumberMin based on the current time when the tx is received (ie we set blockNumberMin to currentBlock+2 if currentBlock.timestamp + maxInclusionTimeInSlot < currentTime)

Does it make sense?

…796)

Replace the raw `timestamp: u64` field on `PoolTransaction` with
`conditions: Option<TransactionConditional>` from alloy, moving the
inclusion logic from mining-time timestamp comparison to submission-time
`block_number_min` computation via `compute_tx_conditions()`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@spalladino spalladino force-pushed the feat/max-tx-inclusion-time-in-slot branch from 8ee8095 to a9fb407 Compare February 14, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants