From 4a0cb993b3a47e502c3dbc854fd5468b00a14326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Granh=C3=A3o?= <32176319+danielgranhao@users.noreply.github.com> Date: Tue, 29 Apr 2025 20:05:16 +0100 Subject: [PATCH] Broadcast receive swap server lockup txs (#904) (cherry picked from commit 68ed656aaa78cf49d440368d26209d371f0235b8) --- lib/core/src/receive_swap.rs | 39 ++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/core/src/receive_swap.rs b/lib/core/src/receive_swap.rs index ec7654d..903fdc7 100644 --- a/lib/core/src/receive_swap.rs +++ b/lib/core/src/receive_swap.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::str::FromStr; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Context, Result}; use boltz_client::swaps::boltz::RevSwapStates; use boltz_client::{boltz, Serialize, ToHex}; use log::{debug, error, info, warn}; @@ -120,19 +120,28 @@ impl ReceiveSwapHandler { let tx_hex = transaction.hex.ok_or(anyhow!( "Missing lockup transaction hex in swap status update" ))?; - let lockup_tx = match self - .verify_lockup_tx(&receive_swap, &transaction.id, &tx_hex, false) - .await - { - Ok(lockup_tx) => lockup_tx, - Err(e) => { + let lockup_tx = utils::deserialize_tx_hex(&tx_hex) + .context("Failed to deserialize tx hex in swap status update")?; + debug!( + "Broadcasting lockup tx received in swap status update for receive swap {id}" + ); + if let Err(e) = self.liquid_chain_service.broadcast(&lockup_tx).await { + warn!( + "Failed to broadcast lockup tx in swap status update: {e:?} - maybe the \ + tx depends on inputs that haven't been seen yet, falling back to waiting for \ + it to appear in the mempool" + ); + if let Err(e) = self + .verify_lockup_tx_status(&receive_swap, &transaction.id, &tx_hex, false) + .await + { return Err(anyhow!( - "Swapper mempool reported lockup could not be verified. txid: {}, err: {}", - transaction.id, - e - )); + "Swapper mempool reported lockup could not be verified. txid: {}, err: {}", + transaction.id, + e + )); } - }; + } if let Err(e) = self .verify_lockup_tx_amount(&receive_swap, &lockup_tx) @@ -203,7 +212,7 @@ impl ReceiveSwapHandler { "Missing lockup transaction hex in swap status update" ))?; let lockup_tx = match self - .verify_lockup_tx(&receive_swap, &transaction.id, &tx_hex, true) + .verify_lockup_tx_status(&receive_swap, &transaction.id, &tx_hex, true) .await { Ok(lockup_tx) => lockup_tx, @@ -463,7 +472,7 @@ impl ReceiveSwapHandler { .serialize() .to_lower_hex_string(); let lockup_tx = self - .verify_lockup_tx(receive_swap, &tx_id, &tx_hex, true) + .verify_lockup_tx_status(receive_swap, &tx_id, &tx_hex, true) .await?; if let Err(e) = self.verify_lockup_tx_amount(receive_swap, &lockup_tx).await { self.update_swap_info(swap_id, Failed, None, None, None, None)?; @@ -518,7 +527,7 @@ impl ReceiveSwapHandler { } } - async fn verify_lockup_tx( + async fn verify_lockup_tx_status( &self, receive_swap: &ReceiveSwap, tx_id: &str,