Skip to content

Add logging in route hint filtering #1770

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

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Oct 14, 2022

Knowing why a channel was not included as an invoice route hint can be valuable. Add logging on the decisions made when filtering channels.

@jkczyz jkczyz force-pushed the 2022-10-debug-route-hints branch from e7d17e3 to 2545426 Compare October 14, 2022 16:18
@codecov-commenter
Copy link

codecov-commenter commented Oct 14, 2022

Codecov Report

Base: 90.91% // Head: 90.91% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (7bc5d46) compared to base (a534dcc).
Patch coverage: 97.26% of modified lines in pull request are covered.

❗ Current head 7bc5d46 differs from pull request most recent head b75e111. Consider uploading reports for the commit b75e111 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1770   +/-   ##
=======================================
  Coverage   90.91%   90.91%           
=======================================
  Files          87       87           
  Lines       48048    48078   +30     
  Branches    48048    48078   +30     
=======================================
+ Hits        43681    43711   +30     
  Misses       4367     4367           
Impacted Files Coverage Δ
lightning-invoice/src/utils.rs 95.13% <96.72%> (+0.31%) ⬆️
lightning-invoice/src/payment.rs 89.85% <100.00%> (ø)
lightning/src/util/logger.rs 86.13% <100.00%> (+0.72%) ⬆️
lightning/src/util/macro_logger.rs 86.15% <100.00%> (-0.99%) ⬇️
lightning/src/util/events.rs 38.13% <0.00%> (-0.27%) ⬇️
lightning/src/ln/functional_tests.rs 96.96% <0.00%> (-0.02%) ⬇️
lightning-net-tokio/src/lib.rs 77.03% <0.00%> (+0.30%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Looks good and is definitely helpful :)! Just leaving some suggestions for clarifications for phantom invoice route hints filtering.

continue;
}

if channel.is_public {
// If any public channel exists, return no hints and let the sender
// look at the public channels instead.
log_debug!(logger, "Not including invoice route hints on account of public channel {}",
Copy link
Contributor

Choose a reason for hiding this comment

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

This wording will be pretty confusing for phantom invoices as well. Say a phantom invoice is generated using 3 participating nodes, where only one of the nodes have public channels, but the other 2 have only private channels. That invoice will include invoice route hints for the channels of the 2 participating nodes with private channels only, yet log this message due to the 3rd participating node with public channel(s), hence incorrectly indicating that no invoice route hints were included.

Also note that phantom invoices will include invoice route hints for every participating node even if all of them have public channels. Phantom hops with the node id for every participating node will be included in the invoice route hints due to:

route_hints.push(RouteHint(vec![]))

Perhaps we could phrase this sentence as something like:
"Non of the considered channels are included in the invoice route hints on account of public channel {}."

Not sure what the best way to phrase this is though :)!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tweaked the wording. Should be clearer now with the additional logging, too.

Comment on lines 467 to 521
let has_enough_inbound_capacity = channel.inbound_capacity_msat >= min_inbound_capacity;
let include_channel = !min_capacity_channel_exists || has_enough_inbound_capacity;
if !include_channel {
log_debug!(logger, "Ignoring channel {} without enough capacity for invoice route hints",
log_bytes!(channel.channel_id));
}
include_channel
Copy link
Contributor

Choose a reason for hiding this comment

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

This will clash a little with the cleanup in #1769 :). I have no preference for which version we go with, but could be worth considering by either version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on #1769 now though that may need some changes to the filtering logic still.

@jkczyz jkczyz added this to the 0.0.112 milestone Oct 17, 2022
@jkczyz jkczyz force-pushed the 2022-10-debug-route-hints branch from 2545426 to 7bc5d46 Compare October 18, 2022 22:21
@TheBlueMatt
Copy link
Collaborator

Feel free to squash, basically LGTM but the super verbose channel-inclusion-exclusion stuff may make more sense as TRACE, or at least the why-was-it-excluded ones.

@jkczyz
Copy link
Contributor Author

jkczyz commented Oct 20, 2022

Feel free to squash, basically LGTM but the super verbose channel-inclusion-exclusion stuff may make more sense as TRACE, or at least the why-was-it-excluded ones.

Hmm... seems like why a channel was excluded is more important than which channels were included given the latter can be gleaned from the invoice? I'm fine with making everything log_trace, if you'd like.

And anything logged outside filter_channels isn't all that important without having the logging in filter_channels.

@jkczyz jkczyz force-pushed the 2022-10-debug-route-hints branch from 7bc5d46 to 33a5b89 Compare October 20, 2022 03:35
@jkczyz
Copy link
Contributor Author

jkczyz commented Oct 20, 2022

Squashed and changed all logging to log_trace for now.

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

LGTM, leaving one suggestion that's just a nice to have!

match filtered_channels.entry(channel.counterparty.node_id) {
hash_map::Entry::Occupied(mut entry) => {
let current_max_capacity = entry.get().inbound_capacity_msat;
if channel.inbound_capacity_msat < current_max_capacity {
continue;
}
log_trace!(logger, "Preferring channel {} ({} msats) over {} ({} msats) for invoice route hints",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also be worth mentioning the counterparty node id for the channel here, due to the filtering only including 1 channel per counterparty node.

}

match filtered_channels.entry(channel.counterparty.node_id) {
hash_map::Entry::Occupied(mut entry) => {
let current_max_capacity = entry.get().inbound_capacity_msat;
if channel.inbound_capacity_msat < current_max_capacity {
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom Oct 20, 2022

Choose a reason for hiding this comment

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

Actually sorry, we should probably log here that the channel is ignored, no?

@TheBlueMatt
Copy link
Collaborator

If it's alright with Viktor, feel free to keep this one squashed so we can land it ASAP.

@ViktorTigerstrom
Copy link
Contributor

That's ok for me @TheBlueMatt! The new changes looks good. They could possibly be dryed up a little instead of being repeated twice, but then again being this explicit makes it easier to read, so the current version is fine for me:). LGTM once squashed.

Knowing why a channel was not included as an invoice route hint can be
valuable. Add logging on the decisions made when filtering channels.
@jkczyz jkczyz force-pushed the 2022-10-debug-route-hints branch from b75e111 to 90c9763 Compare October 20, 2022 20:18
@@ -353,6 +375,8 @@ where
if let Some(amt) = amt_msat {
invoice = invoice.amount_milli_satoshis(amt);
}

let route_hints = filter_channels(channels, amt_msat, &logger);
Copy link
Contributor

Choose a reason for hiding this comment

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

Some changes in this method seem unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need the filter_channels logging to come after the logging above, the latter of which needs payment_hash.

@valentinewallace valentinewallace merged commit ad82c9e into lightningdevkit:main Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants