Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle pending payments when failed payments with same hash exist #2151

Merged
merged 17 commits into from
Feb 13, 2023

Conversation

vindard
Copy link
Contributor

@vindard vindard commented Jan 10, 2023

Description

This PR fixes an issue where our updatePendingPayments isn't able to progress past the isLnTxRecorded step because it wasn't able to register if pending ledger transactions also exist alongside settled failed ones.

  • The first step was to adjust the isLnTxRecorded check

  • The next step was to then fail a pending payment if its amount did not match the amount we got back from lnd (in the case of different amounts used for no-amount invoices)

Note

This PR assumes that there can't be 2 simultaneous pending payments (see a4f9e06) for the same hash with the same correct amount. It assumes there can only be 1 pending payment for the correct amount and multiple other failed payments for the same hash.

If this assumption does not hold then there is the risk that multiple payments out get settled for the same single lnd payment which would mean that users would notice an extra payment out. If we think this assumption isn't fair, we can consider adding some provision to account for potentially multiple pending payments (or we can wait until a user observes this in actual usage).

@vindard vindard requested a review from dolcalmi January 10, 2023 12:13
@vindard vindard changed the title fix: handle pending payments when failed payments with same has exist fix: handle pending payments when failed payments with same hash exist Jan 10, 2023
@vindard vindard force-pushed the add-mult-payment-handling branch 6 times, most recently from a845fc4 to 45bad5c Compare January 20, 2023 16:56
@vindard vindard marked this pull request as ready for review January 20, 2023 17:36
@vindard vindard force-pushed the add-mult-payment-handling branch 4 times, most recently from c1408ea to 17dfd87 Compare January 20, 2023 20:51
@gitguardian
Copy link

gitguardian bot commented Jan 20, 2023

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
5547718 Elliptic Curve Private Key 42ab2a4 dev/lnd/tls.key View secret
5547719 Elliptic Curve Private Key 42ab2a4 dev/lnd/tls.key.base64 View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@vindard vindard force-pushed the add-mult-payment-handling branch 3 times, most recently from ff66d6d to baf7aa7 Compare February 1, 2023 15:08
if (
status === PaymentStatus.Failed ||
// pendingPayment is a different version to latest payment from lnd
satsAmount !== toSats(paymentFlow.btcPaymentAmount.amount)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comparison should be made with invoice amount because fees can change depending on the route

Copy link
Contributor Author

@vindard vindard Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both sides of this is the invoice amount without fees (left from lnd, right from PaymentFlow)... is it?

src/app/payments/update-pending-payments.ts Outdated Show resolved Hide resolved
Comment on lines +286 to +285
if (!(filteredPayments && filteredPayments.length))
return new CouldNotFindTransactionError()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this.... so I cant re-try a failed invoice? an example can be done with OBW, create an invoice, close the app, try a payment (it will fail because is not connected) then open OBW wait to connect and try payment again (should succeed)

Copy link
Contributor Author

@vindard vindard Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this affects retry. As-is now we can always retry as tested here? https:/GaloyMoney/galoy/pull/2151/files#diff-15e9812156b4ff1c33faaaf99ffcc368a8af2756ccb7a5e81acdcfc46782db9fR2363

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same logic as what was here before at Ln259, except done over an array instead of a single payment instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you are including amount validation... lets validate it in staging.

hash: paymentHash,
})

return totalNotPending > 0 && totalPending === 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the material change that allows us to retry if there are both pending and settled txns (from multiple attempts)

dolcalmi
dolcalmi previously approved these changes Feb 13, 2023
Copy link
Collaborator

@dolcalmi dolcalmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with small comment, also, please let me know to test this in staging.

The 2nd success payment can't be made for some reason even with
liquidity available on the path. This could probably use some more
troubleshooting to determine if it's a:
- path liquidity problem
- lnd mission control issue
Needed to:
1. Make sure payment is above channel reserve
2. Probe 1st to avoid duplicate fee_reimburse when undoing txns
3. Add a manual 1-sat reimburse to accommodate sub-sat accounting
   inconsistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants