Skip to content

Commit 11f0820

Browse files
authored
fix: do not show duplicated incoming funds from channel closures (#755)
Fixes #752 Fixes #612 There is overlap in balance from pending closed channels and total onchain balance. They will show as incoming in the total onchain balance once the channel becomes sweepable. Therefore, this PR no longer manually includes balances from pending closed channels in the "incoming" amount on the savings balance card. This PR also adds extra balance info that can be retrieved from debug tools -> get balances which is useful for debugging channels that are stuck (e.g. unconfirmed) or to know if the funds on a channel are still locked, and which counterparty the channel is with.
2 parents 70ac096 + 7456a88 commit 11f0820

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

frontend/src/screens/channels/Channels.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,11 @@ export default function Channels() {
318318
{new Intl.NumberFormat().format(balances.onchain.spendable)}{" "}
319319
sats
320320
{balances &&
321-
(balances.onchain.spendable !== balances.onchain.total ||
322-
balances.onchain.pendingBalancesFromChannelClosures >
323-
0) && (
321+
balances.onchain.spendable !== balances.onchain.total && (
324322
<p className="text-xs text-muted-foreground animate-pulse">
325323
+
326324
{new Intl.NumberFormat().format(
327-
balances.onchain.total -
328-
balances.onchain.spendable +
329-
balances.onchain.pendingBalancesFromChannelClosures
325+
balances.onchain.total - balances.onchain.spendable
330326
)}{" "}
331327
sats incoming
332328
</p>
@@ -435,7 +431,9 @@ export default function Channels() {
435431
balances.onchain.pendingBalancesFromChannelClosures
436432
)}{" "}
437433
sats pending from one or more closed channels. Once spendable again
438-
these will become available in your savings balance.{" "}
434+
these will become available in your savings balance. Funds from
435+
channels that were force closed may take up to 2 weeks to become
436+
available.{" "}
439437
<ExternalLink
440438
to="https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/faq-alby-hub/why-was-my-lightning-channel-closed-and-what-to-do-next"
441439
className="underline"

lnclient/ldk/ldk.go

+16
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,13 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
10211021
"balances": balances,
10221022
}).Debug("Listed Balances")
10231023

1024+
type internalLightningBalance struct {
1025+
BalanceType string
1026+
Balance ldk_node.LightningBalance
1027+
}
1028+
1029+
internalLightningBalances := []internalLightningBalance{}
1030+
10241031
pendingBalancesFromChannelClosures := uint64(0)
10251032
// increase pending balance from any lightning balances for channels that are pending closure
10261033
// (they do not exist in our list of open channels)
@@ -1033,6 +1040,11 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
10331040
}
10341041
}
10351042

1043+
// include the balance type as it's useful to know the state of the channel
1044+
internalLightningBalances = append(internalLightningBalances, internalLightningBalance{
1045+
BalanceType: fmt.Sprintf("%T", balance),
1046+
Balance: balance,
1047+
})
10361048
switch balanceType := (balance).(type) {
10371049
case ldk_node.LightningBalanceClaimableOnChannelClose:
10381050
increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
@@ -1066,6 +1078,10 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
10661078
Total: int64(balances.TotalOnchainBalanceSats - balances.TotalAnchorChannelsReserveSats),
10671079
Reserved: int64(balances.TotalAnchorChannelsReserveSats),
10681080
PendingBalancesFromChannelClosures: pendingBalancesFromChannelClosures,
1081+
InternalBalances: map[string]interface{}{
1082+
"internal_lightning_balances": internalLightningBalances,
1083+
"all_balances": balances,
1084+
},
10691085
}, nil
10701086
}
10711087

lnclient/lnd/lnd.go

+4
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ func (svc *LNDService) GetOnchainBalance(ctx context.Context) (*lnclient.Onchain
760760
Total: int64(balances.TotalBalance),
761761
Reserved: int64(balances.ReservedBalanceAnchorChan),
762762
PendingBalancesFromChannelClosures: pendingBalancesFromChannelClosures,
763+
InternalBalances: map[string]interface{}{
764+
"balances": balances,
765+
"pending_channels": pendingChannels,
766+
},
763767
}, nil
764768
}
765769

lnclient/models.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ type CloseChannelResponse struct {
134134
}
135135

136136
type OnchainBalanceResponse struct {
137-
Spendable int64 `json:"spendable"`
138-
Total int64 `json:"total"`
139-
Reserved int64 `json:"reserved"`
140-
PendingBalancesFromChannelClosures uint64 `json:"pendingBalancesFromChannelClosures"`
137+
Spendable int64 `json:"spendable"`
138+
Total int64 `json:"total"`
139+
Reserved int64 `json:"reserved"`
140+
PendingBalancesFromChannelClosures uint64 `json:"pendingBalancesFromChannelClosures"`
141+
InternalBalances interface{} `json:"internalBalances"`
141142
}
142143

143144
type PeerDetails struct {

0 commit comments

Comments
 (0)