From: Jeffrey Czyz Date: Wed, 27 Oct 2021 19:30:15 +0000 (-0500) Subject: f - Fix divide by zero X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=07cd143e58de201ab3536276c28fcfc29aab41e0;p=rust-lightning f - Fix divide by zero --- 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, + } }