-
Notifications
You must be signed in to change notification settings - Fork 2.2k
rpcserver+routerrpc: allow overpayment of fixed-amount invoices #10549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
In this commit, we introduce a new ValidatePayReqAmt helper function in the lnrpc package that consolidates the logic for validating a caller-specified payment amount against a BOLT11 invoice amount. The helper handles three cases: zero-amount invoices (caller must specify an amount), fixed-amount invoices with no caller override (use invoice amount), and fixed-amount invoices with a caller override (allow overpayment, reject underpayment). This helper will be used in the next commit to fix a bug where amt_msat was silently ignored when paying fixed-amount invoices.
Previously, the SendPaymentSync path in rpcserver.go silently ignored the amt_msat field when paying a BOLT11 invoice that already contained a fixed amount, and the SendPaymentV2 path in router_backend.go rejected the request outright with "amount must not be specified when paying a non-zero amount invoice". Both behaviors prevented users from intentionally overpaying an invoice, which is permitted by the BOLT spec. In this commit, we replace the duplicated amount validation logic in both extractPaymentIntent (rpcserver.go) and extractIntentFromSendRequest (router_backend.go) with calls to the new ValidatePayReqAmt helper. When a caller specifies amt_msat alongside a fixed-amount invoice, the payment now proceeds as long as the specified amount is at least the invoice amount. Underpayment is still rejected with a clear error message. Fixes #10541
In this commit, we add an integration test that verifies a payer can overpay a fixed-amount BOLT11 invoice by specifying a larger amt_msat in the SendPaymentV2 request. The test creates a 1000 sat invoice, pays it with 1100 sat (1,100,000 msat), and asserts that both the sender's payment record and the receiver's invoice reflect the overpaid amount.
Summary of ChangesHello @Roasbeef, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a long-standing issue where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant improvement by allowing intentional overpayment of fixed-amount invoices, aligning the behavior of SendPaymentSync and SendPaymentV2 with the BOLT specification. The introduction of the shared ValidatePayReqAmt helper in the lnrpc package is a great refactoring that centralizes validation logic, removes duplication, and ensures consistent behavior across different RPC paths. The changes are well-tested with both unit tests for the new helper and an end-to-end integration test, which gives high confidence in the correctness of the implementation. The code is clean, readable, and adheres to the project's style guide. Overall, this is an excellent contribution that improves correctness and maintainability.
🔴 PR Severity: CRITICAL
🔴 Critical (1 file)
🟠 High (2 files)
🟢 Low (3 files)
AnalysisThis PR is classified as CRITICAL because it modifies Key considerations:
Review focus areas:
To override, add a |
|
Tested. It works. 👍 |
Fixes #10541
Previously, sending a payment with
amt_msatset alongside a fixed-amountBOLT11 invoice did not work as expected. The
SendPaymentSyncpath inrpcserver.gosilently ignored theamt_msatfield and used the invoiceamount, while the
SendPaymentV2path inrouter_backend.gorejected therequest outright with "amount must not be specified when paying a non-zero
amount invoice". Both behaviors prevented users from intentionally overpaying
an invoice, which is permitted by the BOLT spec.
This PR introduces a shared
ValidatePayReqAmthelper in thelnrpcpackagethat consolidates the invoice-amount-vs-caller-amount validation logic. When a
caller specifies
amt_msat(oramt) alongside a fixed-amount invoice, thepayment now proceeds as long as the specified amount is at least the invoice
amount. Underpayment is rejected with a clear error. For zero-amount invoices,
the existing behavior (caller must specify an amount) is preserved.
Both
extractPaymentIntent(legacySendPayment/SendPaymentSync) andextractIntentFromSendRequest(SendPaymentV2) now use this shared helper,eliminating duplicated logic and ensuring consistent behavior across both RPC
paths.
The change includes unit tests for the new helper covering overpayment, exact
payment, underpayment, zero-amount invoices, and sat/msat mutual exclusivity,
as well as an integration test that verifies end-to-end overpayment of a
fixed-amount invoice.