Skip to content

Commit c4947ac

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 86976e0 commit c4947ac

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lightning/src/routing/scoring.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,15 +1123,15 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
11231123

11241124
/// Computes the liquidity penalty from the penalty multipliers.
11251125
#[inline(always)]
1126-
fn combined_penalty_msat(amount_msat: u64, negative_log10_times_2048: u64,
1126+
fn combined_penalty_msat(amount_msat: u64, mut negative_log10_times_2048: u64,
11271127
liquidity_penalty_multiplier_msat: u64, liquidity_penalty_amount_multiplier_msat: u64,
11281128
) -> u64 {
1129-
let liquidity_penalty_msat = {
1130-
// Upper bound the liquidity penalty to ensure some channel is selected.
1131-
let multiplier_msat = liquidity_penalty_multiplier_msat;
1132-
let max_penalty_msat = multiplier_msat.saturating_mul(NEGATIVE_LOG10_UPPER_BOUND);
1133-
(negative_log10_times_2048.saturating_mul(multiplier_msat) / 2048).min(max_penalty_msat)
1134-
};
1129+
negative_log10_times_2048 =
1130+
negative_log10_times_2048.min(NEGATIVE_LOG10_UPPER_BOUND * 2048);
1131+
1132+
// Upper bound the liquidity penalty to ensure some channel is selected.
1133+
let liquidity_penalty_msat = negative_log10_times_2048
1134+
.saturating_mul(liquidity_penalty_multiplier_msat) / 2048;
11351135
let amount_penalty_msat = negative_log10_times_2048
11361136
.saturating_mul(liquidity_penalty_amount_multiplier_msat)
11371137
.saturating_mul(amount_msat) / 2048 / AMOUNT_PENALTY_DIVISOR;

0 commit comments

Comments
 (0)