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

Limit payment path length based on payment_metadata, custom TLVs, etc. #3026

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

Conversation

valentinewallace
Copy link
Contributor

Currently the maximum payment path length is hardcoded in the router to 19. However, the presence of payment_metadata, custom TLVs, and/or blinded paths may mean that the actual limit is much shorter. Account for these extra onion fields when calculating and setting the maximum path length for use in pathfinding.

Closes #2201.


let num_reserved_bytes = match &route_params.payment_params.payee {
Payee::Blinded { route_hints, .. } => {
let largest_path = route_hints
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: currently I’m evaluating the max path length based on the largest blinded path, i.e. the blinded path that limits us the most. Therefore, if some blinded paths are larger than others, this could unnecessarily limit us in pathfinding. We could set the max path length on a per-blinded-path basis? In practice, ISTM that blinded paths within the same invoice are likely to be of similar sizes to each other.

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2024

Codecov Report

Attention: Patch coverage is 97.91304% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 89.83%. Comparing base (da7a916) to head (6255996).

Files Patch % Lines
lightning/src/routing/router.rs 79.48% 8 Missing ⚠️
lightning/src/ln/max_payment_path_len_tests.rs 99.22% 2 Missing ⚠️
lightning/src/ln/outbound_payment.rs 91.66% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3026      +/-   ##
==========================================
+ Coverage   89.79%   89.83%   +0.03%     
==========================================
  Files         116      117       +1     
  Lines       96466    96909     +443     
  Branches    96466    96909     +443     
==========================================
+ Hits        86619    87055     +436     
- Misses       7290     7301      +11     
+ Partials     2557     2553       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
Copy link
Contributor Author

I found some more edge cases around how get_route counts hops as part of a path, so feel free to hold off on review there.

@valentinewallace valentinewallace force-pushed the 2024-04-limit-path-len branch 2 times, most recently from 8ef1770 to c8fbb96 Compare April 30, 2024 19:21
@valentinewallace
Copy link
Contributor Author

Rebased to (hopefully) fix CI. This should be good for review.

lightning/src/routing/router.rs Outdated Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/outbound_payment.rs Outdated Show resolved Hide resolved
lightning/src/routing/router.rs Outdated Show resolved Hide resolved
@valentinewallace valentinewallace force-pushed the 2024-04-limit-path-len branch 3 times, most recently from 7ee7c37 to 8de126d Compare May 13, 2024 23:08
@valentinewallace
Copy link
Contributor Author

Feedback should be addressed. Also this needs a rebase so let me know when I can do that.

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.

Feel free to squash, IMO.

lightning/src/ln/onion_utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/onion_utils.rs Outdated Show resolved Hide resolved
node_features: NodeFeatures::empty(),
short_channel_id: 42,
channel_features: ChannelFeatures::empty(),
fee_msat: route_params.final_value_msat,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be higher if we have to overpay when routing, so the object could serialize a bit longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some buffer here. I think my buffer is a bit conservative so let me know if it needs tuning.

Will be useful when we reuse this enum to calculate the maximum path length,
to avoid cloning the vecs.
Doable now that we take Vecs by reference in OutboundOnionPayload.
Will be used in the next commit when we make this configurable in
PaymentParameters.
Will be useful when we want to calculate the total size of the payloads without
actually allocating for them.
Will be used so the outbound_payment module can calculate the maximum path
length with knowledge of any custom TLVs or payment metadata present.
Also adds some testing by augmenting existing tests.
So the router knows how long the maximum payment path can be.
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.

Figure out path-length-limiting when routing with metadata/blinded paths
4 participants