-
Notifications
You must be signed in to change notification settings - Fork 382
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
Introduce RouteParametersConfig #3342
Conversation
Hey @TheBlueMatt @tnull, A gentle ping! Would love to get your feedback or approach ACK before moving forward with testing and applying a similar approach on the BOLT11 side. Thanks a lot! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3342 +/- ##
==========================================
- Coverage 88.61% 88.58% -0.03%
==========================================
Files 149 149
Lines 116877 116931 +54
Branches 116877 116931 +54
==========================================
+ Hits 103568 103586 +18
- Misses 10802 10833 +31
- Partials 2507 2512 +5 ☔ View full report in Codecov by Sentry. |
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.
LGTM overall.
However I am not the right person to judge if the PR is what the ldk team is looking for.
For instance the following is confusing me :) but I think this is a discussion to be done inside the issue
They also don't really make sense in a BOLT 11 world if we pass a Bolt11Invoice directly to ChannelManager (which we should do now that lightning depends on lightning-invoice).
BTW Nice git history!
P.S: I left some API idea comment in some commit review, idk if they are useful or not. probably they will remove a lot of map(_ {})
code, but I had to write the code to confirm
@@ -9303,7 +9309,7 @@ where | |||
pub fn pay_for_offer( | |||
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>, | |||
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry, | |||
max_total_routing_fee_msat: Option<u64> | |||
manual_routing_params: Option<ManualRoutingParameters> | |||
) -> Result<(), Bolt12SemanticError> { |
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.
OK no needed option here but: what do you think about having the function call like pay_for_offer(offer, OfferParams::default())
where OfferParams
is something like that
struct OfferParams {
quantity: Option<u64>,
amount_msats: Option<u64>,
manual_routing_params: Option<ManualRoutingParameters>,
}
I think is a lot of more verbose in this way, but I also this that this will be a lot of cleaner.
Now I do not think this will fit well in this PR maybe can be a followup one, but with this patter, it is possible to hide future updates to offers (e.g: recurrence or market place feature) without breaking too much the code
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.
I think this is a great improvement! It will help keep the function signature cleaner while remaining maintainable for future parameter increases.
Maybe we can take this in a follow-up. @TheBlueMatt, what do you think?
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.
No strong opinions.
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.
High-level design looks right to me.
@@ -9303,7 +9309,7 @@ where | |||
pub fn pay_for_offer( | |||
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>, | |||
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry, | |||
max_total_routing_fee_msat: Option<u64> | |||
manual_routing_params: Option<ManualRoutingParameters> | |||
) -> Result<(), Bolt12SemanticError> { |
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.
No strong opinions.
Updated from pr3342.02 to pr3342.03 (diff): Changes:
|
lightning/src/ln/outbound_payment.rs
Outdated
// Deprecated: Retained for backward compatibility. | ||
// If set during read, this field overrides `RouteParameters::max_total_routing_fee_msat` | ||
// instead of `RouteParametersOverride::max_total_routing_fee_msat`. | ||
max_total_routing_fee_msat: Option<u64>, |
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.
Ugh, I really prefer to handle this kind of thing at the serialization layer rather than in our logic. It'll be pretty annoying to break out impl_writeable_tlv_based_enum_upgradable!
here, though....I wonder if we shouldn't try to (yet again) expand the featureset of our enum-deser logic. Lets get this PR ready in every other way and then I can play with it, maybe in a followup.
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.
Done! 🚀 Thanks a lot!
Looks like most of my previous comments went unaddressed? Just checking cause I interpreted your comment as you addressing them. |
7cdb03f
to
63b08a4
Compare
Updated from pr3342.03 to pr3342.04 (diff): Changes: Update Role of RouteParamsOverride:
Cleanups:
|
Hey Matt, I’m really sorry for missing your previous comments – not sure how that slipped through! I've gone through everything now and made sure to address them all in the latest update. Thanks so much for your patience! 🌟 |
Okay, I probably spent a bit too long on it, but #3378 should let us drop the legacy fields in |
Updated from pr3342.05 to pr3342.06 (diff): Changes:
|
Lets get a review pass or two on #3378 and see if we want to move forward with it. If we do, we should rebase this on that and do the conversion in |
While it would be very nice to have this in 0.1, we kinda lost track of 3378 and thus I don't think its realistic to get this in in time. IIRC ldk-node wanted it, so we can certainly do an 0.2 not too long after 0.1, but I don't really think that this is worth holding up 0.1 for. |
Discussed offline. Just needed to remove the |
Hmm, that's weird, legacy writes are supposed to be |
Problem was Something like: { let value: Option<$fieldty> = $write($($self)?); value } |
Yep! I believe that's working perfectly. |
Updated from pr3342.09 to pr3342.10 (diff): Changes:
|
LGTM. For the first commit's message, you can remove the "f: " prefix since it isn't a fixup (i.e., won't be squashed). @TheBlueMatt I'm happy to have the fixups squashed if you are. |
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.
One comment on the last commit, but please do squash the fixups and clean up the history, I think this is basically there.
lightning/src/routing/router.rs
Outdated
@@ -943,6 +943,16 @@ impl PaymentParameters { | |||
} | |||
} | |||
|
|||
/// Update the parameters with the configuration provided by user. |
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.
This reads like a comment rather than documentation. Should read something like "Update the parameters with the given configuration". This also needs to mention that we do not apply the max_total_routing_fee_msat
here, which is quite a potential footgun, so honestly I think maybe we should make this pub(crate)
and even maybe call it with_user_config_ignoring_fee_limit
.
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.
Thanks for the pointer! Addressed in pr3342.13
I updated the naming and change the function to pub(crate) to make it explicit that max_total_routing_fee_msat
is not applied here, and prevent potential footgunning.
Also, I added an explicit line of documentation to make it clearer.
Let me know if it looks good now! Thanks!
With the current architecture, Bolt12 payers & builders only allows setting `max_total_routing_fee_msat` as a route parameter. However, it doesn't provide users the flexibility to set other important parameters. This commit introduces a new struct, `RouteParametersConfig`, that optionally allows users to set additional routing parameters. In later commits, this struct will be utilized when paying BOLT12 invoices.
…sConfig` When Bolt12 payers & builders are called, they creates a new `PendingOutboundPayment` entry with relevant values that will be used when the corresponding invoice is received. This update modifies `AwaitingInvoice` & `AwaitingOffer` to include the entire `RouteParametersConfig` struct instead of just `max_total_routing_fee_msat`. This change ensures all manual routing parameters are available when finding payment routes. Decisions & Reasoning: **Introduction of `route_params_config` in `InvoiceReceived`:** This was added for the same reason that `max_total_routing_fee_msat` was originally introduced in PR lightningdevkit#2417. The documentation has been updated to reflect this, based on [this comment](lightningdevkit@d7e2ff6#r1334619765).
This update allows users to call `pay_for_offer`, `pay_for_offer_from_human_readable` and `create_refund_builder` with a set of parameters they wish to manually set for routing the corresponding invoice. By accepting `RouteParametersConfig`, users gain greater control over the routing process.
- This finally allow overriding the {Route, Payment} parameters with the RouteParametersConfig value provided by the user.
Updated from pr3342.12 to pr3342.13 (diff): Changes:
|
amt, | ||
payment_id, | ||
retry, | ||
RouteParametersConfig::default(), |
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.
nit: For stuff like this where rustfmt requires we blow up our code to cover 20 lines we should really create intermediate variables to see if we can avoid it.
Landing as the full diff since @jkczyz's "LGTM" is only $ git diff-tree -U1 d9d73ead1f7fd65342f483d00686ccc845b40c59 78f6ccb5ca06f4f290ee46e2e9b945d47e38de53
diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs
index a6c0cc1ff..f56795cf5 100644
--- a/lightning/src/ln/outbound_payment.rs
+++ b/lightning/src/ln/outbound_payment.rs
@@ -893,3 +893,4 @@ impl OutboundPayments {
let mut route_params = RouteParameters::from_payment_params_and_value(
- PaymentParameters::from_bolt12_invoice(&invoice).with_user_config(params_config), invoice.amount_msats()
+ PaymentParameters::from_bolt12_invoice(&invoice)
+ .with_user_config_ignoring_fee_limit(params_config), invoice.amount_msats()
);
@@ -1068,3 +1069,4 @@ impl OutboundPayments {
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
- let pay_params = PaymentParameters::from_static_invoice(invoice).with_user_config(*route_params_config);
+ let pay_params = PaymentParameters::from_static_invoice(invoice)
+ .with_user_config_ignoring_fee_limit(*route_params_config);
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs
index e68322294..017496f26 100644
--- a/lightning/src/routing/router.rs
+++ b/lightning/src/routing/router.rs
@@ -945,4 +945,9 @@ impl PaymentParameters {
- /// Update the parameters with the configuration provided by user.
- pub fn with_user_config(self, params_config: RouteParametersConfig) -> Self {
+ /// Updates the parameters with the given route parameters configuration.
+ ///
+ /// Note:
+ /// We *do not* apply `max_total_routing_fee_msat` here, as it is unique to each route.
+ /// Instead, we apply only the parameters that are common across multiple route-finding sessions
+ /// for a payment across retries.
+ pub(crate) fn with_user_config_ignoring_fee_limit(self, params_config: RouteParametersConfig) -> Self {
Self { |
Partially addresses #3262
Blocked on #3378