Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shaavan
Copy link
Contributor

@shaavan shaavan commented Sep 26, 2024

Partially addresses #3262

  • Introduce a new struct RouteParametersOverride that optionally takes the parameter to override for routing params.
  • Pass it to pay_for_offer to use it along with the invoice's payment parameter to set route parameters.

@shaavan
Copy link
Contributor Author

shaavan commented Sep 26, 2024

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!

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 82.14286% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.61%. Comparing base (ad19d93) to head (a608b55).

Files with missing lines Patch % Lines
lightning/src/ln/outbound_payment.rs 82.14% 3 Missing and 2 partials ⚠️
lightning/src/routing/router.rs 85.00% 0 Missing and 3 partials ⚠️
lightning/src/ln/channelmanager.rs 75.00% 0 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a 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

lightning/src/routing/router.rs Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Show resolved Hide resolved
@@ -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> {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Collaborator

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/ln/outbound_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Show resolved Hide resolved
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a 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> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No strong opinions.

@@ -962,6 +980,43 @@ impl PaymentParameters {
}
}

/// Information manually provided by the user to route the payment
#[derive(Clone, Copy)]
pub struct ManualRoutingParameters {
Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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>,
Copy link
Collaborator

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?

Copy link
Contributor Author

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>,
Copy link
Collaborator

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>,
Copy link
Collaborator

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?

lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
@shaavan
Copy link
Contributor Author

shaavan commented Oct 13, 2024

Updated from pr3342.01 to pr3342.02 (diff):

Changes:

  1. Rebase on main

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.
@shaavan
Copy link
Contributor Author

shaavan commented Oct 13, 2024

Updated from pr3342.02 to pr3342.03 (diff):
Addressed @vincenzopalazzo, @jkczyz, @TheBlueMatt comments

Changes:

  1. Renamed ManualRoutingParameters -> RouteParametersOverride
  2. Reintroduce the max_total_routing_fee_msat in AwaitingInvoice to support downgrading.
  3. Update API, so that the PaymentParameters are created using the Overrides, and then the RouteParameters are created using it.

@shaavan shaavan changed the title Introduce ManualRoutingParameters Introduce RouteParametersOverride Oct 14, 2024
@@ -962,6 +970,46 @@ impl PaymentParameters {
}
}

/// A struct for overriding specific [`RouteParameters`] values created
Copy link
Collaborator

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),
Copy link
Collaborator

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")

Comment on lines +64 to 67
// 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>,
Copy link
Collaborator

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.

@TheBlueMatt
Copy link
Collaborator

Looks like most of my previous comments went unaddressed? Just checking cause I interpreted your comment as you addressing them.

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.

4 participants