Skip to content

Commit

Permalink
notify in sendRedeemAsync, short-circuit in confirmRedemption
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Jun 26, 2023
1 parent cc8f105 commit a21fa90
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion client/core/trade.go
Expand Up @@ -2097,7 +2097,7 @@ func (c *Core) resendPendingRequests(t *trackedTrade) {
swapCoinID = proof.MakerSwap
case side == order.Taker && status == order.TakerSwapCast:
swapCoinID = proof.TakerSwap
case side == order.Maker && status == order.MakerRedeemed:
case side == order.Maker && status >= order.MakerRedeemed:
redeemCoinID = proof.MakerRedeem
case side == order.Taker && status >= order.MatchComplete:
redeemCoinID = proof.TakerRedeem
Expand Down Expand Up @@ -2831,6 +2831,11 @@ func (c *Core) sendRedeemAsync(t *trackedTrade, match *matchTracker, coinID, sec
if err != nil {
err = fmt.Errorf("error storing redeem ack sig in database: %v", err)
}
if match.Status == order.MatchConfirmed {
subject, details := t.formatDetails(TopicRedemptionConfirmed, match.token(), t.token())
note := newMatchNote(TopicRedemptionConfirmed, subject, details, db.Success, t, match)
t.notify(note)
}
t.mtx.Unlock()
}()
}
Expand Down Expand Up @@ -2858,6 +2863,25 @@ 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 confs := match.redemptionConfs; confs > 0 && confs >= match.redemptionConfsReq { // already there, stop checking
if len(match.MetaData.Proof.Auth.RedeemSig) == 0 && !t.isSelfGoverned() {
return // waiting on redeem request to succeed
}
// Redeem request just succeeded or we gave up on the server.
if match.Status == order.MatchConfirmed {
return // raced with concurrent sendRedeemAsync
}
match.Status = order.MatchConfirmed
err := t.db.UpdateMatch(&match.MetaMatch)
if err != nil {
t.dc.log.Errorf("failed to update match in db: %v", err)
}
subject, details := t.formatDetails(TopicRedemptionConfirmed, match.token(), t.token())
note := newMatchNote(TopicRedemptionConfirmed, subject, details, db.Success, t, match)
t.notify(note)
return
}

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

Expand Down

0 comments on commit a21fa90

Please sign in to comment.