Skip to content

snap sync - apply BALs before flat db heal#10151

Merged
matkt merged 7 commits intobesu-eth:mainfrom
mirgee:snap-2-apply-bals
Apr 9, 2026
Merged

snap sync - apply BALs before flat db heal#10151
matkt merged 7 commits intobesu-eth:mainfrom
mirgee:snap-2-apply-bals

Conversation

@mirgee
Copy link
Copy Markdown
Contributor

@mirgee mirgee commented Apr 1, 2026

Pass the first pivot, stored in ChainSyncState and persisted in ChainSyncStateStorage, through SnapSyncProcessState to SnapWorldDownloadState (+ make sure to preserve it when recreating SnapSyncProcessStatein SnapSyncDownloader#storeState) where it is used in checkCompletion to decide whether BAL requests should be enqueued. Due to dependencies between request queues, enqueueing BAL requests blocks flat db requests. This means that BALs are applied (when necessary) strictly after trie healing and before flat db healing phase. Moreover, BAL request enqueuing is gated behind AtomicBoolean (+ checkCompletion is synchronized) to happen only once.

Batched BAL responses are then passed through PersistDataStep#persist to BlockAccessListDataRequest#doPersist where they are applied to the provided BonsaiWorldStateKeyValueStorage.Updater and later committed to storage. We make sure to recompute the storage root if any slots were modified.

Some functionality shared with BalStateRootCalculator (where BALs are applied to world state in a similar way) was extracted to BlockAccessListChanges. This results in extra copy - not sure about performance impact.

Follow up PR will introduce a functionality to the Pipeline which will allow to aggregate batches of items into a single batch, so that all changes from BALs are applied to the same updater and committed in one atomic operation.

mirgee added 2 commits April 1, 2026 11:05
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
@mirgee mirgee force-pushed the snap-2-apply-bals branch 2 times, most recently from 57f04b8 to 069462e Compare April 1, 2026 10:11
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
@mirgee mirgee force-pushed the snap-2-apply-bals branch from 069462e to 4bd1a47 Compare April 1, 2026 10:19
@mirgee mirgee marked this pull request as ready for review April 1, 2026 10:21
@mirgee mirgee requested a review from matkt April 1, 2026 10:21
protected PivotSyncState storeState(final PivotSyncState fastSyncState) {
final Optional<BlockHeader> firstPivotBlockHeader =
initialPivotSyncState instanceof SnapSyncProcessState snapSyncState
? snapSyncState.getFirstPivotBlockHeader().or(fastSyncState::getPivotBlockHeader)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we keep all the pivot blocks used during snapsync you can completely skip the fladb healing if all the pivot blocks used are canonical and only trigger the heal if one of the block is not canonical

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily all pivots, as we already discussed. It's a valid point but hopefully you don't want to address it in this PR :)

mirgee added 2 commits April 7, 2026 13:25
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
@mirgee mirgee force-pushed the snap-2-apply-bals branch from 65c1ff7 to 4ee4c1f Compare April 7, 2026 13:17
@mirgee mirgee requested a review from matkt April 7, 2026 13:45
final Optional<BlockHeader> maybeBlockHeader = blockchain.getBlockHeader(blockNumber);
if (maybeBlockHeader.isPresent()) {
final BlockHeader blockHeader = maybeBlockHeader.get();
enqueueRequest(createBlockAccessListDataRequest(blockHeader.getStateRoot(), blockHeader));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in another PR I think it will be better to download the BAL before in the pipeline where we are downloading header, body

Copy link
Copy Markdown
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

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

LGTM

@matkt matkt added amsterdam relating to Glamsterdam fork snapsync block-access-lists labels Apr 9, 2026
@matkt matkt moved this to Done in Block Access List Apr 9, 2026
@matkt matkt enabled auto-merge (squash) April 9, 2026 08:29
@matkt matkt merged commit 268e098 into besu-eth:main Apr 9, 2026
36 of 48 checks passed
@mirgee mirgee deleted the snap-2-apply-bals branch April 9, 2026 09:21
daniellehrner added a commit that referenced this pull request Apr 9, 2026
* Add SHL, SHR and SAR shift operations for EVM v2 (#10154)

* Add SHL, SHR and SAR implementations and benchmarks for EVM v2

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>

* Upgrade RocksDB version from 9.7.3 to 10.6.2 (#9767)

* Upgrade RocksDB version from 9.7.3 to 10.6.2
* Fix JNI SIGSEGV crashes

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>

* Add missing verification metadata (#10198)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Stream debug_traceBlock* responses directly to avoid OOM on large blocks (#9848)

* stream block traces on op code level

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* correctly parse default setting for memory tracing

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* fix initcode capture for failed create op codes

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* created separate streaming debug tracer, for batch request fall back to accumulation in memory, adddress pr comments

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* execute tests from genesis and verify full trace

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* addressed pr comments

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* spotless

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* optimize trace streaming and struct log handling

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>

* spotless

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>

* Fix remaining issues and add unit tests

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>

* added back pressure when writing to the socket and reduced the buffer size to work better with netty's default buffer size

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* improve error handling by deferring to send the header only when data is available, allows to send the proper error codes during setup

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* compactHex candidate comparison

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* wire in more performant hex writer

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* introduce separate timeout for streaming calls, defaults to 10 minutes

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* spotless

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* Fix streamin/accumulating output parity, added missing refund field, corrected error format, reason encoding, returnValue prefix, and precompile gasCost, with equivalence tests between both

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* revert accidental removal of 0x prefix

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

* pad memory bytes to 32 bytes

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>
Co-authored-by: Ameziane H. <ameziane.hamlat@consensys.net>

* Optimize performance and reduce memory when creating Quantity from scalar (#10134)

* Optimize performance and reduce memory when creating Quantity from scalar

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Benchmark other implementations

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

---------

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* snap sync - apply BALs before flat db heal (#10151)

Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>

* Remove dryRunDetector workaround methods from unit tests (#10201)

* Remove dryRunDetector workaround methods from unit tests

The dryRunDetector methods were added as a workaround for a Gradle issue
that prevented @ParameterizedTest classes from being selected when running
with --dry-run. Since the issue is fixed and --dry-run is no longer used,
these methods are no longer needed.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Remove dryRunDetector workaround from acceptance tests too

The Gradle issue is confirmed fixed, so the workaround is no longer
needed anywhere, including acceptance tests.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

---------

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* preserve state gas reservoir for the top level frame in case of OOG (#10205)

Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
Co-authored-by: ahamlat <ameziane.hamlat@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Miroslav Kovář <miroslavkovar@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants