Skip to content

Commit 968a8a1

Browse files
rolznzim-adithya
andauthored
fix: ignore swap out payment timeout (#1517)
* fix: ignore swap out payment timeout * chore: add comment to explain timeout in lnd --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com>
1 parent 3318128 commit 968a8a1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lnclient/lnd/lnd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ func (svc *LNDService) SendPaymentSync(ctx context.Context, payReq string, amoun
442442
}
443443

444444
if resp.Status != lnrpc.Payment_SUCCEEDED {
445+
// In LND, timeout error only happens when there are more routes to try
446+
// but we ran out of time in contrast to LDK where the payment is initiated
447+
// and might still succeed after receiving timeout error
448+
// See https://github.com/lightningnetwork/lnd/issues/4269#issuecomment-626279140
445449
failureReasonMessage := resp.FailureReason.String()
446450
logger.Logger.WithFields(logrus.Fields{
447451
"bolt11": payReq,

swaps/swaps_service.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,18 +1088,20 @@ func (svc *swapsService) startSwapOutListener(swap *db.Swap) {
10881088
"swap_id": swap.SwapId,
10891089
}
10901090
sendPaymentTimeout := int64(3600)
1091-
holdInvoicePayment, err := svc.transactionsService.SendPaymentSync(svc.ctx, swap.Invoice, nil, metadata, svc.lnClient, nil, nil, &sendPaymentTimeout)
1091+
logger.Logger.WithField("swapId", swap.SwapId).Info("Initiating swap invoice payment")
1092+
_, err = svc.transactionsService.SendPaymentSync(svc.ctx, swap.Invoice, nil, metadata, svc.lnClient, nil, nil, &sendPaymentTimeout)
10921093
if err != nil {
1093-
logger.Logger.WithError(err).WithFields(logrus.Fields{
1094-
"swapId": swap.SwapId,
1095-
}).Error("Error paying the swap invoice")
1096-
paymentErrorCh <- err
1097-
return
1098-
}
1099-
logger.Logger.WithField("swapId", swap.SwapId).Info("Initiated swap invoice payment")
1100-
if holdInvoicePayment.PaymentHash != swap.PaymentHash {
1101-
paymentErrorCh <- errors.New("swap hold payment hash mismatch")
1102-
return
1094+
if errors.Is(err, lnclient.NewTimeoutError()) {
1095+
logger.Logger.WithFields(logrus.Fields{
1096+
"swapId": swap.SwapId,
1097+
}).Info("Ignoring payment timeout while swapping out")
1098+
} else {
1099+
logger.Logger.WithError(err).WithFields(logrus.Fields{
1100+
"swapId": swap.SwapId,
1101+
}).Error("Error paying the swap invoice")
1102+
paymentErrorCh <- err
1103+
return
1104+
}
11031105
}
11041106
}()
11051107
case boltz.TransactionMempool:

0 commit comments

Comments
 (0)