Correct allowance budget checks for WebLN payments - #3586
Draft
reneaaron wants to merge 1 commit into
Draft
Conversation
The invoice amount was read from the decoded `satoshis` field, which bolt11 only populates for whole-satoshi amounts, so an invoice with millisatoshi precision was treated as 0 when compared against a host's remaining budget. Derive the amount from millisatoshis instead, via a shared helper, and apply the same derivation to the total_amt reported by the lnbits, lndhub and galoy connectors. Also check that an allowance is enabled and scoped to webln before paying from it, matching what enable and isEnabled already do. Amountless invoices now open the confirm prompt rather than being checked against the budget.
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Describe the changes you have made in this PR
The invoice amount used for the per-host budget check was read from the decoded
satoshisfield.bolt11only populates that field for whole-satoshi amounts, so an invoice with millisatoshi precision (e.g. 1000.5 sat) was compared against the budget as0.getPaymentRequestAmountSats()tosrc/common/utils/paymentRequest.ts, which falls back toceil(millisatoshis / 1000)and returnsnullwhen the invoice has no amountcheckAllowance, and for thetotal_amtreported by the lnbits, lndhub and galoy connectors, which derived the amount the same wayallowance.enabledandenabledForbefore paying from a budget, matching whatenable/isEnabledalready doBehaviour change worth noting
Allowances created before
enabledForexisted may not have it set. Those now fall back to the confirm prompt rather than paying automatically. Happy to add a migration that backfillsenabledFor: ["webln"]on existing enabled allowances if we'd rather avoid that.Tests
src/common/utils/__tests__/paymentRequest.test.ts— amount derivationsrc/extension/background-script/actions/webln/__tests__/sendPaymentOrPrompt.test.ts— prompt vs. auto-pay for whole, sub-satoshi and amountless amounts, plus disabled / non-webln allowancesyarn lint,yarn tsc:compileandyarn test:unitall pass (180 passed, 2 pre-existing skips).