Skip to content

Conversation

@haardikk21
Copy link
Collaborator

@haardikk21 haardikk21 commented Sep 5, 2025

Cross block state management for flashblocks

Optimistically queues flashblocks state updates and overrides, even across block boundaries. Will clear pending state if canonical block signals a reorg occured.

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.

lgtm (assuming we optimize the perf in a follow up)

To test this, can we clone this test, but make the flashblocks across block:

https://github.com/base/node-reth/blob/main/crates/flashblocks-rpc/src/tests/state.rs#L289

@haardikk21 haardikk21 marked this pull request as ready for review September 10, 2025 13:46
@haardikk21 haardikk21 merged commit ccc557c into main Sep 10, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Project Tracking Sep 10, 2025
@haardikk21 haardikk21 deleted the pending-state-cross-blocks branch September 10, 2025 21:06
}
fn get_balance(&self, address: Address) -> Option<U256> {
self.pending_blocks
.load_full()
Copy link
Contributor

@SozinM SozinM Sep 11, 2025

Choose a reason for hiding this comment

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

better to use .load if possible (you will need deref it), because you have 5 premade instances that could be used instantly (and if it exhausted it will fallback to load_full)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do this in a follow-up.

next_log_index += receipt.logs().len();

let mut should_execute_transaction = false;
match &prev_pending_blocks {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is interesting part, would we have state at all, i assume we receive only new transaction in flashblocks
And will this be cleaned on reorgs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, because we have vec of flashblocks
This part could be speed up, because we statically know which transactions should we execute. Only last flashblock should have unexecuted transactions

Copy link
Collaborator Author

@haardikk21 haardikk21 Sep 12, 2025

Choose a reason for hiding this comment

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

technically yeah, can probably remove that check in exchange for extracting last flashblock txns separately and checking if current tx is in the set of the last fb's txns. not sure will be much of a difference in practice but can be done as a small follow up

@SozinM
Copy link
Contributor

SozinM commented Sep 11, 2025

Looks great IMO, only 2 places when i see simple optimisations

0xsimulacra pushed a commit to 0xsimulacra/base-node-reth that referenced this pull request Oct 1, 2025
* first pass at cross-block state management

* please clippy

* rename fb_state to state

* add test for persisting state overrides across blocks

* add test for canonical block progression

* add reorg handling on canonical block

* naive hacky caching

* reduce repeated code and cleanup

* add reorg handling test, add sequential cross-block pending state build-up test

* lockfile

* process flashblocks via a channel queue to avoid data race
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