LNWallet: don't allow rebalancing through frozen channels
What changed, and why it matters
This commit fixes a user-experience and reliability bug in Electrum's Lightning rebalancing feature. Previously, the wallet could attempt to rebalance funds through channels that were 'frozen' (disabled for sending or receiving). This didn't cause loss of funds, but led to confusing downstream failures during route finding. The patch now blocks such rebalances early and reports a clear error.
No urgent security action required. Treat as a normal bug-fix / UX improvement. Users relying on Lightning rebalancing should upgrade to avoid confusing failures.
Security signals we found
Logic bug / reliability fix
Defensive input validation
No direct funds-loss vulnerability evident
Evidence from the diff
In electrum/lnworker.py, the LNWallet rebalancing logic is updated to check whether chan1 is frozen for sending or chan2 is frozen for receiving. If so, num_sats_can_rebalance() returns 0 and rebalance_channels() raises an explicit exception. This prevents the GUI from initiating rebalances that are doomed to fail pathfinding later.
Changed components
electrum/lnworker.pyLNWallet.rebalance_channels()LNWallet.num_sats_can_rebalance()Inspect captured patch +5 / −1
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 8d1950d..ae42216 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -3514,8 +3514,10 @@ class LNWallet(Logger):
else:
return False
- def num_sats_can_rebalance(self, chan1, chan2):
+ def num_sats_can_rebalance(self, chan1: Channel, chan2: Channel) -> int:
# TODO: we should be able to spend 'max', with variable fee
+ if chan1.is_frozen_for_sending() or chan2.is_frozen_for_receiving():
+ return 0
n1 = chan1.available_to_spend(LOCAL)
n1 -= self.estimate_fee_reserve_for_total_amount(n1)
n2 = chan2.available_to_spend(REMOTE)
@@ -3566,6 +3568,8 @@ class LNWallet(Logger):
raise Exception('Rebalance requires two different channels')
if self.uses_trampoline() and chan1.node_id == chan2.node_id:
raise Exception('Rebalance requires channels from different trampolines')
+ if chan1.is_frozen_for_sending() or chan2.is_frozen_for_receiving(): # the gui should not allow this
+ raise Exception('Cannot rebalance through frozen channels')
payment_hash = self.create_payment_info(
amount_msat=amount_msat,
exp_delay=3600,
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.