AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 63 Bitcoin

bwatch: notify watch owners on reorg

Public commit record

What the developer wrote

Authored by Sangbida Chaudhuri

68/100 · Adequate
bwatch: notify watch owners on reorg

When bwatch removes its tip block on a reorg, fire watch_revert for
the affected owners so lightningd-side handlers actually run.

Two cases, depending on whether the watch has an anchor block:

- scriptpubkey watches have no anchor (a wallet address can receive
funds in any block), so notify every owner on every removed block.
Handlers are cheap and defensive — they check their own state and
no-op if there is nothing to undo.

- outpoint, scid, and blockdepth watches each carry a start_block.
Notify only those with start_block >= removed_height (the watch's
anchor is gone). Older watches stay armed and refire naturally on
the new chain.

Owners are snapshotted before dispatch so revert handlers can safely
call watchman_unwatch_* and mutate the watch tables.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a bug in Core Lightning's blockchain-watch plugin (bwatch). When the Bitcoin chain reorganizes (a block that was considered part of the chain gets replaced by a different one), bwatch was removing the old tip block without telling the rest of the node. The fix makes bwatch notify all relevant 'watch owners' before the block is discarded, so lightningd can undo any state changes tied to that now-orphaned block. Without the fix, the node could keep stale or incorrect state after a reorg, which in a Lightning node can lead to incorrect channel balances or missed on-chain events.

Recommended action

Treat this as a correctness/security fix and include it in the next maintenance release. Review lightningd-side watch_revert handlers to confirm they are idempotent and safely handle concurrent reorg events. Consider adding regression tests that simulate a reorg and verify that each watch type receives the expected watch_revert notification.

Security signals we found

01

Missing reorg notification could leave lightningd state inconsistent after chain reorganization

02

Revert handlers are now invoked in the same order blocks are removed

03

Owner snapshotting prevents mutation-safety issues during callback dispatch

04

Conditional notification by start_block avoids spurious revert traffic for older watches

Risk score

Why this scored 63/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 12/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.