Skip to content

Record the total amount when paying an offer with a quantity - #1202

Open
jkczyz wants to merge 1 commit into
lightningdevkit:mainfrom
jkczyz:2026-10-bolt12-quantity-amount
Open

jkczyz wants to merge 1 commit into
lightningdevkit:mainfrom
jkczyz:2026-10-bolt12-quantity-amount

Conversation

@jkczyz

@jkczyz jkczyz commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #1200.

When Bolt12Payment::send is given a quantity, the invoice request amount is the offer amount multiplied by that quantity, and that total is what the node pays. The payment record only stored the per-item offer amount, and the PaymentSent handler never corrects it, so PaymentDetails::amount_msat understated multi-item payments.

This records the total instead (pending and failed records, plus the log line), rejects quantities whose total would overflow with Error::InvalidAmount, and adds an integration test paying for two items of an offer.

🤖 Generated with Claude Code

@ldk-reviews-bot

ldk-reviews-bot commented Oct 22, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull October 22, 2026 22:25
When `Bolt12Payment::send` is given a quantity, the invoice request
amount is the offer amount multiplied by that quantity, and that total
is what the node ends up paying. The payment record, however, stored
only the per-item offer amount, and nothing later corrected it, so
`PaymentDetails::amount_msat` understated multi-item payments.

Record the total instead, in both the pending and failed records as
well as the log line, and reject quantities whose total would overflow.
Add an integration test paying for two items of an offer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jkczyz
jkczyz force-pushed the 2026-10-bolt12-quantity-amount branch from 088e70e to f8f858c Compare October 22, 2026 22:29
Comment thread src/payment/bolt12.rs
Comment on lines +325 to +326
Some(quantity) => {
offer_amount_msat.checked_mul(quantity).ok_or(Error::InvalidAmount)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The other amount/offer checks in send() log before returning, but this one fails silently, and before this change, an overflow got logged via the LDK error path. Could we log here too?

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.

Record the total amount when paying a BOLT 12 offer with a quantity

3 participants