Skip to content

fix: failed payments no longer count towards the daily limit#68

Open
AxelHamburch wants to merge 1 commit into
lnbits:mainfrom
AxelHamburch:fix/daily-limit-failed-payments
Open

fix: failed payments no longer count towards the daily limit#68
AxelHamburch wants to merge 1 commit into
lnbits:mainfrom
AxelHamburch:fix/daily-limit-failed-payments

Conversation

@AxelHamburch

Copy link
Copy Markdown

Problem

In lnurl_callback the hit is marked as spent with the full invoice amount before pay_invoice is attempted. When the payment then fails (e.g. the invoice amount exceeds tx_limit, so pay_invoice raises), the amount stays recorded in the hit.

On the next tap, api_scan sums all of today's hits — including failed ones — and rejects the card with LNURLW error: Max daily limit spent. even though no payment ever happened. A single over-limit attempt can lock the card for the rest of the day.

Changes

  • Validate the invoice amount against tx_limit before marking the hit as spent. A rejected attempt no longer consumes the daily limit. The error message keeps the existing Payment failed - Invoice amount ... too high. Max allowed: ... format.
  • Enforce the daily limit in the callback. The scan-time check runs before the amount is known, so a single payment could previously exceed the daily limit. The callback now checks spent_today + amount > daily_limit.
  • Roll back the amount when pay_invoice raises. The hit amount is reset to 0 so the failed attempt doesn't count towards the daily limit. The hit stays spent, so the same k1 cannot be claimed again.

Testing

Reproduced and verified on an LNbits instance with a physical Bolt Card on a PoS terminal:

  • Invoice above tx_limit → rejected with the expected error, card keeps working on the next tap (previously: blocked with "Max daily limit spent.")
  • Invoice within limits → payment succeeds as before

The hit amount was written via spend_hit before pay_invoice ran, so a
rejected payment (e.g. invoice above tx_limit) still consumed the daily
limit and subsequent taps were blocked with "Max daily limit spent."

- validate invoice amount against tx_limit before marking the hit spent
- check the daily limit in lnurl_callback (scan-time check happens
  before the amount is known, so a single payment could exceed it)
- zero the hit amount when pay_invoice raises; the hit stays spent so
  the same k1 cannot be claimed again

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant