fix: failed payments no longer count towards the daily limit#68
Open
AxelHamburch wants to merge 1 commit into
Open
fix: failed payments no longer count towards the daily limit#68AxelHamburch wants to merge 1 commit into
AxelHamburch wants to merge 1 commit into
Conversation
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>
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.
Problem
In
lnurl_callbackthe hit is marked as spent with the full invoice amount beforepay_invoiceis attempted. When the payment then fails (e.g. the invoice amount exceedstx_limit, sopay_invoiceraises), the amount stays recorded in the hit.On the next tap,
api_scansums all of today's hits — including failed ones — and rejects the card withLNURLW 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
tx_limitbefore marking the hit as spent. A rejected attempt no longer consumes the daily limit. The error message keeps the existingPayment failed - Invoice amount ... too high. Max allowed: ...format.spent_today + amount > daily_limit.pay_invoiceraises. The hit amount is reset to 0 so the failed attempt doesn't count towards the daily limit. The hit staysspent, so the samek1cannot be claimed again.Testing
Reproduced and verified on an LNbits instance with a physical Bolt Card on a PoS terminal:
tx_limit→ rejected with the expected error, card keeps working on the next tap (previously: blocked with "Max daily limit spent.")