Skip to content

Correct allowance budget checks for WebLN payments - #3586

Draft
reneaaron wants to merge 1 commit into
masterfrom
fix/allowance-msat-bypass
Draft

Correct allowance budget checks for WebLN payments#3586
reneaaron wants to merge 1 commit into
masterfrom
fix/allowance-msat-bypass

Conversation

@reneaaron

Copy link
Copy Markdown
Member

Describe the changes you have made in this PR

The invoice amount used for the per-host budget check was read from the decoded satoshis field. bolt11 only populates that field for whole-satoshi amounts, so an invoice with millisatoshi precision (e.g. 1000.5 sat) was compared against the budget as 0.

  • adds getPaymentRequestAmountSats() to src/common/utils/paymentRequest.ts, which falls back to ceil(millisatoshis / 1000) and returns null when the invoice has no amount
  • uses it in checkAllowance, and for the total_amt reported by the lnbits, lndhub and galoy connectors, which derived the amount the same way
  • also checks allowance.enabled and enabledFor before paying from a budget, matching what enable / isEnabled already do
  • amountless invoices now open the confirm prompt instead of being checked against the budget

Behaviour change worth noting

Allowances created before enabledFor existed may not have it set. Those now fall back to the confirm prompt rather than paying automatically. Happy to add a migration that backfills enabledFor: ["webln"] on existing enabled allowances if we'd rather avoid that.

Tests

  • src/common/utils/__tests__/paymentRequest.test.ts — amount derivation
  • src/extension/background-script/actions/webln/__tests__/sendPaymentOrPrompt.test.ts — prompt vs. auto-pay for whole, sub-satoshi and amountless amounts, plus disabled / non-webln allowances

yarn lint, yarn tsc:compile and yarn test:unit all pass (180 passed, 2 pre-existing skips).

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.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 698d10bb-d4b6-455e-ade4-f76e40a7f5cd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/allowance-msat-bypass

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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