lnrouter: LiquidityHint: fix logic bug in calculation
What changed, and why it matters
This is a one-line bug fix in Electrum's Lightning Network routing code. A method that tracks how many pending payments (HTLCs) are flowing in the backward direction was accidentally using the forward-direction counter. This could cause the backward counter to become inaccurate, potentially leading to poor routing decisions, stuck payments, or denial-of-service-like effects for Lightning payments. It is a logic bug rather than a cryptographic flaw, and no direct theft of funds is evident from the diff alone.
Apply the patch. Review related LiquidityHint state transitions for similar copy-paste errors, especially around forward/backward symmetry. Consider adding unit tests that exercise both directions independently.
Security signals we found
Logic bug in state tracking for Lightning routing
Incorrect variable reuse (forward counter in backward branch)
Private security report from external reporter
Potential denial-of-service / payment reliability impact
Evidence from the diff
In electrum/lnrouter.py, the LiquidityHint.htlc_failed method decrements an inflight HTLC counter when a payment attempt fails. The backward-direction branch incorrectly subtracted from self._inflight_htlcs_forward instead of self._inflight_htlcs_backward. The patch corrects this to decrement the proper backward counter. This kind of counter mismatch can desynchronize liquidity hints, causing the router to misjudge channel capacity in one direction and possibly retry routes inappropriately or fail to clean up state.
Changed components
electrum/lnrouter.pyLiquidityHint classLightning payment routing / HTLC failure handlingInspect captured patch +1 / −1
diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py
index 73d6971..4322dc6 100644
--- a/electrum/lnrouter.py
+++ b/electrum/lnrouter.py
@@ -281,7 +281,7 @@ class LiquidityHint:
if is_forward_direction:
self._inflight_htlcs_forward = max(0, self._inflight_htlcs_forward - 1)
else:
- self._inflight_htlcs_backward = max(0, self._inflight_htlcs_forward - 1)
+ self._inflight_htlcs_backward = max(0, self._inflight_htlcs_backward - 1)
def __repr__(self):
return f"forward: can send: {self._can_send_forward} msat, cannot send: {self._cannot_send_forward} msat, htlcs: {self._inflight_htlcs_forward}\n" \
Why this scored 48/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.