diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 46134ff8f54..8f24539a222 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1252,6 +1252,27 @@ DirectedChannelLiquidity< L, BRT, T> { liquidity_penalty_msat.saturating_add(amount_penalty_msat) } + fn success_probability( + &self, usage: ChannelUsage, score_params: &ProbabilisticScoringFeeParameters + ) -> f64 { + let amount_msat = usage.amount_msat; + let available_capacity = self.capacity_msat; + let max_liquidity_msat = self.max_liquidity_msat(); + let min_liquidity_msat = core::cmp::min(self.min_liquidity_msat(), max_liquidity_msat); + + if amount_msat <= min_liquidity_msat { + 1.0 + } else if amount_msat >= max_liquidity_msat { + 0.0 + } else { + let (numerator, denominator) = success_probability( + amount_msat, min_liquidity_msat, max_liquidity_msat, available_capacity, + score_params, false + ); + numerator as f64 / denominator as f64 + } + } + /// Returns the lower bound of the channel liquidity balance in this direction. #[inline(always)] fn min_liquidity_msat(&self) -> u64 { @@ -1391,6 +1412,17 @@ impl>, L: Deref> ScoreLookUp for Probabilistic .saturating_add(base_penalty_msat) } + fn channel_success_probability( + &self, short_channel_id: u64, info: &DirectedChannelInfo, usage: ChannelUsage, + score_params: &ProbabilisticScoringFeeParameters + ) -> f64 { + self.channel_liquidities + .get(&short_channel_id) + .unwrap_or(&ChannelLiquidity::new(Duration::ZERO)) + .as_directed(info.source(), info.target(), usage.effective_capacity.as_msat()) + .success_probability(usage, score_params) + } + fn channel_balance_certainty(&self, short_channel_id: u64, info: &DirectedChannelInfo) -> f64 { self.channel_liquidities .get(&short_channel_id)