Skip to content

ProbabilisticScorer improvements #1399

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
merged 2 commits into from
Apr 2, 2022

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Mar 31, 2022

In ProbabilisticScorer, the channel liquidity balance is reduced whenever a payment fails at the corresponding channel. The payment may still be retried through the channel, however, because the liquidity penalty is capped. Use u64::max_value instead in this situation to avoid retrying over the same path. This effectively makes u64::max_value the penalty for amounts exceeding the upper bound, as well.

Also, penalties tends to be dominated by fees for large payments. To avoid this, add an amount penalty to ProbabilisticScorer with a user configurable multiplier. The multiplier is applied for every 2^20th of the amount weighted by the negative log10 of the channel's success probability for the payment.

TheBlueMatt
TheBlueMatt previously approved these changes Mar 31, 2022
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.

LG either way, but dunno if the extra branch changes anything material - was it just to simplify test changes?

Copy link
Contributor Author

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

LG either way, but dunno if the extra branch changes anything material - was it just to simplify test changes?

See response to your comment which proposes an alternative to limit the extra branch.

@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2022

Codecov Report

Merging #1399 (53f8760) into main (7671ae5) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head 53f8760 differs from pull request most recent head 5b80256. Consider uploading reports for the commit 5b80256 to get more accurate results

@@            Coverage Diff             @@
##             main    #1399      +/-   ##
==========================================
+ Coverage   90.76%   90.83%   +0.06%     
==========================================
  Files          73       73              
  Lines       41195    41476     +281     
  Branches    41195    41476     +281     
==========================================
+ Hits        37392    37676     +284     
+ Misses       3803     3800       -3     
Impacted Files Coverage Δ
lightning/src/routing/scoring.rs 94.23% <100.00%> (+0.19%) ⬆️
lightning/src/ln/functional_tests.rs 97.12% <0.00%> (+0.04%) ⬆️
lightning-persister/src/lib.rs 93.93% <0.00%> (+0.33%) ⬆️
lightning/src/routing/network_graph.rs 89.61% <0.00%> (+0.55%) ⬆️
lightning-background-processor/src/lib.rs 95.35% <0.00%> (+2.25%) ⬆️

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 7671ae5...5b80256. Read the comment docs.

/// provide higher penalties for large payments.
///
/// Default value: false
pub include_amount_penalty: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if we want to make this a switch instead of a second penalty - I think a second penalty more closely lines up with what fees are (a combo of % and absolute fees), which is the property we're going for here - ability to match penalties up to expected/reasonable fees.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as discussed offline. Please take a look at the amount_penalty_multiplier_msat docs. I tried to make them a bit more human understandable. Let me know if I hit the mark or if it can be fine tuned in any way.

@jkczyz jkczyz force-pushed the 2022-03-scoring-tweaks branch from 7817e53 to beecbb3 Compare March 31, 2022 23:47
@jkczyz jkczyz added this to the 0.0.106 milestone Apr 1, 2022
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.

LGTM. I'd say feel free to squash.

@jkczyz jkczyz force-pushed the 2022-03-scoring-tweaks branch from beecbb3 to 53f8760 Compare April 1, 2022 02:37
TheBlueMatt
TheBlueMatt previously approved these changes Apr 1, 2022
@TheBlueMatt
Copy link
Collaborator

LGTM. Feel free to squash.

@jkczyz jkczyz force-pushed the 2022-03-scoring-tweaks branch from 5b80256 to 51e1de9 Compare April 1, 2022 18:40
@jkczyz jkczyz changed the title Avoid retrying over recently failed channels ProbabilisticScorer improvements Apr 1, 2022
TheBlueMatt
TheBlueMatt previously approved these changes Apr 1, 2022
} else if max_liquidity_msat != self.capacity_msat {
// Avoid using the failed channel on retry.
u64::max_value()
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

how likely is this case to ever be hit, that amount_msat is precisely equal to max_liquidity_msat?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we just tried the payment, its possible, the final else here pretty unlikely I'd guess. Maybe for "very round" numbers - 1m sats, 100k sats, etc it could happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, also if the HTLC maximum is some round amount, it may get hit. We should really use the capacity here if known, but currently we do not. I have a commit to do this that was dropped from the original ProbabilisticScorer PR.

jkczyz added 2 commits April 1, 2022 15:52
In ProbabilisticScorer, the channel liquidity balance is reduced
whenever a payment fails at the corresponding channel. The payment may
still be retried through the channel, however, because the liquidity
penalty is capped. Use u64::max_value instead in this situation to avoid
retrying over the same path. This effectively makes u64::max_value the
penalty for amounts exceeding the upper bound, as well.

As an edge case, avoid using u64::max_value on attempts where the amount
is equal to the effective capacity, which may be the HTLC maximum when
the channel capacity is unknown.
The cost of large payments tends to be dominated by the channel fees. To
avoid this, add an amount penalty to ProbabilisticScorer with a user
configurable multiplier. The multiplier is applied for every 2^20th of
the amount weighted by the negative log10 of the channel's success
probability for the payment.
@jkczyz jkczyz force-pushed the 2022-03-scoring-tweaks branch from c8626ca to 5425b2b Compare April 1, 2022 20:55
Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

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

LGTM

@TheBlueMatt TheBlueMatt merged commit af31831 into lightningdevkit:main Apr 2, 2022
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.

4 participants