feat(consensus): add opt-in asynchronous block event publication - #6040
Open
songgaoye wants to merge 6 commits into
Open
feat(consensus): add opt-in asynchronous block event publication#6040songgaoye wants to merge 6 commits into
songgaoye wants to merge 6 commits into
Conversation
Contributor
|
PR author is not in the allowed authors list. |
songgaoye
marked this pull request as draft
August 25, 2026 03:48
songgaoye
marked this pull request as ready for review
August 25, 2026 04:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Block events are currently published synchronously at the end of
ApplyBlock. For blocks containing many transactions, event construction and publication remain on the consensus critical path.Increasing
event_bus_buffer_capacityreduces subscriber backpressure, but does not remove this processing cost fromApplyBlock.This issue was previously observed in crypto-org-chain#4 (comment), where profiling showed synchronous
fireEventsdelaying block execution. That observation motivates this work, while the benchmarks added by this PR provide reproducible evidence across controlled scenarios.This PR adds opt-in asynchronous block event publication while preserving the existing synchronous behavior by default. Block-event tasks are processed in submission order through a bounded serial runner, and accepted work is drained before the EventBus and indexer are stopped.
Event ordering
When asynchronous publication is enabled, block events may temporarily lag behind block execution and other synchronously published EventBus events.
FIFO ordering is preserved between queued block-event tasks. However, global ordering across different EventBus publishers is not guaranteed. For example, after the block events for height H are queued, consensus may publish
NewRoundStepfor height H+1 before clients receiveNewBlockor transaction events for height H.This does not affect consensus, block execution, or persisted state. Event consumers using asynchronous mode should rely on event heights and must not assume delivery order across different event types.
Benchmarks
The benchmarks compare synchronous and asynchronous publication across several scenarios:
ApplyBlock.The most relevant case uses 1,000 transactions and an EventBus capacity of 2,048. The buffer can hold all 1,003 events emitted for the block, so EventBus backpressure is not the bottleneck.
Representative results on Apple M4:
ApplyBlocktimeThis reduces the measured
ApplyBlockcritical-path time by approximately 3.5–4x, demonstrating that increasing the EventBus buffer alone does not eliminate the benefit of asynchronous publication.This optimization moves event processing out of the consensus critical path. It does not reduce the total event-processing work, and event consumers may temporarily lag behind block execution.
Testing
Unit and lifecycle tests cover:
go test ./consensus ./state ./nodePR checklist
CHANGELOG.mddocs/orspec/) and code comments