Skip to content

Commit

Permalink
WIP try not to jump status
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Jun 22, 2023
1 parent 74f72b1 commit c170795
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions client/core/trade.go
Expand Up @@ -92,8 +92,9 @@ type matchTracker struct {

// confirmRedemptionNumTries is just used for logging.
confirmRedemptionNumTries int
// redemptionConfs and redemptionConfsReq are set while the redemption
// confirmation process is running.
// redemptionConfs and redemptionConfsReq are updated while the redemption
// confirmation process is running. Their values are not updated after the
// match reaches MatchConfirmed status.
redemptionConfs uint64
redemptionConfsReq uint64

Expand Down Expand Up @@ -1765,7 +1766,6 @@ func shouldConfirmRedemption(match *matchTracker, log dex.Logger) bool {
proof := &match.MetaData.Proof
if len(proof.Auth.RedeemSig) == 0 {
log.Warnf("Redeemed match still needs a redeem acknowledgement! (match %v)", match)
return false
}
if match.Side == order.Maker {
return len(proof.MakerRedeem) > 0
Expand Down Expand Up @@ -2823,7 +2823,11 @@ func (c *Core) sendRedeemAsync(t *trackedTrade, match *matchTracker, coinID, sec
if match.Side == order.Maker && match.Status < order.MatchComplete {
// As maker, this is the end. However, this diverges from server,
// which still needs taker's redeem.
match.Status = order.MatchComplete
if conf := match.redemptionConfs; conf > 0 && conf >= match.redemptionConfsReq {
match.Status = order.MatchConfirmed // redeem tx already confirmed before redeem request accepted by server
} else {
match.Status = order.MatchComplete
}
}
err = t.db.UpdateMatch(&match.MetaMatch)
if err != nil {
Expand Down Expand Up @@ -2856,11 +2860,6 @@ func (t *trackedTrade) redeemFee() uint64 {
// This method accesses match fields and MUST be called with the trackedTrade
// mutex lock held for writes.
func (t *trackedTrade) confirmRedemption(match *matchTracker) {
if len(match.MetaData.Proof.Auth.RedeemSig) == 0 { // shouldConfirmRedemption should prevent this
t.dc.log.Warnf("Not confirming match %v before it is reported to server", match)
return // let resendPendingRequests have it
}

// In some cases the wallet will need to send a new redeem transaction.
toWallet := t.wallets.toWallet

Expand Down Expand Up @@ -2922,14 +2921,12 @@ func (t *trackedTrade) confirmRedemption(match *matchTracker) {
}
}

if redemptionStatus.Req <= redemptionStatus.Confs {
match.redemptionConfs, match.redemptionConfsReq = redemptionStatus.Confs, redemptionStatus.Req

if redemptionStatus.Confs >= redemptionStatus.Req &&
(len(match.MetaData.Proof.Auth.RedeemSig) > 0 || t.isSelfGoverned()) {
redemptionConfirmed = true
match.Status = order.MatchConfirmed
match.redemptionConfs = 0
match.redemptionConfsReq = 0
} else {
match.redemptionConfs = redemptionStatus.Confs
match.redemptionConfsReq = redemptionStatus.Req
}

if redemptionResubmitted || redemptionConfirmed {
Expand Down

0 comments on commit c170795

Please sign in to comment.