Skip to content

Commit

Permalink
fix(swaps): lookupPayment return Pending on error
Browse files Browse the repository at this point in the history
This catches any errors within the `lookupPayment` swap client method
and returns a "pending" status - since we weren't able to determine a
resolution for the payment - rather than throwing an error. The error
was not being handled in the Swaps module.

Fixes #1701.
  • Loading branch information
sangaman committed Jul 1, 2020
1 parent 54d449e commit 3d78a55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/connextclient/ConnextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ class ConnextClient extends SwapClient {
default:
return { state: PaymentState.Pending };
}
} catch (e) {
this.logger.error(e);
throw errors.SERVER_ERROR;
} catch (err) {
this.logger.error(`could not lookup payment for ${rHash}`, err);
return { state: PaymentState.Pending }; // return pending if we hit an error
}
}

Expand Down
33 changes: 19 additions & 14 deletions lib/lndclient/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,22 +939,27 @@ class LndClient extends SwapClient {
}

public lookupPayment = async (rHash: string) => {
const payments = await this.listPayments(true);
for (const payment of payments.getPaymentsList()) {
if (payment.getPaymentHash() === rHash) {
switch (payment.getStatus()) {
case lndrpc.Payment.PaymentStatus.SUCCEEDED:
const preimage = payment.getPaymentPreimage();
return { preimage, state: PaymentState.Succeeded };
case lndrpc.Payment.PaymentStatus.IN_FLIGHT:
return { state: PaymentState.Pending };
default:
this.logger.warn(`unexpected payment state for payment with hash ${rHash}`);
/* falls through */
case lndrpc.Payment.PaymentStatus.FAILED:
return { state: PaymentState.Failed };
try {
const payments = await this.listPayments(true);
for (const payment of payments.getPaymentsList()) {
if (payment.getPaymentHash() === rHash) {
switch (payment.getStatus()) {
case lndrpc.Payment.PaymentStatus.SUCCEEDED:
const preimage = payment.getPaymentPreimage();
return { preimage, state: PaymentState.Succeeded };
default:
this.logger.warn(`unexpected payment state for payment with hash ${rHash}`);
/* falls through */
case lndrpc.Payment.PaymentStatus.IN_FLIGHT:
return { state: PaymentState.Pending };
case lndrpc.Payment.PaymentStatus.FAILED:
return { state: PaymentState.Failed };
}
}
}
} catch (err) {
this.logger.error(`could not lookup payment for ${rHash}`, err);
return { state: PaymentState.Pending };
}

// if no payment is found, we assume that the payment was never attempted by lnd
Expand Down

0 comments on commit 3d78a55

Please sign in to comment.