Skip to content

Pass EffectiveCapacity through to scorer instead of a u64 #1383

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

TheBlueMatt
Copy link
Collaborator

There is little reason to take the EffectiveCapacity, which has
a bunch of information about the type of channel, and distill it
down to a u64 when scoring channels.

Instead, we here pass the full information we know, in the form of
the original EffectiveCapacity. This does create more branching
in the main router loop, which appears to have a very slight (1-2%)
performance loss, but that may well be within noise.

Much more importantly, this resolves a panic in our log
approximation where we can accidentally call log(0) when the
channel's effective capacity is u64::max_value().

@TheBlueMatt TheBlueMatt added this to the 0.0.106 milestone Mar 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2022

Codecov Report

Merging #1383 (72bc65e) into main (f6fa8e9) will increase coverage by 0.00%.
The diff coverage is 93.22%.

@@           Coverage Diff            @@
##             main    #1383    +/-   ##
========================================
  Coverage   90.81%   90.82%            
========================================
  Files          73       73            
  Lines       41209    41407   +198     
  Branches    41209    41407   +198     
========================================
+ Hits        37424    37607   +183     
- Misses       3785     3800    +15     
Impacted Files Coverage Δ
lightning-invoice/src/payment.rs 92.75% <ø> (ø)
lightning/src/routing/network_graph.rs 89.03% <75.86%> (-0.51%) ⬇️
lightning/src/routing/router.rs 92.42% <80.00%> (-0.04%) ⬇️
lightning/src/routing/scoring.rs 94.20% <97.82%> (-0.10%) ⬇️
lightning/src/ln/functional_tests.rs 97.06% <0.00%> (-0.10%) ⬇️
lightning/src/ln/chanmon_update_fail_tests.rs 98.07% <0.00%> (+0.35%) ⬆️

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 f6fa8e9...72bc65e. Read the comment docs.

There is little reason to take the `EffectiveCapacity`, which has
a bunch of information about the type of channel, and distill it
down to a `u64` when scoring channels.

Instead, we here pass the full information we know, in the form of
the original `EffectiveCapacity`. This does create more branching
in the main router loop, which appears to have a very slight (1-2%)
performance loss, but that may well be within noise.

Much more importantly, this resolves a panic in our log
approximation where we can accidentally call `log(0)` when the
channel's effective capacity is `u64::max_value()`.
@jkczyz
Copy link
Contributor

jkczyz commented Mar 24, 2022

Much more importantly, this resolves a panic in our log approximation where we can accidentally call log(0) when the channel's effective capacity is u64::max_value().

Wouldn't it be quite simpler just to use saturating_add in DirectedChannelLiquidity::penalty_msat when adding 1?

let numerator = (max_liquidity_msat - amount_msat).saturating_add(1);
let denominator = (max_liquidity_msat - min_liquidity_msat).saturating_add(1);

Unknown {
/// An amount which should be considered "already used". Used during routing to keep track
/// of how much we're already considering routing through this channel.
previously_used_msat: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... I was hoping this would be a separate parameter to the scorer since it is relevant for all variants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, good point, let me benchmark that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but its preferrable to tick something off the TODO list while we're at it rather than just fix the narrow case, no?

Not sure exactly how it would ultimately shake out, but I was thinking something along these lines: #1227 (comment). Had a rough start to this as part of some tabled work from #1227 (jkczyz@b88b37e).

Then each scorer could use the in-use amount as they wish. ProbabilisticScorer would just need to subtract it from max_liquidity_msat.

I'd prefer if we make a small fix for 0.0.106 to avoid adding more review to be honest. Also, it somewhat conflicts with some work I pulled out of #1227 but haven't PR'ed: jkczyz@a926913.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it somewhat conflicts with some work I pulled out of #1227 but haven't PR'ed: jkczyz@a926913.

Okay, sounds great! I'll close this and circle back around on the panic. I sent you the patch I'd started to build for this on discord, it looked like a performance win so probably good to incorporate it in your work.

@TheBlueMatt
Copy link
Collaborator Author

Wouldn't it be quite simpler just to use saturating_add in DirectedChannelLiquidity::penalty_msat when adding 1?

Sure, but its preferrable to tick something off the TODO list while we're at it rather than just fix the narrow case, no?

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.

3 participants