-
Notifications
You must be signed in to change notification settings - Fork 110
feat(metering): cache pending trie nodes for faster state root calculation #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
abeece0 to
d96a3ce
Compare
994978c to
13ef63c
Compare
13ef63c to
6817f24
Compare
d492e12 to
afad0ab
Compare
8dadef0 to
724a0c9
Compare
364f2ee to
c9a7614
Compare
be1c7a5 to
f1a198a
Compare
c9a7614 to
63e8c33
Compare
f1a198a to
3e17305
Compare
63e8c33 to
2867178
Compare
refcell
reviewed
Jan 13, 2026
Collaborator
✅ Heimdall Review Status
|
refcell
reviewed
Jan 13, 2026
Contributor
refcell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this needs a rebase, but otherwise, core triedb cache changes look solid
2867178 to
97374cc
Compare
danyalprout
reviewed
Jan 13, 2026
danyalprout
previously approved these changes
Jan 13, 2026
Add a single-entry cache for flashblock trie nodes to avoid redundant I/O when metering multiple bundles against the same flashblock state. Key changes: - Add FlashblockTrieCache with ensure_cached() for lazy trie computation - Add FlashblockTrieData containing TrieUpdates and HashedPostState - Update meter_bundle to accept optional cached_flashblock_trie parameter - Use TrieInput::prepend_cached() to prepend cached trie for state root - Add arc-swap and reth-trie-common dependencies When multiple bundles are metered against the same flashblock, the cache ensures the flashblock's trie is computed only once. Each bundle's state root calculation then measures only its own incremental I/O.
97374cc to
e735883
Compare
danyalprout
approved these changes
Jan 13, 2026
refcell
approved these changes
Jan 13, 2026
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
Cache trie nodes computed during pending flashblock state root calculations and reuse them across bundle metering simulations. This optimization ensures that each bundle simulation only pays the I/O cost for its own state changes, not for all previous flashblock state changes.
Problem
Without caching, every bundle simulation must:
With many bundles being simulated per flashblock, this redundant I/O becomes a bottleneck.
Solution
Introduce
PendingTrieCachethat:TrieUpdatesandHashedPostStatefrom pending state root computationarc_swap::ArcSwapfor lock-free reads and atomic updatesensure_cached()for lazy computation and cachingTrieInputviaprepend_cached()Changes
PendingTrieCachewithensure_cached()method that computes and caches the pending trie input, or returns the cached entry if it matches the current flashblock.PendingTrieInputstruct containingTrieUpdatesandHashedPostState. Add sharedcompute_pending_trie_input()helper with metrics. Updatemeter_bundleto use cached trie input when available. UseTrieInput::prepend_cached()to prepend pending trie for incremental state root calculation.PendingTrieCacheto compute/retrieve cached trie data for bundle simulations.PendingTrieCacheandPendingTrieInput.arc-swap,metrics,metrics-derive, andreth-trie-commondependencies.Metrics
New Prometheus metrics for monitoring cache performance:
reth_metering_pending_trie_cache_hits- counter for cache hitsreth_metering_pending_trie_cache_misses- counter for cache misses (trie computed)reth_metering_pending_trie_compute_duration- histogram of compute time in secondsPerformance Impact
Before: Each bundle simulation reads trie nodes for all flashblock changes
After: Each bundle simulation only reads trie nodes for its own changes
The improvement scales with:
Test Plan
cargo +nightly clippypassescargo +nightly fmtpasses