Skip to content

Log penalty info in route-success line #1300

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

Conversation

jurvis
Copy link
Contributor

@jurvis jurvis commented Feb 9, 2022

This PR is an attempt at #1233.

My goal is to be able to leverage on the existing log_route! macro to print the penalties for each path found within a route, which meant making the penalty data available somehow in the Route struct.

I think this contribution can be improved by adding test coverage, but am struggling to figure out where to add them. Suggestions welcome!

I'm new to Rust + contributing to open-source, so please feel free to leave feedback! I am also happy to change the implementation if adding a field to Route is not something we want to pursue.

Thanks!

Demo

This is the old output for routes (ran via routing::router::tests::simple_route_test):

INFO   [lightning::routing::router : lightning/src/routing/router.rs, 1538] Got route to 03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b: path 0:
 node_id: 02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337, short_channel_id: 2, fee_msat: 100, cltv_expiry_delta: 65
 node_id: 03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b, short_channel_id: 4, fee_msat: 100, cltv_expiry_delta: 42

New (diff in ****):

INFO   [lightning::routing::router : lightning/src/routing/router.rs, 1538] Got route to 03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b: path 0 **(penalty: 0)**:
 node_id: 02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337, short_channel_id: 2, fee_msat: 100, cltv_expiry_delta: 65
 node_id: 03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b, short_channel_id: 4, fee_msat: 100, cltv_expiry_delta: 42

We make this a tuple to track the paths and their corresponding penalties.

I made this decision over creating a separate `path_penalties` vector so we don't run the risk of having to handle the scenario where `selected_paths.len() != path_penalties.len()`.
To leverage the log_route! macro, we want to add a field to the Route struct.

This commit adds the `path_penalties` field, which will contain the penalties to `paths`.
@jurvis jurvis marked this pull request as draft February 9, 2022 19:33
@codecov-commenter
Copy link

Codecov Report

Merging #1300 (0acc230) into main (d29ae18) will decrease coverage by 0.02%.
The diff coverage is 85.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1300      +/-   ##
==========================================
- Coverage   90.51%   90.48%   -0.03%     
==========================================
  Files          71       71              
  Lines       39012    39025      +13     
==========================================
+ Hits        35310    35313       +3     
- Misses       3702     3712      +10     
Impacted Files Coverage Δ
lightning/src/routing/router.rs 91.69% <75.00%> (-0.11%) ⬇️
lightning-invoice/src/payment.rs 92.69% <100.00%> (-0.07%) ⬇️
lightning/src/ln/functional_tests.rs 97.20% <100.00%> (-0.08%) ⬇️
lightning/src/ln/onion_utils.rs 95.65% <100.00%> (+0.01%) ⬆️
lightning/src/util/macro_logger.rs 85.48% <100.00%> (ø)
lightning-invoice/src/de.rs 81.06% <0.00%> (-0.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d29ae18...0acc230. Read the comment docs.

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.

I can't leave a comment there (thanks GitHub...) but maybe instead of changing the public API a bunch we could try to clean up the output printed at L1319 (presumably by doing a custom debug representation of PathBuildingHop instead of the default one).

@@ -76,6 +76,9 @@ pub struct Route {
///
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
pub payment_params: Option<PaymentParameters>,
/// List of penalties corresponding to the paths in the `paths` vector.
/// This is populated by taking the last [`PathBuildingHop`] of every path found in [`find_route`]
pub path_penalties: Vec<u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, do we care about actually exposing this programmatically? Presumably the user can just call their own scorer immediately after getting the route if they really want this info. I think just logging it may be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @TheBlueMatt, thanks for taking a look! that is a good suggestion -- I'll change my implementation. I will take another stab over the weekend :)

@jurvis
Copy link
Contributor Author

jurvis commented Feb 12, 2022

attempting different implementation, closing.

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.

3 participants