Skip to content

BEP648: fix race condition in early finalization.#3547

Merged
allformless merged 1 commit intobnb-chain:developfrom
zlacfzy:debug_finality
Feb 4, 2026
Merged

BEP648: fix race condition in early finalization.#3547
allformless merged 1 commit intobnb-chain:developfrom
zlacfzy:debug_finality

Conversation

@zlacfzy
Copy link
Contributor

@zlacfzy zlacfzy commented Feb 4, 2026

Description

It's a fix for #3520
Fix a critical race condition in CheckFinalityAndNotify where the function relied on currentHeader matching targetBlockHash. Since currentHeader is updated later than highestVerifiedBlock in writeBlockAndSetHead, votes entering curVotes (via GetVerifiedBlockByHash check) would trigger CheckFinalityAndNotify before currentHeader was updated, causing the check to fail.

Rationale

In writeBlockAndSetHead, highestVerifiedBlock is set before currentHeader. When votes arrive and GetVerifiedBlockByHash returns non-nil, they enter curVotes and trigger CheckFinalityAndNotify. However, currentHeader hasn't been updated yet, so the check currentHeader.Hash() != targetBlockHash fails, preventing early finalization from working correctly.

Example

Before fix:

  • CheckFinalityAndNotify skipped due to "currentHeader mismatch"
  • Early finalization rarely triggered via VotePool

After fix:

  • Target header retrieved directly by GetHeaderByHash
  • Early finalization works reliably

Changes

Notable changes:

  • CheckFinalityAndNotify: Use GetHeaderByHash(targetBlockHash) instead of
    checking currentHeader.Hash() == targetBlockHash
  • VotePool: Add early filtering using HighestNotifiedFinal() to skip
    already-finalized blocks
  • BlockChain: Add HighestNotifiedFinal() getter for deduplication
  • Parlia: Remove finalizedNotified LRU cache

@zlacfzy zlacfzy changed the title consensus/parlia, core: fix race condition in early finalization BEP-648: fix race condition in early finalization Feb 4, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@zlacfzy zlacfzy changed the title BEP-648: fix race condition in early finalization BEP-648: fix race condition in early finalization. Feb 4, 2026
@zlacfzy zlacfzy changed the title BEP-648: fix race condition in early finalization. BEP648: fix race condition in early finalization. Feb 4, 2026
@allformless allformless merged commit 6c103a8 into bnb-chain:develop Feb 4, 2026
8 of 11 checks passed
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.

4 participants