Skip to content

fix: expire stale LNbits pending invoices#575

Merged
cameri merged 3 commits intocameri:mainfrom
kanishka0411:fix/expire-stale-lnbits-invoices
Apr 25, 2026
Merged

fix: expire stale LNbits pending invoices#575
cameri merged 3 commits intocameri:mainfrom
kanishka0411:fix/expire-stale-lnbits-invoices

Conversation

@kanishka0411
Copy link
Copy Markdown
Contributor

Description

Expired pending LNbits invoices can remain in the oldest pending polling batch forever when LNbits returns 404. This marks them expired only when the local invoice is already past expiresAt and the processor returns 404.
Generic processor/network errors still keep the invoice pending, and paid invoices remain completed even if their expiry timestamp has passed.

Related Issue

Fixes #333
Related to #342

Motivation and Context

The maintenance worker polls the oldest 10 pending invoices every minute. Stale invoices that LNbits has already purged (404) were being retried forever, blocking newer paid invoices from being reconciled.

How Has This Been Tested?

Added unit tests covering all four edge cases:

  • expired + 404 → expire it
  • expired + non-404 error → leave pending
  • non-expired + 404 → leave pending
  • LNbits returns unpaid + past expiry → EXPIRED; paid + past expiry → still COMPLETED

Commands run locally:

npx mocha test/unit/app/maintenance-worker.spec.ts test/unit/payments-processors/lnbits-payment-processor.spec.ts
npm run build:check
npx biome lint src/app/maintenance-worker.ts src/payments-processors/lnbits-payment-processor.ts test/unit/app/maintenance-worker.spec.ts test/unit/payments-processors/lnbits-payment-processor.spec.ts

Result: 36 passing, build clean, lint clean.

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 25, 2026

🦋 Changeset detected

Latest commit: 9e11716

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

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

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 25, 2026

Coverage Status

coverage: 75.475% (+0.5%) from 74.929% — kanishka0411:fix/expire-stale-lnbits-invoices into cameri:main

Comment thread src/payments-processors/lnbits-payment-processor.ts Outdated
Comment thread src/app/maintenance-worker.ts Outdated
@cameri cameri merged commit b7324a6 into cameri:main Apr 25, 2026
12 of 13 checks passed
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.

[BUG] Endless checking of an unpaid invoice (processor LNBits)

3 participants