lnwatcher: remove address callback if keep_watching is False
What changed, and why it matters
This is a small follow-up fix in Electrum's Lightning watchtower code. It ensures that when a channel closure no longer needs monitoring, the software stops watching the associated Bitcoin address. Without this cleanup, Electrum could keep polling or reacting to address updates indefinitely, wasting resources and potentially causing stale state or minor errors. The change itself is defensive housekeeping rather than a clear-cut vulnerability patch.
Treat as a routine maintenance fix. Users running Lightning nodes should update to a version containing this commit to avoid stale watchers. No urgent exploit mitigation is evident from the diff alone.
Security signals we found
Resource cleanup omission in Lightning watchtower path
Follow-up to prior commit 9b72dc297b799a01b03a95c25aec75bd4f492543
Potential stale callback/state persistence after channel closure
Evidence from the diff
In electrum/lnwatcher.py, after sweeping a commitment transaction, LNWatcher checks whether it should keep watching the channel’s closing address. Previously, if keep_watching became False, the address callback was not removed, so the watcher could continue to be triggered for that address. The patch adds self.remove_callback(address) when keep_watching is False. This is a resource-leak/state-cleanup fix. It does not, from the diff alone, demonstrate an exploitable security flaw, but it prevents continued processing for a channel that is considered closed/settled.
Changed components
electrum/lnwatcher.pyLNWatcher classLightning channel closure / sweep pathInspect captured patch +2 / −0
diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py
index 7927f65..e41497d 100644
--- a/electrum/lnwatcher.py
+++ b/electrum/lnwatcher.py
@@ -109,6 +109,8 @@ class LNWatcher(Logger, EventListener):
closing_tx = self.adb.get_transaction(closing_txid)
if closing_tx:
keep_watching = await self.sweep_commitment_transaction(funding_outpoint, closing_tx)
+ if not keep_watching:
+ self.remove_callback(address)
else:
self.logger.info(f"channel {funding_outpoint} closed by {closing_txid}. still waiting for tx itself...")
keep_watching = True
Why this scored 34/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.