From 161d46fe447d117784919a08292b8d69c31962a4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 5 Dec 2023 17:51:31 +0000 Subject: [PATCH] f include ms/ns time parts when decaying --- lightning/src/routing/scoring.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 6a9f7266..329b2697 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1074,10 +1074,10 @@ impl ChannelLiquidity { } fn decayed_offset(&self, offset: u64, decay_params: ProbabilisticScoringDecayParameters) -> u64 { - let half_life = decay_params.liquidity_offset_half_life.as_secs(); - if half_life != 0 { - let elapsed_time = T::now().duration_since(self.last_updated).as_secs() as f64; - ((offset as f64) * powf64(0.5, elapsed_time / (half_life as f64))) as u64 + let half_life = decay_params.liquidity_offset_half_life.as_secs_f64(); + if half_life != 0.0 { + let elapsed_time = T::now().duration_since(self.last_updated).as_secs_f64(); + ((offset as f64) * powf64(0.5, elapsed_time / half_life)) as u64 } else { 0 } @@ -1508,8 +1508,8 @@ impl>, L: Deref, T: Time> ScoreUpdate for Prob let elapsed_time = T::now().duration_since(liquidity.offset_history_last_updated); if elapsed_time > decay_params.historical_no_updates_half_life { - let half_life = decay_params.historical_no_updates_half_life.as_secs() as f64; - let divisor = powf64(2048.0, (elapsed_time.as_secs() as f64) / half_life) as u64; + let half_life = decay_params.historical_no_updates_half_life.as_secs_f64(); + let divisor = powf64(2048.0, elapsed_time.as_secs_f64() / half_life) as u64; for bucket in liquidity.min_liquidity_offset_history.buckets.iter_mut() { *bucket = ((*bucket as u64) * 1024 / divisor) as u16; } -- 2.30.2