Skip to content

Limit amount of hints resulting from filter_channels to 3 #1919

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

Closed

Conversation

cdmoss
Copy link

@cdmoss cdmoss commented Dec 14, 2022

As per #1782, filter_channels will only take 20 channels from the selected channels and shuffles the channel list before returning it.

@cdmoss cdmoss changed the title Limit amount of hints resulting from filter_channels to 20 and shuffles them Limit amount of hints resulting from filter_channels to 3 Dec 14, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2022

Codecov Report

Base: 90.77% // Head: 90.73% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (84c5b5e) compared to base (d4dc05b).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1919      +/-   ##
==========================================
- Coverage   90.77%   90.73%   -0.05%     
==========================================
  Files          94       94              
  Lines       49603    49603              
  Branches    49603    49603              
==========================================
- Hits        45026    45006      -20     
- Misses       4577     4597      +20     
Impacted Files Coverage Δ
lightning-invoice/src/utils.rs 97.76% <ø> (ø)
lightning-net-tokio/src/lib.rs 77.01% <0.00%> (-0.30%) ⬇️
lightning/src/ln/functional_tests.rs 96.93% <0.00%> (-0.23%) ⬇️
lightning/src/chain/channelmonitor.rs 90.80% <0.00%> (-0.20%) ⬇️
lightning/src/ln/channelmanager.rs 86.70% <0.00%> (-0.03%) ⬇️

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

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

LGTM after squash

@TheBlueMatt
Copy link
Collaborator

Please squash commits as described at https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

@cdmoss cdmoss force-pushed the 2022-12-limit-and-shuffle-hints branch from 84c5b5e to d73bb08 Compare December 15, 2022 19:57
@ViktorTigerstrom
Copy link
Contributor

ViktorTigerstrom commented Dec 15, 2022

Great thanks for the contribution!

If you have the possibility to do so, it would great if you add test coverage of this case, as our current test coverage covers all filtering variations that I know of. Have a look at the other tests in the same file you've been updating and see if you can add test coverage. If you'd prefer to not add the test coverage, I can do so in a follow-up instead.

A general discussion point I'd like to point out for everyone:

For phantom invoices, with the change of this PR, the route hints will still be really large if we for example have 3 participating nodes with 3 channels to different counterparties each. Would we like this to only include 3 (or maybe some other number) channels in total for phantom invoices given that we have users that runs a phantom node setup for mobile as well, or are we ok with including more channels for phantom invoices for now (9 in the example I gave)?

@cdmoss
Copy link
Author

cdmoss commented Dec 15, 2022

Great thanks for the contribution!

If you have the possibility to do so, it would great if you add test coverage of this case, as our current test coverage covers all filtering variations that I know of. Have a look at the other tests in the same file you've been updating and see if you can add test coverage. If you'd prefer to not add the test coverage, I can do so in a follow-up instead.

A general discussion point I'd like to point out for everyone:

For phantom invoices, with the change of this PR, the route hints will still be really large if we for example have 3 participating nodes with 3 channels to different counterparties each. Would we like this to only include 3 (or maybe some other number) channels in total for phantom invoices given that we have users that runs a phantom node setup for mobile as well, or are we ok with including more channels for phantom invoices for now (9 in the example I gave)?

My pleasure :). I will be quite busy with school over the next few days, but I will possibly have some time tomorrow or early next week to look into adding the new coverage.

@ViktorTigerstrom
Copy link
Contributor

ViktorTigerstrom commented Dec 15, 2022

My pleasure :). I will be quite busy with school over the next few days, but I will possibly have some time tomorrow or early next week to look into adding the new coverage.

Nice, thanks! Let me know if you'd need any help once you've had time to look into it :).

@TheBlueMatt
Copy link
Collaborator

For phantom invoices, with the change of this PR, the route hints will still be really large if we for example have 3 participating nodes with 3 channels to different counterparties each. Would we like this to only include 3 (or maybe some other number) channels in total for phantom invoices given that we have users that runs a phantom node setup for mobile as well, or are we ok with including more channels for phantom invoices for now (9 in the example I gave)?

Yes, good point, we should really limit to one channel per phantom node.

Note that the current PR actually still randomizes! The ordering is currently controlled by the filtered_channels HashMap. In Rust, HashMaps are randomized for anti-DoS resistance, so in practice the iteration order of a HashMap will always be random (with some exceptions for no-std).

I'm not sure what the "right" answer here is, it probably depends a bit on what we think the intended use-case is - I think, mostly, private nodes simply won't have more than one or two channels to begin with, so it doesn't matter all that much. Given that, we can be lazy and just sort by something dumb, eg return the top two channels by node_id or channel_id or whatever. If we want to do something more clever, we could shuffle by the high bits in duration_since_epoch as a way to get a slowly rotating channel selection.

@TheBlueMatt
Copy link
Collaborator

Any chance you want to pick this back up?

@freddiekrugerrand
Copy link
Contributor

Any chance you want to pick this back up?

If @cdmoss isn't free to resume this PR, I would be interested in picking it up. If I understand it, the outstanding items are:

  1. Add unit test coverage for the change
  2. Add some type of deterministic sorting to the output

Yes, good point, we should really limit to one channel per phantom node.

I don't understand this part.

@ViktorTigerstrom
Copy link
Contributor

I don't understand this part.

In LDK there's support for generating invoices that can be paid to multiple receiving nodes, without making it obvious to the payer that those nodes may be the final destination. This concept is called Phantom payments and you can be read more about it here:
https://lightningdevkit.org/blog/introducing-phantom-node-payments/

These types of invoices are generated through the _create_phantom_invoice function, and what you'd probably like to do is to add an argument to the filter_channels function that specifies how many channels the function should maximally return, and then set that value to 1 in the _create_phantom_invoice function, as well as 3 in the "normal" _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash function :).

@freddiekrugerrand
Copy link
Contributor

Picking this up now, sorry for the delay.

Yes, good point, we should really limit to one channel per phantom node.

Limiting hints for phantom nodes to 1 breaks two of the existing unit tests because they specifically test multi-node cases:

These tests don't really make much sense in a world where phantom nodes only have one hint (other than asserting that the code only selects one hint when multiple would have been eligible). Does it make sense to rather try move this coverage to _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash? Seems like the tests are pretty specific to phantom invoices...

@TheBlueMatt
Copy link
Collaborator

We should maybe consider doing the limiting at the _create_phantom_invoice layer? First walk through all peers and get up to three hints from each via filter_channels, then, if we have more than three across all our nodes, limit to three by picking one from each node until we have three. I think that will make those tests pass.

@TheBlueMatt
Copy link
Collaborator

Closing as abandoned and superseded by #2044.

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.

6 participants