diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index d88bce4f580..0e7cfc1bdc5 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1556,6 +1556,7 @@ DirectedChannelLiquidity { chan_descr, existing_max_msat, amount_msat); } self.update_history_buckets(0, duration_since_epoch); + *self.last_datapoint_time = duration_since_epoch; } /// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream. @@ -1571,6 +1572,7 @@ DirectedChannelLiquidity { chan_descr, existing_min_msat, amount_msat); } self.update_history_buckets(0, duration_since_epoch); + *self.last_datapoint_time = duration_since_epoch; } /// Adjusts the channel liquidity balance bounds when successfully routing `amount_msat`. @@ -1580,6 +1582,7 @@ DirectedChannelLiquidity { let max_liquidity_msat = self.max_liquidity_msat().checked_sub(amount_msat).unwrap_or(0); log_debug!(logger, "Subtracting {} from max liquidity of {} (setting it to {})", amount_msat, chan_descr, max_liquidity_msat); self.set_max_liquidity_msat(max_liquidity_msat, duration_since_epoch); + *self.last_datapoint_time = duration_since_epoch; self.update_history_buckets(amount_msat, duration_since_epoch); } @@ -1603,7 +1606,6 @@ DirectedChannelLiquidity { *self.max_liquidity_offset_msat = 0; } *self.last_updated = duration_since_epoch; - *self.last_datapoint_time = duration_since_epoch; } /// Adjusts the upper bound of the channel liquidity balance in this direction. @@ -1613,7 +1615,6 @@ DirectedChannelLiquidity { *self.min_liquidity_offset_msat = 0; } *self.last_updated = duration_since_epoch; - *self.last_datapoint_time = duration_since_epoch; } } @@ -4139,21 +4140,24 @@ mod tests { short_channel_id: 42, }); - // Apply some update to set the last-update time to now - scorer.payment_path_failed(&payment_path_for_amount(1000), 42, Duration::ZERO); + // Initialize the state for channel 42 + scorer.payment_path_failed(&payment_path_for_amount(500), 42, Duration::ZERO); + + // Apply an update to set the last-update time to 1 second + scorer.payment_path_failed(&payment_path_for_amount(500), 42, Duration::from_secs(1)); // If no time has passed, we get the full probing_diversity_penalty_msat assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 1_000_000); // As time passes the penalty decreases. - scorer.time_passed(Duration::from_secs(1)); + scorer.time_passed(Duration::from_secs(2)); assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 999_976); - scorer.time_passed(Duration::from_secs(2)); + scorer.time_passed(Duration::from_secs(3)); assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 999_953); // Once we've gotten halfway through the day our penalty is 1/4 the configured value. - scorer.time_passed(Duration::from_secs(86400/2)); + scorer.time_passed(Duration::from_secs(86400/2 + 1)); assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 250_000); } }