Skip to content

Commit

Permalink
fix: make xpay exit handling more reliable (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Feb 1, 2025
1 parent 4d51493 commit 9c92159
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/lightning/PendingPaymentTracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Logger from '../Logger';
import { racePromise } from '../PromiseUtils';
import { formatError, getHexBuffer, getHexString } from '../Utils';
import { getHexBuffer, getHexString } from '../Utils';
import DefaultMap from '../consts/DefaultMap';
import LightningPayment, {
LightningPaymentStatus,
Expand Down Expand Up @@ -233,7 +233,7 @@ class PendingPaymentTracker {
if (
lightningClient.type === NodeType.CLN &&
!isPermanentError &&
formatError(e).includes('xpay')
ClnPendingPaymentTracker.shouldBeWatched(e)
) {
this.lightningTrackers[lightningClient.type].watchPayment(
lightningClient,
Expand Down
13 changes: 10 additions & 3 deletions lib/lightning/paymentTrackers/ClnPendingPaymentTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class ClnPendingPaymentTracker extends NodePendingPendingTracker {
);
}

public static shouldBeWatched = (error: unknown) => {
const msg = formatError(error);
return (
(msg.includes('Failed after') && msg.includes('attempts')) ||
msg.includes('xpay') ||
msg === 'Connection dropped'
);
};

public stop = () => {
clearInterval(this.checkInterval as unknown as number);
};
Expand All @@ -42,12 +51,10 @@ class ClnPendingPaymentTracker extends NodePendingPendingTracker {
promise
.then((result) => this.handleSucceededPayment(preimageHash, result))
.catch((error) => {
const msg = formatError(error);

// CLN xpay throws errors while the payment is still pending
if (
!this.isPermanentError(error) &&
(msg.includes('xpay') || msg === 'Connection dropped')
ClnPendingPaymentTracker.shouldBeWatched(error)
) {
this.watchPayment(client, invoice, preimageHash);
} else {
Expand Down

0 comments on commit 9c92159

Please sign in to comment.