Skip to content

fix(cache): rank ingested items with the live env basefee, not 0#280

Merged
Evalir merged 2 commits into
mainfrom
fix/cache-task-env-basefee
Jun 10, 2026
Merged

fix(cache): rank ingested items with the live env basefee, not 0#280
Evalir merged 2 commits into
mainfrom
fix/cache-task-env-basefee

Conversation

@Evalir

@Evalir Evalir commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

CacheTask::task_future declared basefee as a loop-local that was reset to 0 at the top of every select! iteration and assigned (sim_env.basefee) only in the envs.changed() arm. Because add_bundle/add_tx run in the other select! arms — i.e. separate loop iterations — they always received basefee = 0. Cached items were therefore ranked by effective_gas_price(0) instead of the env basefee.

Impact

The basefee feeds only SimItem::calculate_total_fee, whose result is the cache's ranking key — a heuristic for simulation/inclusion order and the eviction key when the cache is over capacity. It does not affect block validity or execution (the real basefee is applied by the EVM during building).

So the effect is limited to ordering/eviction quality:

  • Negligible on gouda (basefee ~7 wei) — the ranking is effectively identical to correct, which is why this is not the bundle-inclusion failure.
  • Latent on any higher-basefee chain or congested period, where the missing basefee · gas term can reorder gas-heavy items or evict the wrong item under capacity pressure → at worst a marginally less profitable block.

Fix

Read the block number and basefee from the live env at ingest time via a new current_block_and_basefee() helper, used by both ingest arms; the loop-local basefee = 0 is removed.

Closes ENG-2333

Test

cache_task_ranks_with_env_basefee drives a real CacheTask, publishes an env with a known basefee, ingests a tx whose effective tip depends on the basefee, and asserts the cached rank matches calculate_total_fee(env_basefee) (with a guard that the basefee actually changes the rank, so it fails on the bug).

Validation

cargo build, the new test, cargo +nightly fmt, cargo clippy --lib --all-targets (no warnings), and the cache-module tests all pass.

🤖 Generated with Claude Code

CacheTask declared basefee as a loop-local reset to 0 on every select! iteration and assigned it only in the envs.changed() arm. Because add_bundle/add_tx run in the other select! arms (separate loop iterations), they always received basefee 0, so cached items were ranked by effective_gas_price(0) instead of the env basefee.

The rank is only a simulation-order and cache-eviction heuristic, so the impact is limited to ordering/eviction quality (negligible at gouda's ~7 wei basefee, latent on higher-basefee chains); it does not affect block validity or execution. Fixed by reading the block number and basefee from the live env at ingest time via current_block_and_basefee.

Adds cache_task_ranks_with_env_basefee as a regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Evalir commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Evalir Evalir marked this pull request as ready for review June 9, 2026 15:53
Comment thread src/tasks/cache/task.rs Outdated
Co-authored-by: Fraser Hutchison <190532+Fraser999@users.noreply.github.com>
@Evalir Evalir merged commit 4edf3cb into main Jun 10, 2026
7 checks passed
@Evalir Evalir deleted the fix/cache-task-env-basefee branch June 10, 2026 21:26
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