AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 47 Bitcoin

Let callers handle errors on `get_available_balances_for_scope`

Public commit record

What the developer wrote

Authored by Leo Nash

85/100 · Strong
Let callers handle errors on `get_available_balances_for_scope`

`get_available_balances_for_scope` only errors if some party in the
channel cannot afford the HTLCs outbound from said party, and the
anchors and transaction fee if they are the funder. We do not account
for the channel reserve here, so this error should be exceedingly rare,
but could nonetheless happen due to concurrent updates on the channel's
state. The upcoming zero-reserve channel type could also make this case
more reachable.

`send_htlc` maps such an error to its own error type since it proposes
an update to the channel's state. The other callers only read the
channel's state, so it would not be a good fit to have them return an
error too. Hence, we choose to let these callers panic in debug mode,
and return saturated values in release mode.

Note that we now handle the if-we-removed-it-already-but-haven't
-fully-resolved-they-can-still-send-an-inbound-HTLC case, as
`LocalRemoved` HTLCs are considered resolved when calculating
`AvailableBalances`. We update the documentation accordingly.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit changes how a Lightning channel balance calculation reports rare error conditions. Previously the function could silently ignore an internal failure and return potentially incorrect balance numbers. Now it returns an explicit error, and callers that only read channel state either crash in debug builds or return conservative 'saturated' values in release builds. The main user-facing effect is more correct balance reporting and safer handling of an edge case where a party cannot actually afford its pending payments plus fees. It is a defensive fix, not a clear-cut exploit patch.

Recommended action

Review whether the saturated fallback values in release builds are safe for all downstream consumers, and consider adding tests for the new `ChannelBalanceOverdrawn` error path and the `LocalRemoved` HTLC balance case.

Security signals we found

01

Defensive error propagation added to balance calculation

02

Read-only callers panic in debug mode and saturate in release mode

03

send_htlc now rejects overdrawn channels explicitly

04

Documentation updated to describe error condition and LocalRemoved HTLC handling

Risk score

Why this scored 47/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 10/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.