Skip to content

Explicitly reject routes that double-back #2741

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

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

shaavan
Copy link
Member

@shaavan shaavan commented Nov 21, 2023

Resolves #2215

  • If a path within a route passes through the same channelID twice, that shows the path is looped and will be rejected by nodes.
  • Add a check to explicitly reject such payments before trying to send them.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for taking a stab at this!

- If a path within a route passes through the same channelID twice,
  that shows the path is looped and will be rejected by nodes.
- Add a check to explicitly reject such payment before trying to send
  them.
@shaavan
Copy link
Member Author

shaavan commented Nov 22, 2023

Updated from pr2741.01 -> pr2741.02 (diff)
Addressed @tnull suggestion

  • Modified the code to use nested for loops instead of a HashSet. Since the number of routeHops will always be very small (<20 for a path), this approach optimized the space complexity over time.

@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (870a0f1) 88.55% compared to head (a06d158) 88.52%.
Report is 3 commits behind head on main.

Files Patch % Lines
lightning/src/ln/functional_tests.rs 91.30% 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    #2741      +/-   ##
==========================================
- Coverage   88.55%   88.52%   -0.04%     
==========================================
  Files         113      113              
  Lines       89330    89351      +21     
  Branches    89330    89351      +21     
==========================================
- Hits        79110    79097      -13     
- Misses       7849     7877      +28     
- Partials     2371     2377       +6     

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

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Pretty much looks good to me. Could we add some test coverage for it though?

You could add a tiny test case checking that we receive the correct APIError if we try to use a looping route. The setup should be similar to, e.g., fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() in functional_tests.rs.

- Also modify the unwrap_send_err!() macro to handle the
  PathParameterError
@shaavan
Copy link
Member Author

shaavan commented Nov 24, 2023

Updated from pr2741.02 -> pr2741.03 (diff)
Addressed @tnull comments

  • Added test coverage for the added code.
  • Also modified the unwrap_send_error!() macro to handle PaymentPathFailure case.

Thanks, @tnull, for the suggestion and for providing a reference to take inspiration for writing up the test.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

LGTM

@tnull tnull merged commit a0183d7 into lightningdevkit:main Nov 27, 2023
@shaavan shaavan mentioned this pull request Dec 15, 2023
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.

Explicitly reject routes which double back
3 participants