From db271d9b7df68ec07d95f649979e3710799bbf27 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 8 May 2025 14:56:52 +0200 Subject: [PATCH] Fix get_pending_swaps: use both funding and spending tx heights Also, do not show closing warnings if we are offline. --- electrum/gui/qt/main_window.py | 4 +++- electrum/submarine_swaps.py | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 576837e2e..348330836 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2699,7 +2699,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): warning = ''.join([ _("Are you sure you want to close Electrum?"), '\n\n', - _("An ongoing operation prevents Electrum from closing:"), + _("An ongoing operation requires you to stay online."), '\n', warning ]) @@ -2734,6 +2734,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): """Callback that will return a warning string if there are unconfirmed swap funding txs.""" if not (self.wallet.has_lightning() and self.wallet.lnworker.swap_manager): return None + if not self.network: + return None if ongoing_swaps := self.wallet.lnworker.swap_manager.get_pending_swaps(): return "".join(( f"{str(len(ongoing_swaps))} ", diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 0800ffa8d..314bb0a0c 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -1283,11 +1283,11 @@ class SwapManager(Logger): """Returns a list of swaps with unconfirmed funding tx (which require us to stay online).""" pending_swaps: List[SwapData] = [] for swap in self.swaps.values(): - if swap.funding_txid and not swap.is_redeemed: - # swap is funded but not marked redeemed by _claim_swap - if self.lnworker.wallet.adb.get_tx_height(swap.funding_txid).height < 1: - # funding TX is not yet confirmed, wallet should not be closed - pending_swaps.append(swap) + # note: adb.get_tx_height returns TX_HEIGHT_LOCAL if the txid is unknown + funding_height = self.lnworker.wallet.adb.get_tx_height(swap.funding_txid).height + spending_height = self.lnworker.wallet.adb.get_tx_height(swap.spending_txid).height + if funding_height > TX_HEIGHT_LOCAL and spending_height <= TX_HEIGHT_LOCAL: + pending_swaps.append(swap) return pending_swaps class SwapServerTransport(Logger):