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

Allow to set manual node penalties #1592

Merged
merged 1 commit into from Jul 8, 2022

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Jul 4, 2022

A user might want to explicitly penalize or prioritize a particular node. We now allow them to do so by specifying a manual penalty override for a given node that is then returned by the scorer.

This is a simple generalization of/follow-up to the approach taken in #1550.

Closes #1239

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.

Sure, LGTM.

dunxen
dunxen previously approved these changes Jul 4, 2022
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

ACK 7238559

@TheBlueMatt
Copy link
Collaborator

Feel free to squash the test fix commit.

@tnull
Copy link
Contributor Author

tnull commented Jul 5, 2022

Squashed.

A user might want to explicitly penalize or prioritize a particular
node. We now allow them to do so by specifying a manual penalty
override for a given node that is then returned by the scorer.
@codecov-commenter
Copy link

Codecov Report

Merging #1592 (7238559) into main (f3d5b94) will decrease coverage by 0.05%.
The diff coverage is 94.11%.

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

@@            Coverage Diff             @@
##             main    #1592      +/-   ##
==========================================
- Coverage   91.07%   91.02%   -0.06%     
==========================================
  Files          80       80              
  Lines       44128    44136       +8     
  Branches    44128    44136       +8     
==========================================
- Hits        40190    40175      -15     
- Misses       3938     3961      +23     
Impacted Files Coverage Δ
lightning/src/routing/scoring.rs 96.81% <90.90%> (+0.01%) ⬆️
lightning/src/routing/router.rs 92.63% <100.00%> (+0.01%) ⬆️
lightning/src/ln/payment_tests.rs 98.88% <0.00%> (-0.38%) ⬇️
lightning/src/ln/functional_tests.rs 96.80% <0.00%> (-0.32%) ⬇️

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 f3d5b94...1ddc6f1. Read the comment docs.

@@ -713,8 +725,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
fn channel_penalty_msat(
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
) -> u64 {
if self.params.banned_nodes.contains(source) || self.params.banned_nodes.contains(target) {
return u64::max_value();
if let Some(penalty) = self.params.manual_node_penalties.get(target) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh, I need to stop reviewing pre-coffee, sorry, this should probably look up the source, not the target. I believe both are correct, but in general the routing happens destination -> sender so if we check the source when getting the channel penalty we'll penalize the path earlier in the routing process. Its a pretty minor difference, but still.

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 see your point that a penalty for the source would be considered a bit earlier. However, I chose the target here since it generally seems more in line with the behavior I would expect, and in particular it allows us to penalize/prefer specific single-hop paths. This could come handy when a user would like to use this mechanism to always choose a particular channel when routing to a neighbor node.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it allows us to penalize/prefer specific single-hop paths. his could come handy when a user would like to use this mechanism to always choose a particular channel when routing to a neighbor node.

Wait, can it? If you're paying a given peer, this API doesn't let you pick a channel to that peer, you can punish that peer, but I'm not sure what that does?

Copy link
Contributor Author

@tnull tnull Jul 5, 2022

Choose a reason for hiding this comment

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

Wait, can it? If you're paying a given peer, this API doesn't let you pick a channel to that peer, you can punish that peer, but I'm not sure what that does?

Well I assume when you have multiple channels open to different peers you can set a low/high penalty to prefer/avoid a specific one over the others for example? I'd think this could even get used for simple balancing purposes, i.e., set higher penalties the more a channel is imbalanced. A nice side-effect in this case would be that you could always still fall back on a penalized peer, as long as you not set the penalty outright to u64::max_value().

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, but I don't see how this accomplishes what you're saying - the penalties here are on nodes, not channels, so you can't balance between different channels you have with the same peer. As for across peers, we'll basically always take the direct path.

Are you suggesting users could use this to penalize the direct path enough that we'd prefer to take an indirect one? I suppose you'd be right there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this gives us the possibility to essentially prioritize first hops. I agree that a more fine-grained prioritization on a per-channel basis could be an improvement, but I think this can be a good first step.

@TheBlueMatt TheBlueMatt merged commit ad2e92a into lightningdevkit:main Jul 8, 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.

Manual node +channel prioritization
5 participants