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

Implement custom debug for PathBuildingHop #1318

Conversation

jurvis
Copy link
Contributor

@jurvis jurvis commented Feb 18, 2022

Re-opened of #1300
This PR is an attempt at #1233.

The goal here is to clean up the existing output for PathBuildingHop, and surface only the properties we care about.

Demo

This is the new output for PathBuildingHop (ran via routing::router::tests::simple_route_test):

Found a path back to us from the target with 2 hops contributing up to 100 msat: 
[(PathBuildingHop: node_id: NodeId(02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337), short_channel_id: 2, fee_msat: 100, path_penalty_msat: 0, path_htlc_minimum_msat: 4294967295, cltv_expiry_delta: 83, [8]), (PathBuildingHop: node_id: NodeId(03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b), short_channel_id: 4, fee_msat: 100, path_penalty_msat: 0, path_htlc_minimum_msat: 0, cltv_expiry_delta: 65, [32])]

Some Questions

I am somewhat dissatisfied with the current implementation because the print-out just doesn't seem very ergonomic. Ideally, we'll be able to have the print-out be something closer to what we have for logging routes. Where instead of printing out the Vec, we'll be able to show:

Found a path back to us from the target with 2 hops contributing up to 100 msat: 
  node_id: 02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337, short_channel_id: 2, fee_msat: 100, path_penalty_msat: 0, path_htlc_minimum_msat: 4294967295, cltv_expiry_delta: 8
  node_id: 03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b, short_channel_id: 4, fee_msat: 100, path_penalty_msat: 0, path_htlc_minimum_msat: 0, cltv_expiry_delta: 65

There is an opportunity for improvement here by adding a macro to macro_logger that does a clean Display of PaymentPath, but that will mean having to exposing fields in PathBuildingHop and PaymentPath to be public, which I am not sure we want.

Any thoughts on this will be appreciated!

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #1318 (e73b8a2) into main (b8e9e8b) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e73b8a2 differs from pull request most recent head 1ce2b92. Consider uploading reports for the commit 1ce2b92 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1318      +/-   ##
==========================================
- Coverage   90.50%   90.49%   -0.01%     
==========================================
  Files          71       72       +1     
  Lines       39042    39631     +589     
==========================================
+ Hits        35336    35866     +530     
- Misses       3706     3765      +59     
Impacted Files Coverage Δ
lightning/src/routing/router.rs 91.96% <100.00%> (+0.17%) ⬆️
lightning/src/chain/keysinterface.rs 93.58% <0.00%> (-2.29%) ⬇️
lightning/src/util/scid_utils.rs 98.37% <0.00%> (-1.63%) ⬇️
lightning/src/util/config.rs 46.80% <0.00%> (-1.02%) ⬇️
lightning/src/routing/network_graph.rs 89.52% <0.00%> (-0.46%) ⬇️
lightning/src/ln/onion_utils.rs 95.33% <0.00%> (-0.31%) ⬇️
lightning/src/ln/functional_tests.rs 97.05% <0.00%> (-0.18%) ⬇️
lightning/src/ln/peer_channel_encryptor.rs 94.98% <0.00%> (-0.16%) ⬇️
lightning/src/ln/channel.rs 89.24% <0.00%> (-0.08%) ⬇️
lightning/src/ln/msgs.rs 85.84% <0.00%> (-0.05%) ⬇️
... and 10 more

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 b8e9e8b...1ce2b92. Read the comment docs.

@jkczyz jkczyz self-requested a review February 18, 2022 16:35
#[derive(Clone, Debug)]
struct PathBuildingHop<'a> {
#[derive(Clone)]
pub struct PathBuildingHop<'a> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dont think this needs to be pub, its only used internally in the routing.

@@ -463,6 +463,13 @@ struct PathBuildingHop<'a> {
value_contribution_msat: u64,
}

impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "PathBuildingHop: node_id: {:?}, short_channel_id: {}, fee_msat: {}, path_penalty_msat: {}, path_htlc_minimum_msat: {}, cltv_expiry_delta: {}", self.node_id, self.candidate.short_channel_id(), self.fee_msat, self.path_penalty_msat, self.path_htlc_minimum_msat, self.candidate.cltv_expiry_delta())?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of fee_msat, maybe more informative to use next_hops_fee_msat, hop_use_fee_msat and total_fee_msat - {next_hops,hop_use]_fee_msat.

nit: tabs, not spaces, and maybe put a line break after the format string so the arguments are on the next line.

@TheBlueMatt
Copy link
Collaborator

