From e93becf33a5f16e59f496add8f0ae325dd971240 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 27 Mar 2021 14:29:10 +0100 Subject: [PATCH] wallet.add_transaction: prevent channel backup from being added twice --- electrum/address_synchronizer.py | 7 ++++++- electrum/wallet.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index bc2c0067c..d6ecd9540 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -251,7 +251,12 @@ class AddressSynchronizer(Logger): return conflicting_txns def add_transaction(self, tx: Transaction, *, allow_unrelated=False) -> bool: - """Returns whether the tx was successfully added to the wallet history.""" + """ + Returns whether the tx was successfully added to the wallet history. + Note that a transaction may need to be added several times, if our + list of addresses has increased. This will return True even if the + transaction was already in self.db. + """ assert tx, tx # note: tx.is_complete() is not necessarily True; tx might be partial # but it *needs* to have a txid: diff --git a/electrum/wallet.py b/electrum/wallet.py index e4cc8d966..75fd0a61c 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -884,8 +884,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC): return bool(labels) def add_transaction(self, tx, *, allow_unrelated=False): + is_known = bool(self.db.get_transaction(tx.txid())) tx_was_added = super().add_transaction(tx, allow_unrelated=allow_unrelated) - if tx_was_added: + if tx_was_added and not is_known: self._maybe_set_tx_label_based_on_invoices(tx) if self.lnworker: self.lnworker.maybe_add_backup_from_tx(tx)