mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
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.
This commit is contained in:
parent
86976e0003
commit
c4947acaec
1 changed files with 7 additions and 7 deletions
|
@ -1123,15 +1123,15 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
|
|||
|
||||
/// Computes the liquidity penalty from the penalty multipliers.
|
||||
#[inline(always)]
|
||||
fn combined_penalty_msat(amount_msat: u64, negative_log10_times_2048: u64,
|
||||
fn combined_penalty_msat(amount_msat: u64, mut negative_log10_times_2048: u64,
|
||||
liquidity_penalty_multiplier_msat: u64, liquidity_penalty_amount_multiplier_msat: u64,
|
||||
) -> u64 {
|
||||
let liquidity_penalty_msat = {
|
||||
// Upper bound the liquidity penalty to ensure some channel is selected.
|
||||
let multiplier_msat = liquidity_penalty_multiplier_msat;
|
||||
let max_penalty_msat = multiplier_msat.saturating_mul(NEGATIVE_LOG10_UPPER_BOUND);
|
||||
(negative_log10_times_2048.saturating_mul(multiplier_msat) / 2048).min(max_penalty_msat)
|
||||
};
|
||||
negative_log10_times_2048 =
|
||||
negative_log10_times_2048.min(NEGATIVE_LOG10_UPPER_BOUND * 2048);
|
||||
|
||||
// Upper bound the liquidity penalty to ensure some channel is selected.
|
||||
let liquidity_penalty_msat = negative_log10_times_2048
|
||||
.saturating_mul(liquidity_penalty_multiplier_msat) / 2048;
|
||||
let amount_penalty_msat = negative_log10_times_2048
|
||||
.saturating_mul(liquidity_penalty_amount_multiplier_msat)
|
||||
.saturating_mul(amount_msat) / 2048 / AMOUNT_PENALTY_DIVISOR;
|
||||
|
|
Loading…
Add table
Reference in a new issue