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

core: properly handle client->server request errors during trade #459

Merged
merged 7 commits into from
Jun 18, 2020

Conversation

itswisdomagain
Copy link
Member

@itswisdomagain itswisdomagain commented Jun 9, 2020

One potential cause for trade disruption as documented in #361 is when notifying the DEX after taking a required action results in an error such as when sending init request after broadcasting swap tx or when sending redeem request after redeeming the counter-party swap.

Currently, the client does not update the match status to indicate that the required action has been executed and also does not re-attempt sending the request (unless dexc is restarted).

Also, as mentioned in #302 (comment), for init errors, the client is unable to perform auto-refund when the swap's locktime expires.

This corrects the behaviour for failed client->server requests by

  • saving relevant details to database regardless of request success or failure
  • re-trying the request in the next trade.tick() (aka every 1/3rd bcastTimeout until the match is revoked or the client's swap is refunded, whichever happens first)
  • performing auto-refund for consistent init failures up till expiration of the client's swap locktime.

Worth noting that with this PR, all auto-refund cases should be covered. If there's a potential refund scenario not yet considered, please mention.

@itswisdomagain itswisdomagain marked this pull request as ready for review June 10, 2020 09:36
@itswisdomagain
Copy link
Member Author

I'm thinking #432 should go in first so I can add test case(s) for client->server request error scenarios and validate that the recovery steps implemented here work as expected.

client/core/trade.go Show resolved Hide resolved
client/core/trade.go Outdated Show resolved Hide resolved
client/core/trade.go Show resolved Hide resolved
client/core/trade.go Outdated Show resolved Hide resolved
client/core/trade.go Outdated Show resolved Hide resolved
client/core/core_test.go Show resolved Hide resolved
Comment on lines 445 to 455
wallet := t.wallets.toWallet
if !wallet.unlocked() {
log.Errorf("cannot redeem order %s, match %s, because %s wallet is not unlocked",
t.ID(), match.id, unbip(wallet.AssetID))
return false
}

walletLocked := !t.wallets.toWallet.unlocked()
Copy link
Member

Choose a reason for hiding this comment

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

I didn't mean to get rid of the first check. I just meant that there's no need to keep checking after that. The walletLocked variable would always be false, since you just verified it a few lines up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. Thought you meant all checks. The checks are not too relevant anyways since core tries to keep the wallets unlocked while there are active trades. But a user may manually lock the wallet, so restoring the checks just to be safe.

Currently, init request errors prevent swap details from being saved
for a even though the swap tx has been broadcasted. This made it
impossible to re-attempt sending the init request after some time or
to refund the swap if it becomes necessary to do so.

This is corrected by saving relevant swap details to database even
if sending the init request fails. Also, if sending the init req fails for a
match, the request is re-tried in the next call to trade.tick().

Finally, if sending the init request does not complete successfully
before the swap's locktime expires, the swap is refunded.
@chappjc
Copy link
Member

chappjc commented Jun 16, 2020

Note the new conflict for you.

@itswisdomagain
Copy link
Member Author

This should be up next for me:

add test case(s) for client->server request error scenarios and validate that the recovery steps implemented here work as expected.

@chappjc chappjc added the client label Jun 18, 2020
Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

OK with me now. Not sure if @buck54321 's review comment was addressed though.

@chappjc chappjc requested a review from buck54321 June 18, 2020 16:14
@chappjc chappjc merged commit 1e6e35d into decred:master Jun 18, 2020
@itswisdomagain itswisdomagain deleted the more-auto-refund branch June 18, 2020 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants