Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legacy-swap): taker failed spend maker payment marked as failed #2199

Open
wants to merge 29 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1461212
WIP: new fn confirm_maker_payment_spend, Taker command and events
laruh Aug 23, 2024
31292be
Merge remote-tracking branch 'origin/dev' into taker-failed-swaps-mar…
laruh Aug 25, 2024
0ede740
update events in recreate_taker_swap_taker_expected.json
laruh Aug 26, 2024
9c6c892
update events in recreate_taker_swap_taker_payment_wait_confirm_faile…
laruh Aug 26, 2024
b716806
update events in for_tests.rs consts, taker_swap.rs mod taker_swap_te…
laruh Aug 26, 2024
5c47ef0
add "MakerPaymentSpendConfirmed" to TAKER_ACTUAL_EVENTS_TAKER_SPENDS_…
laruh Aug 26, 2024
3117c5f
Merge remote-tracking branch 'origin/dev' into taker-failed-swaps-mar…
laruh Sep 5, 2024
eca0bda
provide "MakerPaymentSpendConfirmed" success event in more test jsons
laruh Sep 5, 2024
0e9a807
log events
laruh Sep 5, 2024
eb16235
TakerSwapEvent::MakerPaymentSpentByWatcher(_) => Some(TakerSwapComman…
laruh Sep 5, 2024
1a1a775
in taker_restart.rs provide TakerSwapCommand::ConfirmMakerPaymentSpen…
laruh Sep 5, 2024
3af96a5
move TakerSwapEvent::MakerPaymentSpendConfirmFailed in MakerSavedEvent
laruh Sep 5, 2024
1c3c935
use TakerSwapCommand::SpendMakerPayment => check_maker_payment_spend_…
laruh Sep 5, 2024
7829b4b
return TakerSwapEvent::MakerPaymentSpentByWatcher(_) => Some(TakerSwa…
laruh Sep 5, 2024
075de97
add "MakerPaymentSpendConfirmed" to TAKER_USING_WATCHERS_SUCCESS_EVENTS
laruh Sep 5, 2024
cc7c963
add "MakerPaymentSpendConfirmed" to TAKER_USING_WATCHERS_SUCCESS_EVEN…
laruh Sep 5, 2024
69ed68e
remove logs
laruh Sep 5, 2024
b2446b9
self.r().data.maker_payment_requires_nota.unwrap_or(false)
laruh Sep 6, 2024
2c119be
provide number of confirmations in wait_for_confirmations
laruh Sep 8, 2024
b9ba150
Merge remote-tracking branch 'origin/dev' into taker-failed-swaps-mar…
laruh Sep 8, 2024
165ddfe
provide requires_nota:false in confirm_maker_payment_spend
laruh Sep 26, 2024
b50b2a3
review: make doc com of wait_for_confirmations clearer
laruh Sep 26, 2024
6fa527a
Merge remote-tracking branch 'origin/dev' into taker-failed-swaps-mar…
laruh Sep 26, 2024
0073fe8
Revert "provide number of confirmations in wait_for_confirmations"
laruh Sep 26, 2024
aed8d4c
review: for old saved swaps check "TakerSwapEvent::MakerPaymentSpent"…
laruh Sep 27, 2024
ed91569
review: add "MakerPaymentSpendConfirmed" event in const FINISHED_TAKE…
laruh Sep 27, 2024
0661ee2
review: cover ConfirmMakerPaymentSpend for MakerPaymentSpentByWatcher
laruh Sep 27, 2024
5ce137f
review: add SAVED_SWAP_V for new version fields in TakerSavedSwap and…
laruh Sep 29, 2024
f93fcde
update confirmation comments in confirm_maker_payment_spend and in co…
laruh Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
macro_rules! update_status_with_error {
($status: ident, $error: ident) => {
match $error.get_inner() {
Expand Down Expand Up @@ -2328,7 +2328,8 @@ impl MarketCoinOps for EthCoin {
Ok(conf) => {
if conf == confirmed_at {
status.append(" Confirmed.");
break Ok(());
// Let's avoid risking additional errors by calling `current_block` and instead return required_confirms
break Ok(required_confirms.as_u64());
onur-ozkan marked this conversation as resolved.
Show resolved Hide resolved
shamardy marked this conversation as resolved.
Show resolved Hide resolved
}
},
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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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(()),
HTLCStatus::Pending | HTLCStatus::Succeeded => return Ok(1u64),
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(()),
HTLCStatus::Claimable | HTLCStatus::Succeeded => return Ok(1u64),
HTLCStatus::Pending => info!("Payment {} not received yet!", payment_hex),
HTLCStatus::Failed => return ERR!("Lightning swap payment {} failed", payment_hex),
},
Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@ 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;

fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send>;
/// 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>;
shamardy marked this conversation as resolved.
Show resolved Hide resolved

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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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<(), String> {
) -> Result<u64, String> {
let tx_hash = H256Json::from(qtum_tx.hash().reversed());
try_s!(
let confirmations = 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(())
Ok(confirmations)
}

/// Generate `ContractCallOutput` outputs required to send a swap payment.
Expand Down
5 changes: 4 additions & 1 deletion mm2src/coins/siacoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ 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 = (), Error = String> + Send> {
fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, Error = String> + Send> {
unimplemented!()
}

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

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

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

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

Expand Down
5 changes: 3 additions & 2 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
// Sanity check
let _: TxRaw = try_fus!(Message::decode(input.payment_tx.as_slice()));

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

if let Some(tx_status_code) = tx_status_code {
return match tx_status_code {
cosmrs::tendermint::abci::Code::Ok => Ok(()),
// 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::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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
self.platform_coin.wait_for_confirmations(input)
}

Expand Down
5 changes: 4 additions & 1 deletion mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ 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 = (), Error = String> + Send> {
fn wait_for_confirmations(
&self,
_input: ConfirmPaymentInput,
) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
) -> Box<dyn Future<Item = u64, 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(());
return Ok(tx_confirmations as u64);
} 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, 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 = (), Error = String> + Send> {
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> {
utxo_common::wait_for_confirmations(self.as_ref(), input)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"MakerPaymentReceived",
"MakerPaymentWaitConfirmStarted",
"MakerPaymentValidatedAndConfirmed",
"TakerPaymentSent",
"TakerPaymentSpent",
"MakerPaymentSpent",
"MakerPaymentSpendConfirmed",
"Finished"
],
"error_events": [
Expand All @@ -164,8 +166,12 @@
"TakerPaymentDataSendFailed",
"TakerPaymentWaitForSpendFailed",
"MakerPaymentSpendFailed",
"MakerPaymentSpendConfirmFailed",
"TakerPaymentWaitRefundStarted",
"TakerPaymentRefundStarted",
"TakerPaymentRefunded",
"TakerPaymentRefundFailed"
"TakerPaymentRefundedByWatcher",
"TakerPaymentRefundFailed",
"TakerPaymentRefundFinished"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"taker_coin":"MORTY",
"gui":"atomicDEX 0.5.1 iOS",
"mm_version":"1b065636a",
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","Finished"],
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
"taker_coin":"MORTY",
"gui":"atomicDEX 0.5.1 iOS",
"mm_version":"1b065636a",
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","Finished"],
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
"taker_coin":"MORTY",
"gui":null,
"mm_version":"",
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed","TakerPaymentRefundFinished"]
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed","TakerPaymentRefundFinished"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"taker_coin":"MORTY",
"gui":null,
"mm_version":"",
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed","TakerPaymentRefundFinished"]
"success_events":["Started","Negotiated","TakerFeeSent","TakerPaymentInstructionsReceived","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],
"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed","TakerPaymentRefundFinished"]
}
2 changes: 1 addition & 1 deletion mm2src/mm2_main/src/lp_swap/maker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ impl MakerSwapEvent {
},
MakerSwapEvent::TakerPaymentSpent(_) => "Taker payment spent...".to_owned(),
MakerSwapEvent::TakerPaymentSpendFailed(_) => "Taker payment spend failed...".to_owned(),
MakerSwapEvent::TakerPaymentSpendConfirmStarted => "Taker payment send wait confirm started...".to_owned(),
MakerSwapEvent::TakerPaymentSpendConfirmStarted => "Taker payment spend confirm started...".to_owned(),
MakerSwapEvent::TakerPaymentSpendConfirmed => "Taker payment spend confirmed...".to_owned(),
MakerSwapEvent::TakerPaymentSpendConfirmFailed(_) => "Taker payment spend confirm failed...".to_owned(),
MakerSwapEvent::MakerPaymentWaitRefundStarted { wait_until } => {
Expand Down
2 changes: 2 additions & 0 deletions mm2src/mm2_main/src/lp_swap/recreate_swap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ fn convert_taker_to_maker_events(
| TakerSwapEvent::MakerPaymentWaitConfirmStarted
| TakerSwapEvent::MakerPaymentValidatedAndConfirmed
| TakerSwapEvent::MakerPaymentSpent(_)
| TakerSwapEvent::MakerPaymentSpendConfirmed
| TakerSwapEvent::MakerPaymentSpendConfirmFailed(_)
| TakerSwapEvent::MakerPaymentSpentByWatcher(_)
| TakerSwapEvent::MakerPaymentSpendFailed(_)
// We don't know the reason at the moment, so we rely on the errors handling above.
Expand Down
1 change: 1 addition & 0 deletions mm2src/mm2_main/src/lp_swap/taker_restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub async fn get_command_based_on_maker_or_watcher_activity(
Err(e) => ERR!("Error {} when trying to find taker payment spend", e),
},
TakerSwapCommand::SpendMakerPayment => check_maker_payment_spend_and_add_event(ctx, swap, saved).await,
TakerSwapCommand::ConfirmMakerPaymentSpend => Ok(command),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below is related to this change in get_command_based_on_maker_or_watcher_activity.

I think we should return TakerSwapCommand::ConfirmMakerPaymentSpend instead of TakerSwapCommand::Finish here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.c. @dimxy

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems so.
search_for_swap_tx_spend_other fn may return unconfirmed txns.
So we need (with the created event MakerPaymentSpentByWatcher) to go to ConfirmMakerPaymentSpend command.
I think it's better to fix also get_command() to ensure MakerPaymentSpentByWatcher event triggers ConfirmMakerPaymentSpend.
And good to have a new swap watcher test for this to ensure the flow works okay

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to fix also get_command() to ensure MakerPaymentSpentByWatcher event triggers ConfirmMakerPaymentSpend.

yep, if we want to return TakerSwapCommand::ConfirmMakerPaymentSpend in check_maker_payment_spend_and_add_event, then we also need to cover confirmation step in get_command for MakerPaymentSpentByWatcher

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to fix also get_command() to ensure MakerPaymentSpentByWatcher event triggers ConfirmMakerPaymentSpend.

yep, if we want to return TakerSwapCommand::ConfirmMakerPaymentSpend in check_maker_payment_spend_and_add_event, then we also need to cover confirmation step in get_command for MakerPaymentSpentByWatcher

Hmm it means that we also need to update fn is_recoverable according to the same note as here #2199 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, if we want to return TakerSwapCommand::ConfirmMakerPaymentSpend in check_maker_payment_spend_and_add_event, then we also need to cover confirmation step in get_command for MakerPaymentSpentByWatcher

It will be done here

let event = TakerSwapEvent::MakerPaymentSpentByWatcher(tx_ident);
let to_save = TakerSavedEvent {
timestamp: now_ms(),
event,
};
swap.apply_event(to_save.event.clone());
saved.events.push(to_save);
let new_swap = SavedSwap::Taker(saved);
try_s!(new_swap.save_to_db(ctx).await);
info!("{}", MAKER_PAYMENT_SPENT_BY_WATCHER_LOG);
Ok(TakerSwapCommand::Finish)
by this change #2199 (comment)

Hmm it means that we also need to update fn is_recoverable according to the same note as here #2199 (comment)

Yes, I suppose.

one moment about watchers, do we actually use this feature in production? Im not sure that it is fully functional in prod.
If nope, we shouldn't change MakerPaymentSpentByWatcher handle in legacy get_command()function

It's used for utxo <-> utxo swap in production. We need to collect data about it though to know how many users used it etc.. , we should leave a comment about this to @KomodoPlatform/qa

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to handle it here too

TakerSwapEvent::MakerPaymentSpentByWatcher(_) => Some(TakerSwapCommand::Finish),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for utxo <-> utxo swap in production.

Got it, then I also update MakerPaymentSpentByWatcher cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to handle it here too

TakerSwapEvent::MakerPaymentSpentByWatcher(_) => Some(TakerSwapCommand::Finish),

yep, its what dimxy was referencing about

Copy link
Member Author

@laruh laruh Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Covered TakerSwapCommand::ConfirmMakerPaymentSpend for restart and watchers here 0661ee2


And good to have a new swap watcher test for this to ensure the flow works okay

@dimxy new events matching in get_command function already covered in watcher (restart) tests in swap_watchers_test.rs , when we compare expected event list with actual using check_actual_events function

fn check_actual_events(mm_alice: &MarketMakerIt, uuid: &str, expected_events: &[&'static str]) -> Value {

for example I removed "MakerPaymentSpendConfirmed" event from expected_events list in test_taker_saves_the_swap_as_successful_after_restart_panic_at_maker_payment_spend test

and got err https://github.com/laruh/atomicDEX-API/actions/runs/11091593379/job/30815533174#step:6:3409

thread 'docker_tests::swap_watcher_tests::test_taker_saves_the_swap_as_successful_after_restart_panic_at_maker_payment_spend' panicked at 'assertion failed: `(left == right)`
  left: `["Started", "Negotiated", "TakerFeeSent", "TakerPaymentInstructionsReceived", "MakerPaymentReceived", "MakerPaymentWaitConfirmStarted", "MakerPaymentValidatedAndConfirmed", "TakerPaymentSent", "WatcherMessageSent", "TakerPaymentSpent", "MakerPaymentSpentByWatcher", "Finished"]`,
 right: `["Started", "Negotiated", "TakerFeeSent", "TakerPaymentInstructionsReceived", "MakerPaymentReceived", "MakerPaymentWaitConfirmStarted", "MakerPaymentValidatedAndConfirmed", "TakerPaymentSent", "WatcherMessageSent", "TakerPaymentSpent", "MakerPaymentSpentByWatcher", "MakerPaymentSpendConfirmed", "Finished"]`', mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs:269:5

TakerSwapCommand::PrepareForTakerPaymentRefund | TakerSwapCommand::RefundTakerPayment => {
#[cfg(not(any(test, feature = "run-docker-tests")))]
{
Expand Down
Loading
Loading