From 5dc5ef7009719e0e5bba2006aa90fe8db9a9db0a Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 1 Feb 2022 14:51:08 -0600 Subject: [PATCH] f - Remove branching --- lightning/src/routing/scoring.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index d279bd286..c7f36c895 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -648,7 +648,6 @@ impl> DirectedChannelLiquidity { } impl> Score for ProbabilisticScorer { - #[allow(clippy::float_cmp)] fn channel_penalty_msat( &self, short_channel_id: u64, amount_msat: u64, capacity_msat: u64, source: &NodeId, target: &NodeId @@ -659,13 +658,10 @@ impl> Score for ProbabilisticScorer { .unwrap_or(&ChannelLiquidity::new()) .as_directed(source, target, capacity_msat) .success_probability(amount_msat); - if success_probability == 0.0 { - u64::max_value() - } else if success_probability == 1.0 { - 0 - } else { - (-(success_probability.log10()) * liquidity_penalty_multiplier_msat as f64) as u64 - } + // NOTE: If success_probability is ever changed to return 0.0, log10 is undefined so return + // u64::max_value instead. + debug_assert!(success_probability > core::f64::EPSILON); + (-(success_probability.log10()) * liquidity_penalty_multiplier_msat as f64) as u64 } fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { -- 2.39.5