From b1020c1a5cf2b386b9948efad9b5868232323945 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Tue, 10 Nov 2020 12:37:31 -0500 Subject: [PATCH] fix(lnd): don't calculate negative capacities This fixes a bug in the logic for calculating the inbound & outbound amount/capacity totals. We subtract the channel reserve amounts from the balances when determining how large a payment the channel could support, however we should not end up with a negative number. --- lib/lndclient/LndClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lndclient/LndClient.ts b/lib/lndclient/LndClient.ts index 0e634a0aa..8ea03e7b4 100644 --- a/lib/lndclient/LndClient.ts +++ b/lib/lndclient/LndClient.ts @@ -740,13 +740,13 @@ class LndClient extends SwapClient { channels.toObject().channelsList.forEach((channel) => { if (channel.active) { balance += channel.localBalance; - const outbound = channel.localBalance - channel.localChanReserveSat; + const outbound = Math.max(0, channel.localBalance - channel.localChanReserveSat); totalOutboundAmount += outbound; if (maxOutbound < outbound) { maxOutbound = outbound; } - const inbound = channel.remoteBalance - channel.remoteChanReserveSat; + const inbound = Math.max(0, channel.remoteBalance - channel.remoteChanReserveSat); totalInboundAmount += inbound; if (maxInbound < inbound) { maxInbound = inbound;