-
Notifications
You must be signed in to change notification settings - Fork 108
feat(metering): use pending flashblocks state for bundle metering #387
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
da51cc3 to
75e8eaf
Compare
994978c to
13ef63c
Compare
13ef63c to
6817f24
Compare
75e8eaf to
0cba54d
Compare
6817f24 to
8dadef0
Compare
Measure and report time spent calculating state root separately from transaction execution, enabling better performance analysis: - Add MeterBundleOutput struct with state_root_time_us field - Calculate state root after transaction execution using merge_transitions - Track state root calculation time separately from total execution time - Update RPC to log state_root_time_us in metering response - Add meter_bundle_state_root_time_invariant test The state root is computed by calling hashed_post_state on the bundle and then state_root_with_updates on the state provider.
0cba54d to
8bca81f
Compare
8dadef0 to
724a0c9
Compare
Fix the database layering in flashblocks processor to use State<CacheDB<...>> instead of the incorrect CacheDB<State<...>>. The correct layering ensures that State's bundle tracking captures all writes properly. Key changes: - Add bundle_state to PendingBlocks for tracking accumulated state changes - Change processor to wrap CacheDB with State (not vice versa) - Add with_bundle_prestate() to accumulate state across flashblocks - Add layering verification tests
Add support for metering bundles against the current flashblocks pending state instead of just the canonical block state. This ensures that bundle simulations see the same state that will be used when the bundle is actually included. Key changes: - Add FlashblocksState struct containing Cache and BundleState - Update meter_bundle to accept optional FlashblocksState parameter - Implement three-layer database architecture in metering - Add integration tests for flashblock state visibility
724a0c9 to
be1c7a5
Compare
8bca81f to
25c0260
Compare
| let flashblocks_state = flashblocks_config.as_ref().map(|cfg| { | ||
| shared_state | ||
| .get_or_init(|| { | ||
| Arc::new(FlashblocksState::new( | ||
| ctx.provider().clone(), | ||
| cfg.max_pending_blocks_depth, | ||
| )) | ||
| }) | ||
| .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.
I think the metering crate needing the FlashblocksConfig to init this feels like a design flaw in our node setup.
I would suggest we make the following change in main.rs
let fb_state = Arc::new(FlashblocksState::new())
install_ext::<Flashblocks>({ fb_state.clone() })
install_ext::<Metering>({ fb_state })
We should be able to just totally remove the oncecell setup and dependency. This was the symptom of a time where we had two tokio routines racing to initialize it, but I suspect we can get rid of it now.
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.
FlashblocksState needs a Client/Provider object, which we currently get from the context passed to extend_rpc_modules. Unless the builder provides a way to get a reference to something that will eventually give us a provider, we're kind of stuck. One option we still have is to move
the cell inside FlashblocksState, which should be able to give us your code snippet above. But it just moves the mess somewhere else, and probably adds more of it since FlashblocksState would be full of checks for an empty cell.
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.
Gotcha, lets pair tomorrow morning, I have an idea
🟡 Heimdall Review Status
|
Summary
Enable bundle metering to use the current pending flashblocks state instead of just the canonical block state. This ensures that bundle simulations see the same state that will be used when the bundle is actually included in a flashblock.
Changes
Metering Crate
FlashblocksStatestruct containingCacheandBundleState. Updatemeter_bundleto accept an optionalFlashblocksStateparameter. Implement three-layer database architecture:State<CacheDB<StateProviderDatabase>>where:StateProviderDatabasereads from canonical chain stateCacheDBprovides pending flashblock reads via the cacheStatetracks bundle writes with flashblock prestate viawith_bundle_prestate()MeteringApiImplto integrate with flashblocks API. Get pending blocks state and pass it tometer_bundle. Includestate_flashblock_indexin response.MeteringExtensionto accept flashblocks configuration and cell.FlashblocksState.Flashblocks Crate
Architecture
Test Plan
cargo clippypasses