From 07cd143e58de201ab3536276c28fcfc29aab41e0 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 27 Oct 2021 14:30:15 -0500 Subject: [PATCH] f - Fix divide by zero --- lightning/src/routing/scorer.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lightning/src/routing/scorer.rs b/lightning/src/routing/scorer.rs index 6e3b2a289..568be52df 100644 --- a/lightning/src/routing/scorer.rs +++ b/lightning/src/routing/scorer.rs @@ -170,8 +170,12 @@ impl routing::Score for Scorer { #[cfg(not(feature = "no-std"))] fn decay_from(penalty_msat: u64, last_failure: &SystemTime, half_life: Duration) -> u64 { - let decays = last_failure.elapsed().ok().map_or(0, |elapsed| { - elapsed.as_secs() / half_life.as_secs() - }); - penalty_msat >> decays + let decays = match last_failure.elapsed().ok() { + Some(elapsed) => elapsed.as_secs().checked_div(half_life.as_secs()), + None => Some(0), + }; + match decays { + Some(decays) => penalty_msat >> decays, + None => 0, + } } -- 2.39.5