We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents fc7b14b + 82474d3 commit f99301dCopy full SHA for f99301d
lightning/src/util/time.rs
@@ -65,7 +65,12 @@ impl Time for std::time::Instant {
65
}
66
67
fn duration_since(&self, earlier: Self) -> Duration {
68
- self.duration_since(earlier)
+ // On rust prior to 1.60 `Instant::duration_since` will panic if time goes backwards.
69
+ // However, we support rust versions prior to 1.60 and some users appear to have "monotonic
70
+ // clocks" that go backwards in practice (likely relatively ancient kernels/etc). Thus, we
71
+ // manually check for time going backwards here and return a duration of zero in that case.
72
+ let now = Self::now();
73
+ if now > earlier { now - earlier } else { Duration::from_secs(0) }
74
75
76
fn duration_since_epoch() -> Duration {
0 commit comments