From d9f1a21219ed466cee1e686576b90c59f7aff700 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 9 Mar 2023 14:57:43 +0100 Subject: [PATCH] reverse_swap: return as soon as we detect the funding transaction --- electrum/submarine_swaps.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 7b82b739a..0d86207da 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -444,12 +444,18 @@ class SwapManager(Logger): self._add_or_reindex_swap(swap) # add callback to lnwatcher self.add_lnwatcher_callback(swap) - # initiate payment. + # initiate fee payment. if fee_invoice: self.prepayments[prepay_hash] = preimage_hash asyncio.ensure_future(self.lnworker.pay_invoice(fee_invoice, attempts=10)) - # initiate payment. - success, log = await self.lnworker.pay_invoice(invoice, attempts=10, channels=channels) + # we return if we detect funding + async def wait_for_funding(swap): + while swap.spending_txid is None: + await asyncio.sleep(1) + # initiate main payment + tasks = [self.lnworker.pay_invoice(invoice, attempts=10, channels=channels), wait_for_funding(swap)] + await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED) + success = swap.spending_txid is not None return success def _add_or_reindex_swap(self, swap: SwapData) -> None: