fix(payments): stop stale invoices from wedging payment polling - #746
Open
Anshumancanrock wants to merge 2 commits into
Open
fix(payments): stop stale invoices from wedging payment polling#746Anshumancanrock wants to merge 2 commits into
Anshumancanrock wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: edec59d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A relay running pay-to-relay can stop admitting paying users, with
delete from invoicesas the only known workaround. There are two causes.The first is invoices that can never be retired. The worker marks a pending
invoice expired when the processor reports it gone and the invoice is past its
expiry. An invoice with no expiry fails that second condition forever. LNURL
creates every invoice without one, so there it hits every unpaid invoice.
The second is the polling window. The worker checks ten pending invoices per run,
always the ten oldest, so once ten are stuck it never looks past them and newer
payments never clear.
Invoices now get a default expiry when the processor supplies none, existing rows
without one are backfilled, and the worker walks the queue ten at a time instead
of restarting at the oldest ten.
Related Issue
#342
Motivation and Context
I did not change when the worker gives up on an invoice. It still retires one only
on a 404, never on a network error. #575 chose that deliberately and it is right:
a network error means we do not know whether the invoice was paid, and LNURL and
NWC have no callback, so retiring one wrongly would lose the payment.
Invoices that used to sit pending forever now get retired
after the default expiry, so on a processor with no callback a very late payment
will not be picked up. Hence a 24 hour default rather than the hour a typical
Lightning invoice lives for, and a documented setting for processors that issue
longer-lived ones.
How Has This Been Tested?
20 new unit tests, and the full suite passes.
Ran the maintenance worker against a local Postgres:
drained them over two runs, and newly created invoices were reached on the third.
across ten runs before the change, and are picked up every cycle after it.