feat(metering): cache flashblock trie nodes for faster state root calculation #388
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 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
FlashblockTrieCachethat:TrieUpdatesandHashedPostStatefrom flashblock state root computationarc_swap::ArcSwapfor lock-free reads and atomic updatesTrieInputviaprepend_cached()Changes
FlashblockTrieCachewithstore()andload()methods.FlashblockTrieDatastruct andcached_flashblock_trieparameter tometer_bundle. UseTrieInput::prepend_cached()when cached data is available.FlashblockTrieCacheto load cached trie data for bundle simulations.arc-swapandreth-trie-commondependencies.Performance 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 clippypasses