feat(flashblocks): add state trie cache warming for witness generation #568
+284
−3
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.
Overview
Add background state trie cache warming that calculates state roots to pre-warm state trie caches before witness generation. This addresses performance issues when state root calculation is disabled.
Problem Statement
When the builder runs with
disable_state_root: true, witness generation for the state trie uses cold caches, causing slow performance (~500-2000ms). This can contribute to missed blocks during high-load periods.Solution
Proactively calculate state roots in the background after each flashblock (even though the result isn't used) to warm state trie caches. The warming process runs asynchronously and the warm caches remain available for fast witness generation.
Key Features
Configuration
New CLI flag and environment variable:
--flashblocks.enable-state-trie-warming # (default: false) FLASHBLOCKS_ENABLE_STATE_TRIE_WARMING=trueImplementation Details
FlashblocksArgs(crates/builder/cli/src/flashblocks.rs)FlashblocksConfig(crates/builder/core/src/flashblocks/config.rs)StateTrieWarmermodule with background task spawning (crates/builder/core/src/flashblocks/state_trie_warmer.rs)crates/builder/core/src/metrics.rs)crates/builder/core/src/flashblocks/payload.rs)spawn_blockingfor CPU-intensive workMetrics
Monitor the feature with:
base_builder_state_trie_warming_started_count- Tasks startedbase_builder_state_trie_warming_completed_count- Tasks completed successfullybase_builder_state_trie_warming_skipped_count- Tasks skipped (already warming)base_builder_state_trie_warming_duration- Duration histogrambase_builder_state_trie_warming_error_count- Error countTest Plan (Sepolia Alpha)
FLASHBLOCKS_ENABLE_STATE_TRIE_WARMING=truestarted,completed,skipped,duration)Files Changed
crates/builder/cli/src/flashblocks.rs- CLI flagcrates/builder/cli/src/builder.rs- Config conversioncrates/builder/core/src/flashblocks/config.rs- Config fieldcrates/builder/core/src/flashblocks/state_trie_warmer.rs- Core warming logic (new file, with unit tests)crates/builder/core/src/flashblocks/payload.rs- Integration pointcrates/builder/core/src/flashblocks/mod.rs- Module exportscrates/builder/core/src/metrics.rs- New metrics