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): remove the need for takers to confirm their payment #2249

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 17 additions & 1 deletion mm2src/coins/qrc20/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,23 @@ impl Qrc20Coin {
receiver,
secret_hash,
..
} = try_s!(self.erc20_payment_details_from_tx(&tx).await);
} = try_s!(
retry_on_err!(async { self.erc20_payment_details_from_tx(&tx).await })
.until_ready()
.repeat_every_secs(check_every)
.until_s(wait_until)
.inspect_err({
let tx_hash = tx.hash().reversed();
move |e| {
error!(
"Failed to retrieve QRC20 payment details from transaction {} \
will retry in {} seconds. Error: {:?}",
tx_hash, check_every, e
)
}
})
.await
);

loop {
// Try to find a 'receiverSpend' contract call.
Expand Down
26 changes: 3 additions & 23 deletions mm2src/mm2_main/src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,34 +1715,14 @@ impl TakerSwap {
self.p2p_privkey,
);

let confirm_taker_payment_input = ConfirmPaymentInput {
payment_tx: self.r().taker_payment.clone().unwrap().tx_hex.0,
confirmations: self.r().data.taker_payment_confirmations,
requires_nota: self.r().data.taker_payment_requires_nota.unwrap_or(false),
wait_until: self.r().data.taker_payment_lock,
check_every: WAIT_CONFIRM_INTERVAL_SEC,
};
let wait_f = self
.taker_coin
.wait_for_confirmations(confirm_taker_payment_input)
.compat();
if let Err(err) = wait_f.await {
return Ok((Some(TakerSwapCommand::PrepareForTakerPaymentRefund), vec![
TakerSwapEvent::TakerPaymentWaitConfirmFailed(
ERRL!("!taker_coin.wait_for_confirmations: {}", err).into(),
),
TakerSwapEvent::TakerPaymentWaitRefundStarted {
wait_until: self.wait_refund_until(),
},
]));
}

#[cfg(any(test, feature = "run-docker-tests"))]
if self.fail_at == Some(FailAt::WaitForTakerPaymentSpendPanic) {
// Wait for 5 seconds before panicking to ensure the message is sent
Timer::sleep(5.).await;
panic!("Taker panicked unexpectedly at wait for taker payment spend");
}

info!("Taker payment confirmed");
info!("Waiting for maker to spend taker payment!");

let wait_until = match std::env::var("USE_TEST_LOCKTIME") {
Ok(_) => self.r().data.started_at,
Expand Down
5 changes: 1 addition & 4 deletions mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,8 @@ fn test_taker_completes_swap_after_taker_payment_spent_while_offline() {
// stop taker after taker payment sent
let taker_payment_msg = "Taker payment tx hash ";
block_on(mm_alice.wait_for_log(120., |log| log.contains(taker_payment_msg))).unwrap();
let alice_log = mm_alice.log_as_utf8().unwrap();
let tx_hash_start = alice_log.find(taker_payment_msg).unwrap() + taker_payment_msg.len();
let payment_tx_hash = alice_log[tx_hash_start..tx_hash_start + 64].to_string();
// ensure p2p message is sent to the maker, this happens before this message:
block_on(mm_alice.wait_for_log(120., |log| log.contains(&format!("Waiting for tx {}", payment_tx_hash)))).unwrap();
block_on(mm_alice.wait_for_log(120., |log| log.contains("Waiting for maker to spend taker payment!"))).unwrap();
alice_conf.conf["dbdir"] = mm_alice.folder.join("DB").to_str().unwrap().into();
block_on(mm_alice.stop()).unwrap();

Expand Down
Loading