lnwatcher: early return in sweep_commitment_transaction if chan.need_to_subscribe returns False
What changed, and why it matters
This commit adds an early exit in Electrum's Lightning watchtower code so it stops trying to sweep a closed channel if the channel reports it no longer needs monitoring. Without this guard, the watcher could continue running sweep logic on a channel that has already been settled or is otherwise inactive, potentially causing unnecessary on-chain transactions, wasted fees, or confusion in recovery flows. The change is small and defensive.
Review the implementation and call sites of chan.need_to_subscribe() to confirm it correctly identifies channels that should no longer be swept. Consider adding tests covering the new early-return branch and monitor for any user reports of stuck funds after channel closes.
Security signals we found
Defensive early return added to prevent sweep logic on unsubscribed channels
Potential for unnecessary or invalid on-chain sweeps without the guard
Change is partial/context-dependent; full security impact depends on need_to_subscribe semantics
Evidence from the diff
In electrum/lnwatcher.py, sweep_commitment_transaction() now returns False immediately if chan.need_to_subscribe() is False. Previously it only checked that the channel existed. The new guard prevents the watcher from proceeding to detect the closing party, build sweep_info_dict, and attempt to claim outputs for channels that have explicitly opted out of further subscription. A logging line was also added to record when the sweep path is actually entered.
Changed components
electrum/lnwatcher.pyLNWatcher.sweep_commitment_transactionLightning channel sweep/recovery flowInspect captured patch +3 / −0
diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py
index 126fb94..6a4842c 100644
--- a/electrum/lnwatcher.py
+++ b/electrum/lnwatcher.py
@@ -153,6 +153,9 @@ class LNWatcher(Logger, EventListener):
chan = self.lnworker.channel_by_txo(funding_outpoint)
if not chan:
return False
+ if not chan.need_to_subscribe():
+ return False
+ self.logger.info(f'sweep_commitment_transaction {funding_outpoint}')
# detect who closed and get information about how to claim outputs
is_local_ctx, sweep_info_dict = chan.get_ctx_sweep_info(closing_tx)
# note: we need to keep watching *at least* until the closing tx is deeply mined,
Why this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.