From 655eca68e3034b641c7c707f39809459c219986b Mon Sep 17 00:00:00 2001 From: mojoX911 Date: Fri, 17 Jan 2025 20:12:44 +0530 Subject: [PATCH] remove deadlock --- src/maker/api.rs | 83 +++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/src/maker/api.rs b/src/maker/api.rs index e952fef8..675b145f 100644 --- a/src/maker/api.rs +++ b/src/maker/api.rs @@ -752,18 +752,18 @@ pub(crate) fn recover_from_swap( maker.config.network_port ); } 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() - ); - } + 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 @@ -779,38 +779,47 @@ pub(crate) fn recover_from_swap( //broadcast all the outgoing contracts for ((og_rs, tx), _) in outgoings.iter() { - if maker + let check_tx_result = maker .wallet .read()? .rpc - .get_raw_transaction_info(&tx.compute_txid(), None) - .is_ok() - { - log::info!( - "[{}] Outgoing Contract already broadcasted", - maker.config.network_port - ); - } else if let Err(e) = maker.wallet.read()?.send_tx(tx) { + .get_raw_transaction_info(&tx.compute_txid(), None); + + match check_tx_result { + Ok(_) => { log::info!( - "Can't send ougoing contract: {} | {:?}", - tx.compute_txid(), - e + "[{}] Outgoing Contract already broadcasted", + maker.config.network_port ); - 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)?; + } + Err(_) => { + let send_tx_result = maker.wallet.read()?.send_tx(tx); + match send_tx_result { + Ok(_) => { + log::info!( + "[{}] Broadcasted Outgoing Contract : {}", + maker.config.network_port, + tx.compute_txid() + ); + } + Err(e) => { + 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. + maker + .get_wallet() + .write()? + .remove_outgoing_swapcoin(og_rs)?; + log::info!("Removed outgoing swapcoin: {}", tx.compute_txid()); + } + } } - } else { - log::info!( - "[{}] Broadcasted Outgoing Contract : {}", - maker.config.network_port, - tx.compute_txid() - ); } + } } // Save the wallet here before going into the expensive loop.