-
Notifications
You must be signed in to change notification settings - Fork 58
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
Draft
niran
wants to merge
10
commits into
main
Choose a base branch
from
meter-state-root
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
bea1d62 to
ea0edba
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.
Corrects the database architecture to properly layer State -> CacheDB -> StateProviderDatabase, and ensures both cache and bundle state accumulate across flashblocks for accurate state root calculations in bundle metering. Key changes: - Fix database layering: State now wraps CacheDB instead of CacheDB wrapping State - Track accumulated bundle state in PendingBlocks alongside cache - Apply bundle prestate when building state to include previous flashblocks changes - Use merge_transitions before take_bundle to properly extract accumulated state
ea0edba to
20b881b
Compare
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.
🟡 Heimdall Review Status
|
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.
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
state_root_time_usfield in response4. Flashblocks-RPC Fixes (discovered during implementation)
CacheDB → StatetoState → CacheDB → StateProviderDatabasePendingBlocksnow tracks accumulatedBundleStatealongside cachewith_bundle_prestate()to accumulate state changes across flashblocksTesting
Dependencies: Bumped
tips-coreto86b275c0fd63226c3fb85ac5512033f99b67d0f5