lnpeer: wait_for_received_pending_htlcs_to_get_removed: wait only if peer has been initialized
What changed, and why it matters
This commit fixes a Lightning Network code path where Electrum would try to wait on a peer that had not finished initial setup. The change skips uninitialized peers instead of calling a method on them. This likely prevents a hang or crash during channel operations, but the commit message does not frame it as a security fix and no exploit details are provided.
Treat as a routine stability/defensive fix. Review whether uninitialized peers can still leave pending HTLCs unprocessed, and consider adding tests for peer-not-initialized edge cases. No urgent security response is indicated absent further disclosure.
Security signals we found
Defensive guard added around peer initialization state
Potential denial-of-service/hang vector in Lightning HTLC processing mitigated
No explicit security framing by vendor in commit message
Evidence from the diff
In electrum/lnworker.py, wait_for_received_pending_htlcs_to_get_removed() previously spawned peer.wait_one_htlc_switch_iteration() for every peer in self.lnpeermgr.peers.values() unconditionally. The patch adds an if peer.is_initialized() guard before spawning. This avoids interacting with a peer whose initialization has not completed, which could otherwise lead to awaiting on a not-yet-ready peer and potentially stalling HTLC resolution or raising an exception.
Changed components
electrum/lnworker.pyLNWallet.wait_for_received_pending_htlcs_to_get_removedLightning peer manager / HTLC switching loopInspect captured patch +2 / −1
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 259b4e8..a255c09 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -1227,7 +1227,8 @@ class LNWallet(Logger):
# that we can already fail/fulfill. e.g. forwarded htlcs cannot be removed
async with OldTaskGroup() as group:
for peer in self.lnpeermgr.peers.values():
- await group.spawn(peer.wait_one_htlc_switch_iteration())
+ if peer.is_initialized():
+ await group.spawn(peer.wait_one_htlc_switch_iteration())
while True:
if all(not peer.received_htlcs_pending_removal for peer in self.lnpeermgr.peers.values()):
break
Why this scored 31/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.