diff --git a/electrum/txbatcher.py b/electrum/txbatcher.py index ee1727e04..48279b40e 100644 --- a/electrum/txbatcher.py +++ b/electrum/txbatcher.py @@ -329,7 +329,7 @@ class TxBatch(Logger): for prevout, sweep_info in list(self.batch_inputs.items()): assert prevout == sweep_info.txin.prevout prev_txid, index = prevout.to_str().split(':') - if not self.wallet.adb.db.get_transaction(prev_txid): + if not (prev_tx := self.wallet.adb.db.get_transaction(prev_txid)): continue if sweep_info.is_anchor(): prev_tx_mined_status = self.wallet.adb.get_tx_height(prev_txid) @@ -337,6 +337,21 @@ class TxBatch(Logger): self.logger.info(f"anchor not needed {prevout}") self.batch_inputs.pop(prevout) # note: if the input is already in a batch tx, this will trigger assert error continue + prev_tx_current_fee = self.wallet.adb.get_tx_fee(prev_txid) + try: + prev_tx_target_fee = self.fee_policy.estimate_fee( + prev_tx.estimated_size(), + network=self.wallet.network, + ) + except NoDynamicFeeEstimates: + prev_tx_target_fee = None + fees_available = prev_tx_current_fee and prev_tx_target_fee + if fees_available and prev_tx_current_fee > prev_tx_target_fee: + self.logger.info( + f"not using anchor now, fee sufficient: " + f"{prev_tx_current_fee=} > {prev_tx_target_fee=}", only_once=True, + ) + continue if spender_txid := self.wallet.adb.db.get_spent_outpoint(prev_txid, int(index)): tx_mined_status = self.wallet.adb.get_tx_height(spender_txid) if tx_mined_status.height() not in [TX_HEIGHT_LOCAL, TX_HEIGHT_FUTURE]: