Skip to content

Commit

Permalink
fix: do not show duplicated incoming funds from channel closures
Browse files Browse the repository at this point in the history
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.

This PR also adds extra balance info that can be retrieved from debug tools -> get balances
  • Loading branch information
rolznz committed Oct 24, 2024
1 parent 70ac096 commit 7456a88
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
12 changes: 5 additions & 7 deletions frontend/src/screens/channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,11 @@ export default function Channels() {
{new Intl.NumberFormat().format(balances.onchain.spendable)}{" "}
sats
{balances &&
(balances.onchain.spendable !== balances.onchain.total ||
balances.onchain.pendingBalancesFromChannelClosures >
0) && (
balances.onchain.spendable !== balances.onchain.total && (
<p className="text-xs text-muted-foreground animate-pulse">
+
{new Intl.NumberFormat().format(
balances.onchain.total -
balances.onchain.spendable +
balances.onchain.pendingBalancesFromChannelClosures
balances.onchain.total - balances.onchain.spendable
)}{" "}
sats incoming
</p>
Expand Down Expand Up @@ -435,7 +431,9 @@ export default function Channels() {
balances.onchain.pendingBalancesFromChannelClosures
)}{" "}
sats pending from one or more closed channels. Once spendable again
these will become available in your savings balance.{" "}
these will become available in your savings balance. Funds from
channels that were force closed may take up to 2 weeks to become
available.{" "}
<ExternalLink
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"
className="underline"
Expand Down
16 changes: 16 additions & 0 deletions lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,13 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
"balances": balances,
}).Debug("Listed Balances")

type internalLightningBalance struct {
BalanceType string
Balance ldk_node.LightningBalance
}

internalLightningBalances := []internalLightningBalance{}

pendingBalancesFromChannelClosures := uint64(0)
// increase pending balance from any lightning balances for channels that are pending closure
// (they do not exist in our list of open channels)
Expand All @@ -1033,6 +1040,11 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
}
}

// include the balance type as it's useful to know the state of the channel
internalLightningBalances = append(internalLightningBalances, internalLightningBalance{
BalanceType: fmt.Sprintf("%T", balance),
Balance: balance,
})
switch balanceType := (balance).(type) {
case ldk_node.LightningBalanceClaimableOnChannelClose:
increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
Expand Down Expand Up @@ -1066,6 +1078,10 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
Total: int64(balances.TotalOnchainBalanceSats - balances.TotalAnchorChannelsReserveSats),
Reserved: int64(balances.TotalAnchorChannelsReserveSats),
PendingBalancesFromChannelClosures: pendingBalancesFromChannelClosures,
InternalBalances: map[string]interface{}{
"internal_lightning_balances": internalLightningBalances,
"all_balances": balances,
},
}, nil
}

Expand Down
4 changes: 4 additions & 0 deletions lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ func (svc *LNDService) GetOnchainBalance(ctx context.Context) (*lnclient.Onchain
Total: int64(balances.TotalBalance),
Reserved: int64(balances.ReservedBalanceAnchorChan),
PendingBalancesFromChannelClosures: pendingBalancesFromChannelClosures,
InternalBalances: map[string]interface{}{
"balances": balances,
"pending_channels": pendingChannels,
},
}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions lnclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ type CloseChannelResponse struct {
}

type OnchainBalanceResponse struct {
Spendable int64 `json:"spendable"`
Total int64 `json:"total"`
Reserved int64 `json:"reserved"`
PendingBalancesFromChannelClosures uint64 `json:"pendingBalancesFromChannelClosures"`
Spendable int64 `json:"spendable"`
Total int64 `json:"total"`
Reserved int64 `json:"reserved"`
PendingBalancesFromChannelClosures uint64 `json:"pendingBalancesFromChannelClosures"`
InternalBalances interface{} `json:"internalBalances"`
}

type PeerDetails struct {
Expand Down

0 comments on commit 7456a88

Please sign in to comment.