Skip to content

Refactor timer management to event-driven model - #188

Merged
YoshihitoAso merged 1 commit into
dev-26.9from
refactor-timer-management
Sep 24, 2026
Merged

YoshihitoAso merged 1 commit into
dev-26.9from
refactor-timer-management

Conversation

@YoshihitoAso

@YoshihitoAso YoshihitoAso commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

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

  • Serialize timer management through the consensus event loop.
  • Validate timer events against their block number, round, and generation, discarding stale or duplicate events.
  • Invalidate delayed proposals and PRE-PREPARE retries when their associated state changes.
  • Isolate timer callbacks across Stop/Start cycles.
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]
Loading
  • Add regression tests covering event ordering, stale timeouts across blocks, proposal replacement, and shutdown/restart.

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=100

All checks passed.

Copilot AI 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.

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.

@YoshihitoAso
YoshihitoAso merged commit dae56d5 into dev-26.9 Sep 24, 2026
9 of 10 checks passed
@YoshihitoAso
YoshihitoAso deleted the refactor-timer-management branch September 24, 2026 10:16
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.

[BUG] QBFT: Concurrent timer resets may leave stale timers that trigger round changes in subsequent blocks

3 participants