From de2007e90ce4d4f2f4f8f37125183acea40beac0 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 17 Jan 2024 18:58:18 +0000 Subject: [PATCH] adb: simplify get_conflicting_transactions --- electrum/address_synchronizer.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 87dc7bb49..ed1a34df0 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -221,7 +221,7 @@ class AddressSynchronizer(Logger, EventListener): self.synchronizer.add(address) self.up_to_date_changed() - def get_conflicting_transactions(self, tx_hash, tx: Transaction, include_self=False): + def get_conflicting_transactions(self, tx: Transaction, *, include_self: bool = False) -> Set[str]: """Returns a set of transaction hashes from the wallet history that are directly conflicting with tx, i.e. they have common outpoints being spent with tx. @@ -243,12 +243,13 @@ class AddressSynchronizer(Logger, EventListener): # annoying assert that has revealed several bugs over time: assert self.db.get_transaction(spending_tx_hash), "spending tx not in wallet db" conflicting_txns |= {spending_tx_hash} - if tx_hash in conflicting_txns: - # this tx is already in history, so it conflicts with itself - if len(conflicting_txns) > 1: - raise Exception('Found conflicting transactions already in wallet history.') - if not include_self: - conflicting_txns -= {tx_hash} + if tx_hash := tx.txid(): + if tx_hash in conflicting_txns: + # this tx is already in history, so it conflicts with itself + if len(conflicting_txns) > 1: + raise Exception('Found conflicting transactions already in wallet history.') + if not include_self: + conflicting_txns -= {tx_hash} return conflicting_txns def get_transaction(self, txid: str) -> Optional[Transaction]: @@ -298,7 +299,7 @@ class AddressSynchronizer(Logger, EventListener): # When this method exits, there must NOT be any conflict, so # either keep this txn and remove all conflicting (along with dependencies) # or drop this txn - conflicting_txns = self.get_conflicting_transactions(tx_hash, tx) + conflicting_txns = self.get_conflicting_transactions(tx) if conflicting_txns: existing_mempool_txn = any( self.get_tx_height(tx_hash2).height in (TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT)