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

client/core: ensure redeem is accepted before confirm/complete match #2405

Merged
merged 1 commit into from Jul 10, 2023

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Jun 19, 2023

In certain cases, the redeem confirmation status was skipping the retries of the 'redeem' request. This was happening because confirmRedemption would advance the status to confirmed regardless of whether there was a stored RedeemSig, which indicates that the redeem request was accepted by the server.
This fixes the issue by adding the RedeemSig check to shouldConfirmRedemption, which allows resendPendingRequests when they are needed. only advancing to MatchConfirmed if both (a) match is confirmed, and (b) server has received and ack'd our redeem request, which is necessary to complete our role in the swap dance.

@chappjc chappjc force-pushed the send-redeem-before-confirm branch from b63a264 to b98a2ef Compare June 20, 2023 18:16
@chappjc chappjc added the bug bug or bugfix label Jun 21, 2023
client/core/trade.go Outdated Show resolved Hide resolved
@chappjc chappjc marked this pull request as draft June 22, 2023 14:10
@chappjc chappjc force-pushed the send-redeem-before-confirm branch 3 times, most recently from c170795 to 029b257 Compare June 23, 2023 22:01
@chappjc chappjc marked this pull request as ready for review June 23, 2023 22:46
Copy link
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

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

LGTM. shouldConfirmRedemption could return false if match.redemptionConfs > match.redemptionConfsReq, but nbd.

@chappjc
Copy link
Member Author

chappjc commented Jun 24, 2023

LGTM. shouldConfirmRedemption could return false if match.redemptionConfs > match.redemptionConfsReq, but nbd.

Will you walk me through this? I might be missing a detail.

Summary of the changes in current PR:

  • sendRedeemAsync sets status to MatchComplete, or if confs already checked and confs >= req, MatchConfirmed
  • confirmRedemption always sets/updates match.redemptionConfs, match.redemptionConfsReq. If there's also a RedeemSig already (or the trade is self-governed), it sets to MatchConfirmed

shouldConfirmRedemption is unchanged and will say false if already MatchConfirmed, which is correct since that state is only when confs >= req, set from a previous confirmRedemption call. So it will keep updating confs until either of the above sets it to MatchConfirmed. Is this last case of extra updates past req what you meant?

@martonp
Copy link
Contributor

martonp commented Jun 25, 2023

Is this last case of extra updates past req what you meant?

Yes. I guess it's better this way though.. the UI will be kept up to date.

@JoeGruffins
Copy link
Member

I'm not sure but I think inside of confirmRedemption if match.redemptionConfs >= match.redemptionConfsReq but we are waiting on (len(match.MetaData.Proof.Auth.RedeemSig) > 0 || t.isSelfGoverned()) a lot of the stuff in confirmRedemption can be skipped. There is no need to continue doing toWallet.Wallet.ConfirmRedemption especially.

Also, I guess setting match.Status = order.MatchConfirmed inside of sendRedeemAsync it will skip the notification on redemptionConfirmed in confirmRedemption. Does sendRedeemAsync need to set the status to confirmed or can that not just be left to confirmRedemption?

@chappjc
Copy link
Member Author

chappjc commented Jun 26, 2023

I'm not sure but I think inside of confirmRedemption if match.redemptionConfs >= match.redemptionConfsReq but we are waiting on (len(match.MetaData.Proof.Auth.RedeemSig) > 0 || t.isSelfGoverned()) a lot of the stuff in confirmRedemption can be skipped. There is no need to continue doing toWallet.Wallet.ConfirmRedemption especially.

The idea was to just keep updating the confirmation count, but you and @martonp both found this notable, so will change it. I had removed a short-circuit condition from a previous iteration: https://github.com/decred/dcrdex/compare/d0530fddea72201fe2cbe1ed01155823b0de356d..c17079563ceeaf401bd6c89399dfe88cff402d83

Also, I guess setting match.Status = order.MatchConfirmed inside of sendRedeemAsync it will skip the notification on redemptionConfirmed in confirmRedemption. Does sendRedeemAsync need to set the status to confirmed or can that not just be left to confirmRedemption?

I was trying to skip having to wait for another tick, but I think it'll do it in the same tick anyway. Updating. EDIT: Nope, won't be the same tick because the meat of sendRedeemAsync is async in a goroutine. Oh well, still changing it so it notifies.

@chappjc chappjc force-pushed the send-redeem-before-confirm branch from 029b257 to a21fa90 Compare June 26, 2023 14:34
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

Thanks for answering our nits.

@chappjc
Copy link
Member Author

chappjc commented Jun 27, 2023

Thanks for answering our nits.

Not nits. I repeatedly missed some important details on this one. Thanks for reviewing.

Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Just a rebase needed.

@chappjc chappjc force-pushed the send-redeem-before-confirm branch from a21fa90 to 2d178ce Compare July 10, 2023 15:32
@chappjc chappjc merged commit 8e7f49e into decred:master Jul 10, 2023
5 checks passed
@chappjc chappjc deleted the send-redeem-before-confirm branch July 10, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bug or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants