Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not show duplicated incoming funds from channel closures #755

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rolznz marked this conversation as resolved.
Show resolved Hide resolved
)}{" "}
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
Loading