aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-05-18 00:00:10 -0700
committerAdam Soltys <[email protected]>2026-05-18 00:00:10 -0700
commitcddafe5ef8fc90559d5163d4ecaa0da37c7947f7 (patch)
treea6f61df28a0e1ea73b9c1bc1956b0153ad47040e /lib
parentb8e194affb096af2468624c4863803c7fa406b6e (diff)
downloadcoinos-server-cddafe5ef8fc90559d5163d4ecaa0da37c7947f7.tar.gz
coinos-server-cddafe5ef8fc90559d5163d4ecaa0da37c7947f7.zip
freezeCheck: only count spendable channels in lnbalance
Previous calc summed our_amount_msat across every channel regardless of state, including ONCHAIN (channels that have been closed and are waiting for the on-chain sweep). Those funds are not actually usable for lightning sends, but were inflating lnbalance — and therefore inflating ${type}:limit — by the locked-up amount. With several closed channels pending sweep, the effective threshold floor was tens of megasats lower than the configured lightning:threshold suggested. Filter to CHANNELD_NORMAL (and CHANNELD_AWAITING_SPLICE so an in-flight splice doesn't briefly pin the limit to zero). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 22bbafb4..380b5e7b 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -975,8 +975,16 @@ const freezeCheck = async () => {
let lnbalance: number | undefined;
try {
const funds = await ln.listfunds();
+ // Only spendable channels — ONCHAIN/CLOSING funds are locked in pending
+ // sweeps and aren't usable for lightning sends, so counting them inflates
+ // the limit. CHANNELD_AWAITING_SPLICE is included so an in-flight splice
+ // doesn't briefly drop the limit to zero.
lnbalance = Math.round(
- funds.channels.reduce((a, b) => a + b.our_amount_msat, 0) / 1000,
+ funds.channels
+ .filter((c) =>
+ c.state === "CHANNELD_NORMAL" || c.state === "CHANNELD_AWAITING_SPLICE",
+ )
+ .reduce((a, b) => a + b.our_amount_msat, 0) / 1000,
);
} catch (e: any) {
warnThrottled("freezeCheck lightning", e.message);