From a084ccc74c87e8a46fa80f62e019dcab116998c2 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 21 Jan 2025 16:52:12 +0100 Subject: [PATCH] lnworker: fix how lightning balance is affected when a channel is force-closed. Assert final balance in lnworker.get_history(). If we offered some HTLCs, we do not know yet whether they will be redeemed by us or by the remote. --- electrum/lnworker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 43c9a5d7a..1da7ee7f4 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1132,7 +1132,7 @@ class LNWallet(LNWorker): 'txid': closing_txid, 'label': self.wallet.get_label_for_txid(closing_txid), 'type': 'channel_closure', - 'amount_msat': -chan.balance_minus_outgoing_htlcs(LOCAL), + 'amount_msat': -chan.balance(LOCAL), 'direction': PaymentDirection.SENT, 'timestamp': tx_height.timestamp, 'monotonic_timestamp': tx_height.timestamp or TX_TIMESTAMP_INF, @@ -1162,6 +1162,10 @@ class LNWallet(LNWorker): for item in out: balance_msat += item['amount_msat'] item['balance_msat'] = balance_msat + + lb = sum(chan.balance(LOCAL) if not chan.is_closed() else 0 + for chan in self.channels.values()) + assert balance_msat == lb return out def channel_peers(self) -> List[bytes]: