fix(cache): rank ingested items with the live env basefee, not 0#280
Merged
Conversation
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>
Fraser999
approved these changes
Jun 10, 2026
Co-authored-by: Fraser Hutchison <190532+Fraser999@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
CacheTask::task_futuredeclaredbasefeeas a loop-local that was reset to0at the top of everyselect!iteration and assigned (sim_env.basefee) only in theenvs.changed()arm. Becauseadd_bundle/add_txrun in the otherselect!arms — i.e. separate loop iterations — they always receivedbasefee = 0. Cached items were therefore ranked byeffective_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:
basefee · gasterm 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-localbasefee = 0is removed.Closes ENG-2333
Test
cache_task_ranks_with_env_basefeedrives a realCacheTask, publishes an env with a known basefee, ingests a tx whose effective tip depends on the basefee, and asserts the cached rank matchescalculate_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