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
Implement custom debug for PathBuildingHop #1318
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
lightning/src/routing/router.rs
Outdated
#[derive(Clone, Debug)] | ||
struct PathBuildingHop<'a> { | ||
#[derive(Clone)] | ||
pub struct PathBuildingHop<'a> { |
There was a problem hiding this comment.
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.
lightning/src/routing/router.rs
Outdated
@@ -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())?; |
There was a problem hiding this comment.
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.
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.
Yea, not a fan of that, if we want to improve the logging I think we should just add a util function in |
lightning/src/routing/router.rs
Outdated
@@ -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())?; |
There was a problem hiding this comment.
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.
@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
Matt: I'm not entirely sure what to explicitly name |
Oh, I meant one print of Otherwise LGTM. |
@TheBlueMatt oh 😆 I'll change it! |
8268719
to
1ce2b92
Compare
Oops, sorry, no, I think we need all three - |
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
1ce2b92
to
a3c2dfd
Compare
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
):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:There is an opportunity for improvement here by adding a macro to
macro_logger
that does a clean Display ofPaymentPath
, but that will mean having to exposing fields inPathBuildingHop
andPaymentPath
to be public, which I am not sure we want.Any thoughts on this will be appreciated!