Repository navigation
Refactor timer management to event-driven model - #188
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Timer state is serialized, stale events are comprehensively validated, and focused regression tests cover the identified race scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Refactors QBFT timer handling into the consensus event loop, preventing stale timers from affecting later rounds or blocks.
Changes:
- Adds generation- and view-aware timer events.
- Integrates timer lifecycle with consensus startup, shutdown, and state transitions.
- Adds regression coverage for stale, replaced, duplicated, and restarted timers.
| File | Description |
|---|---|
core/timer.go |
Implements event-driven timer scheduling and validation. |
core/timer_test.go |
Adds timer regression and lifecycle tests. |
core/request.go |
Schedules delayed empty-block proposals through timer events. |
core/preprepare.go |
Moves deferred PRE-PREPARE retries into the timer system. |
core/handler.go |
Integrates timer events with the consensus loop. |
core/events.go |
Removes the obsolete timeout event. |
core/core.go |
Consolidates timer state and lifecycle management. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
purplesmoke05
approved these changes
Sep 24, 2026
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
close #187
Fix a QBFT timer race that could trigger premature round changes and delay empty-block production.
The empty-block delay callback and PRE-PREPARE acceptance previously reset the round-change timer concurrently. This could leave an untracked timer active after block commitment. Because timeout events carried no block or round information, a stale timeout could affect a subsequent block.
Changes
flowchart LR A[Timer expires] --> B[Send internal event] B --> C[QBFT event loop] D[Receive PRE-PREPARE or other messages] --> C E[Block commitment notification] --> C C --> F[Check whether the event is still valid] F -->|Valid| G[Manage timers and process consensus] F -->|Invalid| H[Discard event]No public API, wire-format, or configuration changes.
Validation
go test ./consensus/istanbul/...go test -race ./consensus/istanbul/qbft/...go test -race ./consensus/istanbul/qbft/core -run '^TestTimer' -count=100All checks passed.