Skip to content

Commit

Permalink
Revert "provide number of confirmations in wait_for_confirmations"
Browse files Browse the repository at this point in the history
This reverts commit 2c119be
  • Loading branch information
laruh committed Sep 26, 2024
1 parent 6fa527a commit 0073fe8
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 54 deletions.
5 changes: 2 additions & 3 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ impl MarketCoinOps for EthCoin {
}
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
macro_rules! update_status_with_error {
($status: ident, $error: ident) => {
match $error.get_inner() {
Expand Down Expand Up @@ -2328,8 +2328,7 @@ impl MarketCoinOps for EthCoin {
Ok(conf) => {
if conf == confirmed_at {
status.append(" Confirmed.");
// Let's avoid risking additional errors by calling `current_block` and instead return required_confirms
break Ok(required_confirms.as_u64());
break Ok(());
}
},
Err(e) => {
Expand Down
6 changes: 3 additions & 3 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ impl MarketCoinOps for LightningCoin {

// Todo: Add waiting for confirmations logic for the case of if the channel is closed and the htlc can be claimed on-chain
// Todo: The above is postponed and might not be needed after this issue is resolved https://github.com/lightningdevkit/rust-lightning/issues/2017
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
let payment_hash = try_f!(payment_hash_from_slice(&input.payment_tx).map_err(|e| e.to_string()));
let payment_hex = hex::encode(payment_hash.0);

Expand All @@ -1139,7 +1139,7 @@ impl MarketCoinOps for LightningCoin {
Ok(Some(payment)) => {
match payment.payment_type {
PaymentType::OutboundPayment { .. } => match payment.status {
HTLCStatus::Pending | HTLCStatus::Succeeded => return Ok(1u64),
HTLCStatus::Pending | HTLCStatus::Succeeded => return Ok(()),
HTLCStatus::Claimable => {
return ERR!(
"Payment {} has an invalid status of {} in the db",
Expand All @@ -1153,7 +1153,7 @@ impl MarketCoinOps for LightningCoin {
HTLCStatus::Failed => return ERR!("Lightning swap payment {} failed", payment_hex),
},
PaymentType::InboundPayment => match payment.status {
HTLCStatus::Claimable | HTLCStatus::Succeeded => return Ok(1u64),
HTLCStatus::Claimable | HTLCStatus::Succeeded => return Ok(()),
HTLCStatus::Pending => info!("Payment {} not received yet!", payment_hex),
HTLCStatus::Failed => return ERR!("Lightning swap payment {} failed", payment_hex),
},
Expand Down
3 changes: 1 addition & 2 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,7 @@ pub trait MarketCoinOps {
/// Signs raw utxo transaction in hexadecimal format as input and returns signed transaction in hexadecimal format
async fn sign_raw_tx(&self, args: &SignRawTransactionRequest) -> RawTransactionResult;

/// Wait for confirmations and return the number of confirmed blocks
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send>;
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send>;

fn wait_for_htlc_tx_spend(&self, args: WaitForHTLCTxSpendArgs<'_>) -> TransactionFut;

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ impl MarketCoinOps for Qrc20Coin {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
let tx: UtxoTx = try_fus!(deserialize(input.payment_tx.as_slice()).map_err(|e| ERRL!("{:?}", e)));
let selfi = self.clone();
let fut = async move {
Expand Down
6 changes: 3 additions & 3 deletions mm2src/coins/qrc20/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ impl Qrc20Coin {
requires_nota: bool,
wait_until: u64,
check_every: u64,
) -> Result<u64, String> {
) -> Result<(), String> {
let tx_hash = H256Json::from(qtum_tx.hash().reversed());
let confirmations = try_s!(
try_s!(
self.utxo
.rpc_client
.wait_for_confirmations(
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Qrc20Coin {
try_s!(check_if_contract_call_completed(&receipt));
}

Ok(confirmations)
Ok(())
}

/// Generate `ContractCallOutput` outputs required to send a swap payment.
Expand Down
5 changes: 1 addition & 4 deletions mm2src/coins/siacoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,7 @@ impl MarketCoinOps for SiaCoin {
#[inline(always)]
async fn sign_raw_tx(&self, _args: &SignRawTransactionRequest) -> RawTransactionResult { unimplemented!() }

fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!()
}

Expand Down
5 changes: 1 addition & 4 deletions mm2src/coins/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,7 @@ impl MarketCoinOps for SolanaCoin {
})
}

fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!()
}

Expand Down
5 changes: 1 addition & 4 deletions mm2src/coins/solana/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,7 @@ impl MarketCoinOps for SplToken {
})
}

fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!()
}

Expand Down
5 changes: 2 additions & 3 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ impl MarketCoinOps for TendermintCoin {
})
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
// Sanity check
let _: TxRaw = try_fus!(Message::decode(input.payment_tx.as_slice()));

Expand All @@ -2581,8 +2581,7 @@ impl MarketCoinOps for TendermintCoin {

if let Some(tx_status_code) = tx_status_code {
return match tx_status_code {
// Tendermint uses Byzantine Fault Tolerance (BFT), achieve instant finality once a block is committed.
cosmrs::tendermint::abci::Code::Ok => Ok(1u64),
cosmrs::tendermint::abci::Code::Ok => Ok(()),
cosmrs::tendermint::abci::Code::Err(err_code) => Err(format!(
"Got error code: '{}' for tx: '{}'. Broadcasted tx isn't valid.",
err_code, tx_hash
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl MarketCoinOps for TendermintToken {
})
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
self.platform_coin.wait_for_confirmations(input)
}

Expand Down
5 changes: 1 addition & 4 deletions mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl MarketCoinOps for TestCoin {
#[inline(always)]
async fn sign_raw_tx(&self, _args: &SignRawTransactionRequest) -> RawTransactionResult { unimplemented!() }

fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl MarketCoinOps for BchCoin {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
utxo_common::wait_for_confirmations(&self.utxo_arc, input)
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/qtum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ impl MarketCoinOps for QtumCoin {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
utxo_common::wait_for_confirmations(&self.utxo_arc, input)
}

Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl UtxoRpcClientEnum {
requires_notarization: bool,
wait_until: u64,
check_every: u64,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
) -> Box<dyn Future<Item = (), Error = String> + Send> {
let selfi = self.clone();
let mut tx_not_found_retries = TX_NOT_FOUND_RETRIES;
let fut = async move {
Expand All @@ -185,7 +185,7 @@ impl UtxoRpcClientEnum {
t.rawconfirmations.unwrap_or(t.confirmations)
};
if tx_confirmations >= confirmations {
return Ok(tx_confirmations as u64);
return Ok(());
} else {
info!(
"Waiting for tx {:?} confirmations, now {}, required {}, requires_notarization {}",
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ impl MarketCoinOps for SlpToken {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
self.platform_coin.wait_for_confirmations(input)
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/utxo_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,7 @@ async fn sign_raw_utxo_tx<T: AsRef<UtxoCoinFields> + UtxoTxGenerationOps>(
pub fn wait_for_confirmations(
coin: &UtxoCoinFields,
input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
) -> Box<dyn Future<Item = (), Error = String> + Send> {
let mut tx: UtxoTx = try_fus!(deserialize(input.payment_tx.as_slice()).map_err(|e| ERRL!("{:?}", e)));
tx.tx_hash_algo = coin.tx_hash_algo;
coin.rpc_client.wait_for_confirmations(
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/utxo_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ impl MarketCoinOps for UtxoStandardCoin {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
utxo_common::wait_for_confirmations(&self.utxo_arc, input)
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ impl MarketCoinOps for ZCoin {
utxo_common::sign_raw_tx(self, args).await
}

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> {
utxo_common::wait_for_confirmations(self.as_ref(), input)
}

Expand Down
25 changes: 11 additions & 14 deletions mm2src/mm2_main/src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,20 +1862,17 @@ impl TakerSwap {
let wait_fut = self
.maker_coin
.wait_for_confirmations(confirm_maker_payment_spend_input);
let confirmations = match wait_fut.compat().await {
Ok(conf) => conf,
Err(err) => {
return Ok((Some(TakerSwapCommand::PrepareForTakerPaymentRefund), vec![
TakerSwapEvent::MakerPaymentSpendConfirmFailed(
ERRL!("!wait for maker payment spend confirmations: {}", err).into(),
),
TakerSwapEvent::TakerPaymentWaitRefundStarted {
wait_until: self.wait_refund_until(),
},
]));
},
};
info!("Maker payment spend confirmed. Confirmation number: {}", confirmations);
if let Err(err) = wait_fut.compat().await {
return Ok((Some(TakerSwapCommand::PrepareForTakerPaymentRefund), vec![
TakerSwapEvent::MakerPaymentSpendConfirmFailed(
ERRL!("!wait for maker payment spend confirmations: {}", err).into(),
),
TakerSwapEvent::TakerPaymentWaitRefundStarted {
wait_until: self.wait_refund_until(),
},
]));
}
info!("Maker payment spend confirmed");
Ok((Some(TakerSwapCommand::Finish), vec![
TakerSwapEvent::MakerPaymentSpendConfirmed,
]))
Expand Down

0 comments on commit 0073fe8

Please sign in to comment.