-
Notifications
You must be signed in to change notification settings - Fork 364
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 RouteParametersOverride #3342
base: main
Are you sure you want to change the base?
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 89.61% 89.61% -0.01%
==========================================
Files 127 127
Lines 103533 103569 +36
Branches 103533 103569 +36
==========================================
+ Hits 92785 92811 +26
- Misses 8051 8053 +2
- Partials 2697 2705 +8 ☔ 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.
lightning/src/routing/router.rs
Outdated
@@ -962,6 +980,43 @@ impl PaymentParameters { | |||
} | |||
} | |||
|
|||
/// Information manually provided by the user to route the payment | |||
#[derive(Clone, Copy)] | |||
pub struct ManualRoutingParameters { |
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.
A bit of a weird name, IMO. This object will be the parameters when sending a payment (BOLT 11 or BOLT 12 offer) when the route-finding is automatic, so kinda weird to call it "manual" :). Maybe PaymentRouteFindingParams
or PaymentRouteParams
, I dunno they're all super confusing with RouteParams
and PaymentParams
already existing...I don't have good ideas, but we should come up with something.
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.
How about RouteParameterOverrides
, RouteParametersConfig
, or CustomizedRouteParameters
? Most fields are for overriding PaymentParameters
, but that is a part of RouteParameters
one of which can be overridden, too.
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.
Updated the name to RouteParametersOverride
in pr3342.03 as it sounded to me the most optimum for now.
Thanks, @jkczyz for the suggestion on names!
@TheBlueMatt
Let me know if the name looks good to you! Thanks!
/// Same as [`PaymentParameters::max_path_count`] | ||
pub max_path_count: Option<u8>, | ||
/// Same as [`PaymentParameters::max_channel_saturation_power_of_half`] | ||
pub max_channel_saturation_power_of_half: Option<u8>, |
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.
Why is this an Option
?
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’ve made all the fields optional, so they act as overrides. If left as None
, the values from PaymentParameters
(created using the invoice and default settings) will be used. I’ve also updated the docs to make this clearer for this struct.
Would love to hear your feedback on this API design! Thanks so much!
/// Same as [`RouteParameters::max_total_routing_fee_msat`] | ||
pub max_total_routing_fee_msat: Option<u64>, | ||
/// Same as [`PaymentParameters::max_total_cltv_expiry_delta`] | ||
pub max_total_cltv_expiry_delta: Option<u32>, |
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 probably shouldn't be an Option
, we should define something.
#[derive(Clone, Copy)] | ||
pub struct ManualRoutingParameters { | ||
/// Same as [`RouteParameters::max_total_routing_fee_msat`] | ||
pub 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.
What happens if this is None
, should be described in the docs. I assume it picks a default not allows any fee?
With the current architecture, `pay_for_offer` 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, `RouteParametersOverride`, that optionally allows users to set additional routing parameters. In later commits, this struct will be utilized when paying BOLT12 invoices.
When `pay_for_offer` is called, it creates a new `PendingOutboundPayment` entry with relevant values that will be used when the corresponding invoice is received. This update modifies `AwaitingInvoice` to include the entire `ManualRoutingParameters` struct instead of just `max_total_routing_fee_msat`. This change ensures all manual routing parameters are available when finding payment routes. Decisions & Reasoning: 1. **Retention of `max_total_routing_fee_msat` in `AwaitingInvoice`:** This field is retained to ensure downgrade support. However, it is removed from `InvoiceReceived` since it was never used, thereby helping to clean up the code while still supporting downgrading. 2. **Introduction of `route_params_override` 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` with a set of parameters they wish to manually set for routing the corresponding invoice. By accepting `RouteParametersOverride`, users gain greater control over the routing process.
Updated from pr3342.02 to pr3342.03 (diff): Changes:
|
@@ -962,6 +970,46 @@ impl PaymentParameters { | |||
} | |||
} | |||
|
|||
/// A struct for overriding specific [`RouteParameters`] values created |
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.
Its a bit weird, IMO, to document/name this in relation to RouteParameters
when most users will never even see a RouteParameters
(once we do #3375) and will only ever see this.
}, | ||
(7, InvoiceReceived) => { | ||
(0, payment_hash, required), | ||
(2, retry_strategy, required), | ||
(4, max_total_routing_fee_msat, option), |
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.
Removing an even value will result in failure to decode on upgrade - we will get an unknown even value which is a failure ("its okay to be odd")
// 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.
Looks like most of my previous comments went unaddressed? Just checking cause I interpreted your comment as you addressing them. |
Partially addresses #3262
RouteParametersOverride
that optionally takes the parameter to override for routing params.pay_for_offer
to use it along with the invoice's payment parameter to set route parameters.