From 16ef287e86326d901e0a6ccb7fc3995d6f029404 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 7 Oct 2023 13:26:07 +0200 Subject: [PATCH] swap server: try to batch funding transactions --- electrum/submarine_swaps.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 033cacbb2..0d865a23c 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -29,6 +29,8 @@ from .i18n import _ from .bitcoin import construct_script from .crypto import ripemd from .invoices import Invoice +from .network import TxBroadcastServerReturnedError + if TYPE_CHECKING: from .network import Network @@ -307,10 +309,12 @@ class SwapManager(Logger): self.lnwatcher.remove_callback(swap.lockup_address) swap.is_redeemed = True elif spent_height == TX_HEIGHT_LOCAL: - if funding_height.conf > 0 or self.wallet.config.LIGHTNING_ALLOW_INSTANT_SWAPS: + if swap.is_reverse and (funding_height.conf > 0 or self.wallet.config.LIGHTNING_ALLOW_INSTANT_SWAPS): tx = self.lnwatcher.adb.get_transaction(txin.spent_txid) - self.logger.info(f'broadcasting tx {txin.spent_txid}') - await self.network.broadcast_transaction(tx) + try: + await self.network.broadcast_transaction(tx) + except TxBroadcastServerReturnedError: + self.logger.info(f'error broadcasting claim tx {txin.spent_txid}') elif funding_height.height == TX_HEIGHT_LOCAL: # the funding tx was double spent. # this will remove both funding and child (spending tx) from adb @@ -401,8 +405,14 @@ class SwapManager(Logger): swap = self.swaps[key] if swap.funding_txid is None: password = self.wallet.get_unlocked_password() - tx = self.create_funding_tx(swap, None, password) - await self.broadcast_funding_tx(swap, tx) + for batch_rbf in [True, False]: + self.wallet.config.WALLET_BATCH_RBF = batch_rbf + tx = self.create_funding_tx(swap, None, password) + try: + await self.broadcast_funding_tx(swap, tx) + except TxBroadcastServerReturnedError: + continue + break def create_normal_swap(self, *, lightning_amount_sat=None, payment_hash: bytes=None, their_pubkey=None): """ server method """