]> git.bitcoin.ninja Git - rust-lightning/commitdiff
f - Fix divide by zero
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 27 Oct 2021 19:30:15 +0000 (14:30 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 27 Oct 2021 19:31:20 +0000 (14:31 -0500)
lightning/src/routing/scorer.rs

index 6e3b2a289de78ed8925cd900554e4b965622717b..568be52df49032822b59076ef62af72116ee6454 100644 (file)
@@ -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,
+       }
 }