Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp authored and JoeGruffins committed Jan 15, 2025
1 parent 5739326 commit 6439f9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 12 additions & 16 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,6 @@ func (w *assetWallet) Redeem(form *asset.RedeemForm, feeWallet *assetWallet, non
// This is still a fee estimate. If we add a redemption confirmation method
// as has been discussed, then maybe the fees can be updated there.
fees := g.RedeemN(len(form.Redemptions)) * form.FeeSuggestion

return txs, outputCoin, fees, nil
}

Expand Down Expand Up @@ -3771,14 +3770,6 @@ func (w *assetWallet) confirmTransaction(coinID dex.Bytes, confirmTx *asset.Conf
var txHash common.Hash
copy(txHash[:], coinID)

// If the status of the swap was refunded when we tried to refund, the
// zero hash is saved. We don't know the tx that altered the swap or
// how many confs it has. Assume confirmed.
zeroHash := common.Hash{}
if txHash == zeroHash {
return confStatus(w.finalizeConfs, w.finalizeConfs, txHash), nil
}

contractVer, secretHash, err := dexeth.DecodeContractData(confirmTx.Contract())
if err != nil {
return nil, fmt.Errorf("failed to decode contract data: %w", err)
Expand All @@ -3788,13 +3779,12 @@ func (w *assetWallet) confirmTransaction(coinID dex.Bytes, confirmTx *asset.Conf

// If we have local information, use that.
if found, s := w.localTxStatus(txHash); found {
if s.assumedLost || len(s.nonceReplacement) > 0 {
if !s.feeReplacement {
// Tell core to update it's coin ID.
txHash = common.HexToHash(s.nonceReplacement)
} else {
return nil, asset.ErrTxLost
}
if s.assumedLost {
return nil, asset.ErrTxLost
}
if len(s.nonceReplacement) > 0 {
// Tell core to update it's coin ID.
txHash = common.HexToHash(s.nonceReplacement)
}

var confirmStatus *asset.ConfirmTxStatus
Expand Down Expand Up @@ -4953,6 +4943,10 @@ func (w *assetWallet) userActionNonceReplacement(actionB []byte) error {
w.log.Infof("Abandoning transaction %s via user action", txHash)
wt.AssumedLost = true
w.tryStoreDBTx(wt)
pendingTx := w.pendingTxs[idx]
if pendingTx.Nonce.Cmp(w.confirmedNonceAt) == 0 {
w.pendingNonceAt.Add(w.pendingNonceAt, big.NewInt(-1))
}
copy(w.pendingTxs[idx:], w.pendingTxs[idx+1:])
w.pendingTxs = w.pendingTxs[:len(w.pendingTxs)-1]
return nil
Expand Down Expand Up @@ -5013,6 +5007,7 @@ func (w *assetWallet) userActionRecoverNonces(actionB []byte) error {
if !*action.Recover {
// Don't reset recoveryRequestSent. They won't see this message again until
// they reboot.
w.emit.ActionResolved(w.missingNoncesActionID())
return nil
}
maxFeeRate, tipRate, err := w.recommendedMaxFeeRate(w.ctx)
Expand All @@ -5023,6 +5018,7 @@ func (w *assetWallet) userActionRecoverNonces(actionB []byte) error {
defer w.nonceMtx.Unlock()
missingNonces := findMissingNonces(w.confirmedNonceAt, w.pendingNonceAt, w.pendingTxs)
if len(missingNonces) == 0 {
w.emit.ActionResolved(w.missingNoncesActionID())
return nil
}
for i, n := range missingNonces {
Expand Down
12 changes: 8 additions & 4 deletions client/core/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3069,12 +3069,18 @@ func (c *Core) confirmRedemptions(t *trackedTrade, matches []*matchTracker) {
// This method accesses match fields and MUST be called with the trackedTrade
// mutex lock held for writes.
func (c *Core) confirmRedemption(t *trackedTrade, match *matchTracker) (bool, error) {
var coinID order.CoinID
if match.Side == order.Maker {
coinID = match.MetaData.Proof.MakerRedeem
} else {
coinID = match.MetaData.Proof.TakerRedeem
}
return c.confirmTx(t, match, &txInfo{
confs: match.redemptionConfs,
confsReq: match.redemptionConfsReq,
numTries: &match.confirmRedemptionNumTries,
wallet: t.wallets.toWallet,
coinID: match.MetaData.Proof.MakerRedeem,
coinID: coinID,
txType: asset.CTRedeem,
fee: t.redeemFee,
isRejected: &match.redemptionRejected,
Expand Down Expand Up @@ -3219,7 +3225,6 @@ func (c *Core) confirmTx(t *trackedTrade, match *matchTracker, info *txInfo) (bo
t.dc.log.Errorf("Failed to update match in db %v", err)
}
return false, errors.New(info.counterTxError)

case errors.Is(err, asset.ErrTxRejected):
*info.isRejected = true
actionRequest, note := newRejectedTxNote(info.wallet.AssetID, t.ID(), info.coinID, info.txType)
Expand All @@ -3230,9 +3235,8 @@ func (c *Core) confirmTx(t *trackedTrade, match *matchTracker, info *txInfo) (bo
return false, fmt.Errorf("%s transaction %s was rejected. Seeking user approval before trying again",
unbip(info.wallet.AssetID), coinIDString(info.wallet.AssetID, info.coinID))
case errors.Is(err, asset.ErrTxLost):
info.handleLostTx()
c.log.Infof("Transaction %s (%s) has been noted as lost.", info.coinID, unbip(info.wallet.AssetID))

info.handleLostTx()
if err := t.db.UpdateMatch(&match.MetaMatch); err != nil {
t.dc.log.Errorf("failed to update match after lost tx reported: %v", err)
}
Expand Down

0 comments on commit 6439f9c

Please sign in to comment.