Skip to content

Conversation

@niran
Copy link
Contributor

@niran niran commented Jan 12, 2026

Summary

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.

This is a prerequisite for using pending flashblock state in bundle metering.

Changes

  • pending_blocks.rs: Add bundle_state: BundleState field to track accumulated state changes across flashblocks. Add get_bundle_state() and get_db_cache() methods to expose this state.
  • processor.rs: Change layering from CacheDB<State<...>> to State<CacheDB<...>>. Add with_bundle_prestate() to accumulate state across flashblocks. Extract bundle state via merge_transitions() and take_bundle().
  • metrics.rs: Add bundle_state_clone_duration and bundle_state_clone_size metrics for observability.
  • tests/layering.rs: Add comprehensive tests verifying correct layering behavior.

Why This Matters

With the previous layering (CacheDB<State<...>>), writes go to CacheDB.cache first and State's bundle tracker never sees them. With the correct layering (State<CacheDB<...>>), State intercepts all writes and properly tracks them in its bundle, which is essential for:

  1. Computing accurate state roots for pending flashblocks
  2. Providing pending state to bundle metering simulations

Test Plan

  • Layering verification tests pass
  • Existing flashblocks tests pass
  • cargo clippy passes

@niran niran force-pushed the niran/meter-state-root-timing branch from 51db7aa to c9302b7 Compare January 12, 2026 20:03
@niran niran force-pushed the niran/flashblocks-layering-fix branch from da51cc3 to 75e8eaf Compare January 12, 2026 20:03
@danyalprout danyalprout added this to the v0.3.0 milestone Jan 12, 2026
@niran niran force-pushed the niran/flashblocks-layering-fix branch from 75e8eaf to 0cba54d Compare January 13, 2026 00:58
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.
@niran niran force-pushed the niran/flashblocks-layering-fix branch from 0cba54d to 8bca81f Compare January 13, 2026 01:22
@niran niran force-pushed the niran/meter-state-root-timing branch from c9302b7 to 8319f27 Compare January 13, 2026 01:22
@danyalprout danyalprout requested a review from meyer9 January 13, 2026 01:39
Copy link
Collaborator

@danyalprout danyalprout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to me, I would like @meyer9 to take a look too

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
meyer9
meyer9 previously approved these changes Jan 13, 2026
Copy link
Contributor

@meyer9 meyer9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG! nice simplification

@niran niran force-pushed the niran/flashblocks-layering-fix branch from 8bca81f to 25c0260 Compare January 13, 2026 01:55
@niran
Copy link
Contributor Author

niran commented Jan 13, 2026

Moved a renaming to the next PR that it was intended for

Base automatically changed from niran/meter-state-root-timing to main January 13, 2026 02:13
@danyalprout danyalprout dismissed meyer9’s stale review January 13, 2026 02:13

The base branch was changed.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jan 13, 2026

✅ Heimdall Review Status

Requirement Status More Info
Reviews 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@danyalprout danyalprout added this pull request to the merge queue Jan 13, 2026
Merged via the queue into main with commit 7c03eb9 Jan 13, 2026
24 checks passed
@danyalprout danyalprout deleted the niran/flashblocks-layering-fix branch January 13, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants