-
Notifications
You must be signed in to change notification settings - Fork 74
feat: Add state root calculation time from latest flashblock state to metering RPC #147
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
base: main
Are you sure you want to change the base?
Conversation
bea1d62 to
ea0edba
Compare
ea0edba to
20b881b
Compare
🟡 Heimdall Review Status
|
8941245 to
9830d93
Compare
70e71ed to
56ba57b
Compare
81107e1 to
76b41e6
Compare
Add state root calculation after transaction execution and measure its time independently. The state root calculation time is included in the total execution time and also tracked separately.
Update tips-core dependency to include state_root_time_us field in MeterBundleResponse. This exposes the state root calculation time as an independent metric in the metering RPC response.
Add unit test to verify total_execution_time_us >= state_root_time_us invariant and RPC integration test to verify state_root_time_us is properly exposed in the response.
Integrate flashblocks state into metering to execute bundles on top of pending flashblock state rather than canonical block state. This ensures metered gas usage and execution time accurately reflect the effects of pending transactions (nonces, balances, storage, code changes). Implementation: - Add flashblocks-rpc dependency to metering crate - Update meter_bundle() to accept optional db_cache parameter - Implement three-layer state architecture: 1. StateProviderDatabase (canonical block base state) 2. CacheDB (applies flashblock pending changes via cache) 3. State wrapper (for EVM builder compatibility) - Update MeteringApiImpl to accept FlashblocksState - Get pending blocks and db_cache from flashblocks when available - Fall back to canonical block state when no flashblocks available - Update response to include flashblock_index in logs - Require flashblocks to be enabled for metering RPC - Update all tests to pass FlashblocksState parameter The metering RPC now uses the same state as flashblocks eth_call, ensuring consistent simulation results.
Adds a single-entry cache for the latest flashblock's trie nodes, allowing bundle metering operations to reuse the cached trie computation instead of recalculating from scratch each time. Key changes: - Add FlashblockTrieCache: thread-safe single-entry cache for latest flashblock - Add FlashblockTrieData: contains trie updates and hashed state for reuse - Cache keyed by block hash and flashblock index for accuracy - Compute flashblock trie once per flashblock, reuse for all bundle operations - Extract flashblock trie calculation outside timing metrics - Use TrieInput.prepend_cached() to combine flashblock + bundle tries The cache replaces previous entries when a new flashblock is cached, as it's designed only for the current/latest flashblock, not historical ones.
The timer and field names now better reflect that they measure the total elapsed time (including both transaction execution and state root calculation), rather than just execution time. This distinguishes them from the per-transaction execution_time_us metrics. Changes: - Renamed execution_start → total_start timer - Renamed total_execution_time → total_time variable - Renamed total_execution_time_us → total_time_us in MeterBundleOutput - Updated logging and tests to use new naming - Added TODO comment for tips-core field rename
Consolidate the logic for using cached vs computed flashblock trie data by introducing a single flashblock_trie_data variable that handles both cases. This eliminates duplicate code paths in the state root calculation section.
Add comments explaining that the trie cache ensures each bundle's state root calculation measures only the bundle's incremental I/O, not the accumulated I/O from previous flashblocks.
76b41e6 to
d8c7184
Compare
| pub fn get_bundle_state(&self) -> BundleState { | ||
| self.bundle_state.clone() | ||
| } |
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.
Do we have any intuition for how expensive this clone can get? Slightly concerned about introducing a perf regression here. A not too older version here had a significant perf regression because of some extremely large clones that started happening. Im unsure how fast bundlestate can grow.
This may be worth testing on mainnet dev node before merging to main
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.
Added metrics for this in 9752d0a.
|
Could you also expand on this?
What issues existed previously and what implications does this have? i'm concerned about changes to the core processing pipeline introducing regressions not caught in the current tests. Definitely think this needs to go on mainnet dev node before being merged |
Track duration and size (number of accounts) when cloning BundleState to help identify if this becomes a performance bottleneck.
We can either remove the
Makes sense. |
Add tests verifying the correct State<CacheDB<StateProviderDatabase>> layering order. These tests demonstrate that CacheDB<State<...>> loses writes because CacheDB intercepts all writes into its internal cache without propagating them to State's bundle tracking.
|
There are now tests in 1942db8 that prove that the new |
Adds state root calculation timing with flashblock state support to the metering RPC to provide visibility into state root computation performance as an independent metric.
TODO
Key Changes
1. Flashblock State Integration
state_flashblock_indexto response2. State Root Optimization
FlashblockTrieCache: caches latest flashblock's trie nodes(block_hash, flashblock_index)TrieInput.prepend_cached()to combine cached flashblock trie with bundle changes3. State Root Metrics
4. Flashblocks-RPC Fixes (discovered during implementation)
CacheDB → StatetoState → CacheDB → StateProviderDatabasePendingBlocksnow tracks accumulatedBundleStatealongside cachewith_bundle_prestate()to accumulate state changes across flashblocks