From 3874f53aec53fe88ec3a3b464946b6f8eb67795b Mon Sep 17 00:00:00 2001 From: mojoX911 Date: Fri, 17 Jan 2025 19:56:55 +0530 Subject: [PATCH] don't hard error on send failure --- src/maker/api.rs | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/maker/api.rs b/src/maker/api.rs index 0b189cb3..e952fef8 100644 --- a/src/maker/api.rs +++ b/src/maker/api.rs @@ -751,15 +751,19 @@ pub(crate) fn recover_from_swap( "[{}] Incoming Contract Already Broadcasted", maker.config.network_port ); - } else { - maker.wallet.read()?.send_tx(&tx)?; - - log::info!( - "[{}] Broadcasted Incoming Contract : {}", - maker.config.network_port, - tx.compute_txid() - ); - } + } else if let Err(e) = maker.wallet.read()?.send_tx(&tx) { + log::info!( + "Can't send incoming contract: {} | {:?}", + tx.compute_txid(), + e + ); + } else { + log::info!( + "[{}] Broadcasted Incoming Contract : {}", + maker.config.network_port, + tx.compute_txid() + ); + } let removed_incoming = maker .wallet @@ -774,7 +778,7 @@ pub(crate) fn recover_from_swap( } //broadcast all the outgoing contracts - for ((_, tx), _) in outgoings.iter() { + for ((og_rs, tx), _) in outgoings.iter() { if maker .wallet .read()? @@ -786,14 +790,27 @@ pub(crate) fn recover_from_swap( "[{}] Outgoing Contract already broadcasted", maker.config.network_port ); - } else { - let txid = maker.wallet.read()?.send_tx(tx)?; - log::info!( - "[{}] Broadcasted Outgoing Contract : {}", - maker.config.network_port, - txid - ); - } + } else if let Err(e) = maker.wallet.read()?.send_tx(tx) { + log::info!( + "Can't send ougoing contract: {} | {:?}", + tx.compute_txid(), + e + ); + if format!("{:?}", e).contains("bad-txns-inputs-missingorspent") { + // This means the funding utxo doesn't exist anymore. Just remove this coin. + log::info!("Removing outgoing swapcoin: {}", tx.compute_txid()); + maker + .get_wallet() + .write()? + .remove_outgoing_swapcoin(og_rs)?; + } + } else { + log::info!( + "[{}] Broadcasted Outgoing Contract : {}", + maker.config.network_port, + tx.compute_txid() + ); + } } // Save the wallet here before going into the expensive loop.