-
Notifications
You must be signed in to change notification settings - Fork 405
Replace maze of BOLT11 payment utilities with parameter generators #2727
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
Replace maze of BOLT11 payment utilities with parameter generators #2727
Conversation
`lightning-invoice` was historically responsible for actually paying invoices, handling retries and everything. However, that turned out to be buggy and hard to maintain, so the payment logic was eventually moved into `ChannelManager`. However, the old utilites remain. Because our payment logic has a number of tunable parameters and there are different ways to pay a BOLT11 invoice, we ended up with six different methods to pay or probe a BOLT11 invoice, with more requested as various options still were not exposed. Instead, here, we replace all six methods with two simple ones which return the arguments which need to be passed to `ChannelManager`. Those arguments can be further tweaked before passing them on, allowing more flexibility.
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2727 +/- ##
==========================================
+ Coverage 88.80% 89.02% +0.22%
==========================================
Files 113 113
Lines 89170 89871 +701
Branches 89170 89871 +701
==========================================
+ Hits 79188 80009 +821
+ Misses 7729 7596 -133
- Partials 2253 2266 +13
☔ View full report in Codecov by Sentry. |
I think this closes #2390 |
#2390 is about |
Since there's a much simpler way to go about it with `Bolt11Invoice::expires_at`.
cbf5fed
to
22305a9
Compare
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.
ACK
The maze has been successfully navigated!
The latest sets of functions have been clarified, making optimal use of common functions wherever possible.
Additionally, the code is also well-documented.
I have also added a summary of my analysis of this PR, which can potentially help fellow contributors in their review process.
Summary:
Let's break it down function by function:
- Simplifying Invoice Handling:
pay_zero_value_invoice
has been replaced withpayment_parameters_from_zero_amount_invoice
.- Removed
retry
strategy andChannelManager
from params. - Switched to using
params_from_invoice
instead of the convolutedpay_zero_value_invoice_with_id
. - Added a check for a zero-amount invoice, eliminating the need for another function (
pay_zero_value_invoice_with_id
).
- Removed
- Cleaner Invoice Payment Process:
pay_zero_value_invoice_with_id
has been removed.pay_invoice_using_amount
is now replaced withpayment_parameters_from_invoice
.- Instead of paying within this function, the process is sent to a common
params_from_invoice
function, reducing complexity. - The function now returns payment-related values upstream.
- Instead of paying within this function, the process is sent to a common
- Streamlining Probing Functions:
preflight_probe_invoice
andpreflight_probe_zero_value_invoice
have been removed, as ChannelManager now handles the probing previously done here.
- Enhancing Code Structure:
- Removed
expiry_time_from_unix_epoch
function, now usingwith_expiry_time
defined within Payment Parameters.
- Removed
- Testing Improvements:
- Removed
invoice
andzero_value_invoice
helper functions used in testing. Respective invoices are now created in their test functions.
- Removed
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.
Good to wait on @G8XSU's ACK before landing.
lightning-invoice
was historically responsible for actually paying invoices, handling retries and everything. However, that turned out to be buggy and hard to maintain, so the payment logic was eventually moved intoChannelManager
. However, the old utilites remain.Because our payment logic has a number of tunable parameters and there are different ways to pay a BOLT11 invoice, we ended up with six different methods to pay or probe a BOLT11 invoice, with more requested as various options still were not exposed.
Instead, here, we replace all six methods with two simple ones which return the arguments which need to be passed to
ChannelManager
. Those arguments can be further tweaked before passing them on, allowing more flexibility.