Skip to content

fix(pxe): serialize block stream event handling to prevent race conditions#22635

Merged
nchamo merged 1 commit intomerge-train/fairiesfrom
fix/block-synchronizer-event-race
Apr 17, 2026
Merged

fix(pxe): serialize block stream event handling to prevent race conditions#22635
nchamo merged 1 commit intomerge-train/fairiesfrom
fix/block-synchronizer-event-race

Conversation

@nchamo
Copy link
Copy Markdown
Contributor

@nchamo nchamo commented Apr 17, 2026

Problem

BlockSynchronizer.handleBlockStreamEvent is a public method that assumes serial invocation. While the L2BlockStream currently dispatches events serially, nothing enforces this at the handler level. If two calls were to run concurrently, a blocks-added event could race with a chain-pruned event, causing the anchor block header to be read and then modified between the check and the rollback.

Fix

Serialize handleBlockStreamEvent through a SerialQueue (the same primitive used elsewhere in the codebase for this pattern). The queue is started in the constructor and ended on stop(), ensuring all in-flight events complete before shutdown.

Fixes AztecProtocol/aztec-claude#162

@nchamo nchamo self-assigned this Apr 17, 2026
@nchamo nchamo requested a review from Thunkar April 17, 2026 11:24
Copy link
Copy Markdown
Contributor

@Thunkar Thunkar left a comment

Choose a reason for hiding this comment

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

how could this ever happen? not against the change, but seems like a responsability for the event emitter

well, I guess our handler could be slow for whatever reason and another event could come and race

@nchamo
Copy link
Copy Markdown
Contributor Author

nchamo commented Apr 17, 2026

Exactly, the potential problem was if the handler is too slow for some reason, and we get another event. The fix was quite simple, so I thought it made sense

@nchamo nchamo merged commit 6332fa2 into merge-train/fairies Apr 17, 2026
12 checks passed
@nchamo nchamo deleted the fix/block-synchronizer-event-race branch April 17, 2026 12:07
@AztecBot
Copy link
Copy Markdown
Collaborator

✅ Successfully backported to backport-to-v4-next-staging #22580.

github-merge-queue Bot pushed a commit that referenced this pull request Apr 17, 2026
BEGIN_COMMIT_OVERRIDE
fix(pxe): stop block synchronizer on PXE shutdown (#22604)
fix(aztec): respect TEST_ACCOUNTS env var in local network mode (#22600)
fix: check all aztec-nr dependency tags, not just aztec (#22483)
fix: reuse anchor block in kernel oracle (#22631)
refactor: unify contract compilation pipeline via bb aztec_process
(#22590)
fix(pxe): queue registerSender wipe to avoid racing with in-flight jobs
(#22623)
fix(pxe): bounds-check PropertySelector in pick_notes (#22614)
fix(pxe): guard private event store rollback against in-flight jobs
(#22615)
refactor(pxe): rename sideEffectCounter to initialSideEffectCounter
(#22599)
fix(pxe): correct stale authwitness comment and inverted tagging error
(#22537)
fix(aztec-nr): range-check auth witness fields before byte cast (#22624)
fix(pxe): serialize block stream event handling to prevent race
conditions (#22635)
fix(pxe): throw error on origin/contract address mismatch in simulation
(#22637)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants