diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 524f0ed3158..b4dba7d0ff1 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1177,10 +1177,20 @@ impl Readable for ChannelLiquidity { (2, max_liquidity_offset_msat, required), (4, duration_since_epoch, required), }); + // On rust prior to 1.60 `Instant::duration_since` will panic if time goes backwards. + // Because we calculate "now" against wallclock time when we were written are reloading + // here, we may cause time to go backwards if wallclock time is before when we were + // written. Thus, we check if we'd end up with a time in the future and just use `now` + // instead to avoid panicing later. + let wall_clock_now = T::duration_since_epoch(); + let now = T::now(); + let last_updated = if wall_clock_now > duration_since_epoch { + now - (wall_clock_now - duration_since_epoch) + } else { now }; Ok(Self { min_liquidity_offset_msat, max_liquidity_offset_msat, - last_updated: T::now() - (T::duration_since_epoch() - duration_since_epoch), + last_updated, }) } }