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

Merged
merged 31 commits into from
Oct 4, 2024

Conversation

laruh
Copy link
Member

@laruh laruh commented Aug 26, 2024

related to #2175 (comment)

To fix issue where taker doesnt wait for maker payment spend tx was confirmed we added two new events:

  • "MakerPaymentSpendConfirmed": successful event, which goes after "MakerPaymentSpent"
    Note: MakerPaymentSpent event means that broadcasted tx taker spends maker payment wasnt reverted
  • "MakerPaymentSpendConfirmFailed": error event, means that taker spend maker payment transaction confirmation was failed.

@laruh laruh added the in progress Changes will be made from the author label Aug 26, 2024
@laruh
Copy link
Member Author

laruh commented Aug 28, 2024

Second problem solving approach

If we wouldn't like to do changes in legacy taker swap events/logic and increase backward incompatibility risks, there is an alternative. We can add maker payment spend confirmation right after send_taker_spends_maker_payment in spend_maker_payment taker swap operation.

async fn spend_maker_payment(&self) -> Result<(Option<TakerSwapCommand>, Vec<TakerSwapEvent>), String> {
#[cfg(any(test, feature = "run-docker-tests"))]
if self.fail_at == Some(FailAt::MakerPaymentSpend) {
return Ok((Some(TakerSwapCommand::Finish), vec![
TakerSwapEvent::MakerPaymentSpendFailed("Explicit test failure".into()),
]));
} else if self.fail_at == Some(FailAt::MakerPaymentSpendPanic) {
panic!("Taker panicked unexpectedly at maker payment spend");
}
let other_maker_coin_htlc_pub = self.r().other_maker_coin_htlc_pub;
let secret = self.r().secret;
let taker_spends_payment_args = SpendPaymentArgs {
other_payment_tx: &self.r().maker_payment.clone().unwrap().tx_hex,
time_lock: self.maker_payment_lock.load(Ordering::Relaxed),
other_pubkey: &*other_maker_coin_htlc_pub,
secret: &secret.0,
secret_hash: &self.r().secret_hash.clone().0,
swap_contract_address: &self.r().data.maker_coin_swap_contract_address.clone(),
swap_unique_data: &self.unique_swap_data(),
watcher_reward: self.r().watcher_reward,
};
let maybe_spend_tx = self
.maker_coin
.send_taker_spends_maker_payment(taker_spends_payment_args)
.await;

If confirmation failed, then also return swap finish command and MakerPaymentSpendFailed event

                return Ok((Some(TakerSwapCommand::Finish), vec![
                    TakerSwapEvent::MakerPaymentSpendFailed(ERRL!("{}", err.get_plain_text_format()).into()),
                ]));

MakerPaymentSpendFailed is not actually correct event in the case of failed maker payment spend confirmation, but in this way we dont do changes in Taker commands and events logic.

In comparison, Maker has taker payment spend confirmation events in MakerSwapEvent:

TakerPaymentSpendConfirmStarted,
TakerPaymentSpendConfirmed,
TakerPaymentSpendConfirmFailed(SwapError),

@laruh
Copy link
Member Author

laruh commented Aug 30, 2024

Solved with second approach in this pr #2206

UPD: opened again as we decided to test both approaches #2206 (comment)

one problem with adding confirmation to SpendMakerPayment step is that GUI will not have the tx hash to show to user until tx is confirmed, users like to check tx on chain while it's awaiting confirmations

This pr approach could be preferable

@laruh laruh closed this Aug 30, 2024
@laruh laruh reopened this Sep 5, 2024
@shamardy
Copy link
Collaborator

shamardy commented Sep 6, 2024

@laruh this is still draft, should I review it? I want to check it so that I can close the other PR if there are no problems with the approach here.

@laruh
Copy link
Member Author

laruh commented Sep 8, 2024

@laruh this is still draft, should I review it? I want to check it so that I can close the other PR if there are no problems with the approach here.

Its almost r2r, I just wanted to fix these notes #2206 (review) in other approach and cherry pick commit to this branch, as both branches would have the same review notes. (already fixed this b2446b9, just confirmation number is left)

@laruh laruh marked this pull request as ready for review September 8, 2024 02:07
@laruh laruh removed the in progress Changes will be made from the author label Sep 8, 2024
@laruh laruh force-pushed the taker-failed-swaps-marked-successful branch from 4462a41 to 0073fe8 Compare September 26, 2024 13:49
@laruh laruh added in progress Changes will be made from the author and removed under review labels Sep 27, 2024
@laruh laruh force-pushed the taker-failed-swaps-marked-successful branch from cd75bd0 to aed8d4c Compare September 27, 2024 09:16
@laruh laruh force-pushed the taker-failed-swaps-marked-successful branch from d2fd10f to 5ce137f Compare September 29, 2024 12:20
@laruh laruh added under review and removed in progress Changes will be made from the author labels Sep 29, 2024
dimxy
dimxy previously approved these changes Oct 3, 2024
Copy link
Collaborator

@dimxy dimxy left a comment

Choose a reason for hiding this comment

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

LGTM

shamardy
shamardy previously approved these changes Oct 4, 2024
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

LGTM but for one nit!

Please open docs issue and add To Test comment to the PR opening comment.

mm2src/mm2_main/src/lp_swap/taker_swap.rs Outdated Show resolved Hide resolved
@shamardy shamardy requested a review from cipig October 4, 2024 08:54
@shamardy
Copy link
Collaborator

shamardy commented Oct 4, 2024

@cipig you tested this #2206 but we opted for a new event instead and implemented in this PR. Can you please check if the issue is resolved here?

@laruh
Copy link
Member Author

laruh commented Oct 4, 2024

Please open docs issue and add To Test comment to the PR opening comment.

KomodoPlatform/komodo-docs-mdx#351

@shamardy shamardy merged commit 359cb5c into dev Oct 4, 2024
26 checks passed
@shamardy shamardy deleted the taker-failed-swaps-marked-successful branch October 4, 2024 10:56
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 17, 2024
* dev:
  fix(cosmos): fix tx broadcasting error (#2238)
  chore(solana): remove solana implementation (#2239)
  chore(cli): remove leftover subcommands from help message (#2235)
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants