create_channel_backup: handle case where peer_addresses list is empty
What changed, and why it matters
This commit fixes a crash in Electrum's Lightning channel backup feature. Previously, if a channel had no known peer addresses, the code would try to access the first item of an empty list and fail. The fix safely handles that case by using empty host and port values instead. It is a defensive bug fix that prevents an unhandled exception, but the commit itself does not describe any security relevance.
Treat as a routine stability/robustness fix. No urgent security action is indicated by the commit alone. Users relying on Lightning channel backups may benefit from the fix to avoid backup failures when peer addresses are unavailable.
Security signals we found
Fixes an unhandled exception (IndexError) in channel backup creation
Defensive null/empty-list handling for peer address data
No explicit security claim made by vendor in commit message or diff
Evidence from the diff
In electrum/lnworker.py, create_channel_backup() previously assumed chan.get_peer_addresses() always returned at least one address and directly indexed peer_addresses[0]. If the list was empty, this raised an IndexError, aborting the backup creation. The patch checks whether peer_addresses is non-empty and falls back to host=’’ and port=0 when it is empty. This is a robustness fix; no cryptographic, authentication, or network-layer security controls are changed.
Changed components
electrum/lnworker.pyLNWallet.create_channel_backup()ImportedChannelBackupStorage constructionInspect captured patch +3 / −3
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 1c8b1f3..71ac86d 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -3684,15 +3684,15 @@ class LNWallet(Logger):
# do not backup old-style channels
assert chan.is_static_remotekey_enabled()
peer_addresses = list(chan.get_peer_addresses())
- peer_addr = peer_addresses[0]
+ peer_addr = peer_addresses[0] if peer_addresses else None
return ImportedChannelBackupStorage(
node_id=chan.node_id,
privkey=self.node_keypair.privkey,
funding_txid=chan.funding_outpoint.txid,
funding_index=chan.funding_outpoint.output_index,
funding_address=chan.get_funding_address(),
- host=peer_addr.host,
- port=peer_addr.port,
+ host=peer_addr.host if peer_addr else '',
+ port=peer_addr.port if peer_addr else 0,
is_initiator=chan.constraints.is_initiator,
channel_seed=chan.config[LOCAL].channel_seed,
local_delay=chan.config[LOCAL].to_self_delay,
Why this scored 30/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.