Skip to content

feat(consensus): async fireEvents - #5578

Closed
JayT106 wants to merge 21 commits into
cometbft:mainfrom
JayT106:jt/cherry-pick-async-fireEvents
Closed

JayT106 wants to merge 21 commits into
cometbft:mainfrom
JayT106:jt/cherry-pick-async-fireEvents

Conversation

@JayT106

@JayT106 JayT106 commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

fireEvents is heavy in large block size. Consider to fire it async.
crypto-org-chain#4 (comment)

Changes

Add an asyncRunner in state/execution, it can be enabled by enable the async_fire_events in config file.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

Note

Enables asynchronous event dispatch during block execution to reduce blocking on large blocks, guarded by consensus.async_fire_events (default false).

  • Adds libs/async.TaskRunner and wires it into consensus/state and state/BlockExecutor to enqueue fireEvents when enabled, with creation on Start, cleanup on Stop, and recovery on failure
  • Updates config and template to expose consensus.async_fire_events; defaults and tests added (consensus/state_test.go, libs/async/task_runner_test.go)
  • Skips firing when eventBus is NopEventBus and preserves FIFO ordering with panic recovery
  • Introduces crypto/sr25519 (priv/pub key types, batch verifier, JSON type registration) and dependency updates
  • Adds proxy.NewConsensusSyncLocalClientCreator for consensus-serialized local ABCI interactions

Written by Cursor Bugbot for commit 21eb886. This will update automatically on new commits. Configure here.

cursor[bot]

This comment was marked as outdated.

@JayT106
JayT106 force-pushed the jt/cherry-pick-async-fireEvents branch 2 times, most recently from da20910 to fbff475 Compare January 19, 2026 20:15
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@swift1337 swift1337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain what "heavy" means in this context? Also, what is considered a "large block size"?

fireEvents is heavy in large block size...

Also, did you try async event-bus?

return NewEventBusWithBufferCapacity(defaultCapacity)

Comment thread consensus/state.go Outdated
// The getLogger function is called on each panic to retrieve the current logger.
// The stop function performs a graceful shutdown: it signals the worker to stop
// accepting new tasks, drains remaining tasks, and waits for completion.
func spawnTaskRunner(buf int, getLogger func() log.Logger) (enqueue func(func()), stop func()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This section appears more complex than necessary. Could you consider streamlining it?

Also, it's not relevant to the consensus state and should be moved outside of this package

@JayT106 JayT106 Jan 21, 2026 •

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.

Hi @swift1337 Thanks for the feedback, I don't know the testing scenario when the dev implement this feature, But I think the general idea is the move the critical path of the block execution to another executing thread. When a block has several hundred txs inside, it will create a lot of events which may increase some millisecond level's latency, for we are targeting the block time under 1 sec even lower, say 300~500ms, it might be a significant portion of it.

For the spawnTaskRunner, I will try to rework it in a better way.

@JayT106 JayT106 Jan 21, 2026 •

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.

Just did some simple benchmark, assuming 1000txs in a block and 250 bytes per tx. The buffered eventBus consumes 1.4ms in a fireEvents call. Run with Apple m1 pro chip.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JayT106
JayT106 force-pushed the jt/cherry-pick-async-fireEvents branch from 0da511e to cc05df9 Compare January 21, 2026 19:21
cursor[bot]

This comment was marked as outdated.

@JayT106
JayT106 force-pushed the jt/cherry-pick-async-fireEvents branch from 087a359 to 1b9b522 Compare January 21, 2026 21:25
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@JayT106
JayT106 force-pushed the jt/cherry-pick-async-fireEvents branch from 5240307 to e94c7f9 Compare January 22, 2026 03:28
cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

tr.Enqueue(func() {
resultsCh <- i
})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test captures loop variable by reference in closure

Low Severity

The test "executes tasks in order" captures the loop variable i by reference inside the closure passed to Enqueue. In Go versions prior to 1.22, all closures share the same i variable, so by the time tasks execute, i will be 5 for all of them. The assertion require.Equal(t, []int{0, 1, 2, 3, 4}, results) would fail on older Go versions. While Go 1.22+ scopes loop variables per-iteration, this pattern is error-prone and the test may not actually verify FIFO ordering correctly on all supported Go versions.

Fix in Cursor Fix in Web

@swift1337

Copy link
Copy Markdown
Member

I think this PR went off track. Closing

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.

2 participants