Skip to content

Commit 1b21317

Browse files
committed
Correctly apply penalty bounds on the per-amount penalties
When we attempt to score a channel which has a success probability very low, we may have a log well above our cut-off of two. For the liquidity penalties this works great, we bound it by `NEGATIVE_LOG10_UPPER_BOUND` and `min` the two scores. For the amount liquidity penalty we didn't do any `min`ing at all. This fix is to min the log itself first and then reuse the min'd log in both calculations.
1 parent e7c45d9 commit 1b21317

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lightning/src/routing/scoring.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,14 +1088,16 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
10881088

10891089
/// Computes the liquidity penalty from the penalty multipliers.
10901090
#[inline(always)]
1091-
fn combined_penalty_msat(amount_msat: u64, negative_log10_times_2048: u64,
1091+
fn combined_penalty_msat(amount_msat: u64, mut negative_log10_times_2048: u64,
10921092
liquidity_penalty_multiplier_msat: u64, liquidity_penalty_amount_multiplier_msat: u64,
10931093
) -> u64 {
1094+
negative_log10_times_2048 =
1095+
negative_log10_times_2048.min(NEGATIVE_LOG10_UPPER_BOUND * 2048);
1096+
10941097
let liquidity_penalty_msat = {
10951098
// Upper bound the liquidity penalty to ensure some channel is selected.
10961099
let multiplier_msat = liquidity_penalty_multiplier_msat;
1097-
let max_penalty_msat = multiplier_msat.saturating_mul(NEGATIVE_LOG10_UPPER_BOUND);
1098-
(negative_log10_times_2048.saturating_mul(multiplier_msat) / 2048).min(max_penalty_msat)
1100+
negative_log10_times_2048.saturating_mul(multiplier_msat) / 2048
10991101
};
11001102
let amount_penalty_msat = negative_log10_times_2048
11011103
.saturating_mul(liquidity_penalty_amount_multiplier_msat)

0 commit comments

Comments
 (0)