diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 3c7b623065d..26c5b1035b0 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1251,6 +1251,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 { @@ -1390,6 +1411,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)