File tree 1 file changed +13
-1
lines changed 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> {
1215
1215
( 2 , max_liquidity_offset_msat, required) ,
1216
1216
( 4 , duration_since_epoch, required) ,
1217
1217
} ) ;
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 } ;
1218
1230
Ok ( Self {
1219
1231
min_liquidity_offset_msat,
1220
1232
max_liquidity_offset_msat,
1221
- last_updated : T :: now ( ) - ( T :: duration_since_epoch ( ) - duration_since_epoch ) ,
1233
+ last_updated,
1222
1234
} )
1223
1235
}
1224
1236
}
You can’t perform that action at this time.
0 commit comments