File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1215,10 +1215,22 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
12151215 ( 2 , max_liquidity_offset_msat, required) ,
12161216 ( 4 , duration_since_epoch, required) ,
12171217 } ) ;
1218+ // On rust prior to 1.60 `Instant::duration_since` will panic if time goes backwards.
1219+ // We write `last_updated` as wallclock time even though its ultimately an `Instant` (which
1220+ // is a time from a monotonic clock usually represented as an offset against boot time).
1221+ // Thus, we have to construct an `Instant` by subtracting the difference in wallclock time
1222+ // from the one that was written. However, because `Instant` can panic if we construct one
1223+ // in the future, we must handle wallclock time jumping backwards, which we do by simply
1224+ // using `Instant::now()` in that case.
1225+ let wall_clock_now = T :: duration_since_epoch ( ) ;
1226+ let now = T :: now ( ) ;
1227+ let last_updated = if wall_clock_now > duration_since_epoch {
1228+ now - ( wall_clock_now - duration_since_epoch)
1229+ } else { now } ;
12181230 Ok ( Self {
12191231 min_liquidity_offset_msat,
12201232 max_liquidity_offset_msat,
1221- last_updated : T :: now ( ) - ( T :: duration_since_epoch ( ) - duration_since_epoch ) ,
1233+ last_updated,
12221234 } )
12231235 }
12241236}
You can’t perform that action at this time.
0 commit comments