I am somewhat dissatisfied with the current implementation because the print-out just doesn't seem very ergonomic. Ideally, we'll be able to have the print-out be something closer to what we have for logging routes.

Yea, I don't disagree, though I'm not sure how much its worth going the complexification route here, kinda up to you. This is much better than it was already.

There is an opportunity for improvement here by adding a macro to macro_logger that does a clean Display of PaymentPath, but that will mean having to exposing fields in PathBuildingHop and PaymentPath to be public, which I am not sure we want.

Yea, not a fan of that, if we want to improve the logging I think we should just add a util function in router.rs which does the printing given a list of PathBuildingHops, not do it via Debug or whatever.

@@ -463,6 +463,13 @@ struct PathBuildingHop<'a> {
value_contribution_msat: u64,
}

impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "PathBuildingHop: node_id: {:?}, short_channel_id: {}, fee_msat: {}, path_penalty_msat: {}, path_htlc_minimum_msat: {}, cltv_expiry_delta: {}", self.node_id, self.candidate.short_channel_id(), self.fee_msat, self.path_penalty_msat, self.path_htlc_minimum_msat, self.candidate.cltv_expiry_delta())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use Formatter methods as shown here: https://doc.rust-lang.org/std/fmt/struct.DebugStruct.html#examples

That way pretty-printing is honored if the caller specifies it.

@jurvis
Copy link
Contributor Author

jurvis commented Feb 23, 2022

@jkczyz @TheBlueMatt thanks for taking the time to review! I made some changes based on your feedback. I improved the print-out to be prettier, now it looks like that (thanks for that tip on debug_struct, Jeff!):

TRACE  [lightning::routing::router : lightning/src/routing/router.rs, 1318] Found a path back to us from the target with 2 hops contributing up to 100 msat: 
 [
    PathBuildingHop {
        node_id: NodeId(02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337),
        short_channel_id: 2,
        next_hops_fee_msat: 100,
        hop_use_fee_msat: 0,
        total_fee_msat - next_hops_fee_msat: 0,
        total_fee_msat - hop_use_fee_msat: 100,
        path_penalty_msat: 0,
        path_htlc_minimum_msat: 4294967295,
        cltv_expiry_delta: 83,
    },
    PathBuildingHop {
        node_id: NodeId(03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b),
        short_channel_id: 4,
        next_hops_fee_msat: 0,
        hop_use_fee_msat: 0,
        total_fee_msat - next_hops_fee_msat: 100,
        total_fee_msat - hop_use_fee_msat: 100,
        path_penalty_msat: 0,
        path_htlc_minimum_msat: 0,
        cltv_expiry_delta: 65,
    },
]

Matt: I'm not entirely sure what to explicitly name total_fee_msat - [next_hops, hop_use]_fee_msat, so I just left the variables there. Let me know if you have something else in mind.

@TheBlueMatt
Copy link
Collaborator

Matt: I'm not entirely sure what to explicitly name total_fee_msat - [next_hops, hop_use]_fee_msat, so I just left the variables there. Let me know if you have something else in mind.

Oh, I meant one print of total_fee_msat less both the next_hops and hop_use fees. Seems strange to duplicate it.

Otherwise LGTM.

@jurvis
Copy link
Contributor Author

jurvis commented Feb 23, 2022

@TheBlueMatt oh 😆 I'll change it!

@jurvis jurvis force-pushed the jurvis/2022-02-log-router-penalty-data-4 branch from 8268719 to 1ce2b92 Compare February 23, 2022 18:13
@jurvis jurvis marked this pull request as ready for review February 23, 2022 18:13
@TheBlueMatt
Copy link
Collaborator

Oops, sorry, no, I think we need all three - next_hops_fee_msat, hop_use_fee_msat and total_fee_msat - {next_hops,hop_use]_fee_msat.

Add other fields to log for PathBuildingHop

Use DebugStruct to print PathBuildingHop

Fix PathBuildingHop visibility

Add more useful fee print-outs

Remove Features<NodeContext> from hop print-out

Remove logging fields we don’t need

Add fields to log back to PathBuildingHop
@jurvis jurvis force-pushed the jurvis/2022-02-log-router-penalty-data-4 branch from 1ce2b92 to a3c2dfd Compare February 24, 2022 01:51
@jurvis jurvis requested a review from jkczyz February 24, 2022 16:39
@TheBlueMatt TheBlueMatt merged commit 4b77ce1 into lightningdevkit:main Feb 24, 2022
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.

None yet

4 participants