feat(flashblocks): add state trie cache warming for witness generation#568
Draft
feat(flashblocks): add state trie cache warming for witness generation#568
Conversation
Add background state trie cache warming feature that calculates state roots to pre-warm state trie caches before witness generation. This addresses performance issues when state root calculation is disabled. ## Overview When the builder runs with `disable_state_root: true`, witness generation for the state trie uses cold caches, causing slow performance. By proactively calculating state roots in the background (even though the result isn't used), we warm these caches. The warming process runs asynchronously after each flashblock, and the warm caches remain available for fast witness generation. ## Key Features - **Background warming**: State root calculation runs in background threads after each flashblock publishes, never blocking the main build pipeline - **Smart throttling**: Only one warming task runs at a time using atomic flags; additional attempts are skipped and tracked in metrics - **Non-interruptible**: State root calculation runs to completion once started, but doesn't block new FCU arrivals - **Comprehensive metrics**: Full observability with start/complete/skip/error counters and duration histograms ## Configuration New CLI flag and environment variable: - `--flashblocks.enable-state-trie-warming` (default: false) - `FLASHBLOCKS_ENABLE_STATE_TRIE_WARMING` ## Expected Performance Impact - **Cold cache state root**: ~500-2000ms (disk I/O intensive) - **Warm cache state root**: ~50-200ms (CPU-bound) - **Net improvement**: 5-10x faster witness generation - **Use case**: Helps avoid missed blocks during high-load periods ## Implementation Details 1. Added CLI flag to FlashblocksArgs 2. Added config field to FlashblocksConfig 3. Created StateTrieWarmer module with background task spawning 4. Added 5 new metrics for observability 5. Integrated warming after each flashblock publishes 6. Warming uses spawn_blocking for CPU-intensive work ## Note This is a DRAFT implementation to illustrate potential performance improvements. It has NOT been tested in production and requires thorough testing and validation before deployment. The primary goal is to demonstrate a possible solution for avoiding missed blocks by pre-warming state trie caches.
Collaborator
🟡 Heimdall Review Status
|
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.
Overview
Add background state trie cache warming feature 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=trueExpected Performance Impact
Implementation Details
FlashblocksArgs(crates/builder/base-builder-cli/src/flashblocks.rs:45-52)FlashblocksConfig(crates/builder/op-rbuilder/src/flashblocks/config.rs:40)StateTrieWarmermodule with background task spawning (crates/builder/op-rbuilder/src/flashblocks/state_trie_warmer.rs)spawn_blockingfor CPU-intensive workMetrics
Monitor the feature with:
op_rbuilder_state_trie_warming_started_count- Tasks startedop_rbuilder_state_trie_warming_completed_count- Tasks completed successfullyop_rbuilder_state_trie_warming_skipped_count- Tasks skipped (already warming)op_rbuilder_state_trie_warming_duration- Duration histogramop_rbuilder_state_trie_warming_error_count- Error countTesting Status
❌ NOT TESTED - This implementation has not been tested in any environment (dev, staging, or production).
Next Steps
Before considering for production:
Files Changed
crates/builder/base-builder-cli/src/flashblocks.rs- CLI flagcrates/builder/op-rbuilder/src/flashblocks/config.rs- Config fieldcrates/builder/op-rbuilder/src/flashblocks/state_trie_warmer.rs- Core warming logic (new file)crates/builder/op-rbuilder/src/flashblocks/payload.rs- Integration pointcrates/builder/op-rbuilder/src/flashblocks/mod.rs- Module exportscrates/builder/op-rbuilder/src/metrics.rs- New metrics