-
Notifications
You must be signed in to change notification settings - Fork 402
Use MonotonicTime
as Instant
shifted by 10 years forward
#2322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use MonotonicTime
as Instant
shifted by 10 years forward
#2322
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2322 +/- ##
=======================================
Coverage 90.32% 90.33%
=======================================
Files 106 106
Lines 54951 54965 +14
Branches 54951 54965 +14
=======================================
+ Hits 49633 49651 +18
+ Misses 5318 5314 -4
☔ View full report in Codecov by Sentry. |
a9f5498
to
3a54cff
Compare
Awesome, thanks! ISTM we should simply drop the |
3a54cff
to
a4cb4db
Compare
Makes sense. Now |
lightning/src/util/time.rs
Outdated
} | ||
|
||
fn elapsed(&self) -> Duration { | ||
self.0.elapsed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this result in an underflow? Instant::elapsed
uses Instant::now() - *self
.
Also, note that this method is used in Writeable for ChannelLiquidity<T>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this result in an underflow?
Instant::elapsed
usesInstant::now() - *self
.
Ah, actually that's not a problem since you are adding -- not subtracting -- 10 years. My mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you were right. I changed the implementation and added tests (the tests would fail without the fix).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, yeah, I confused myself. The subtraction occurs in Instant::elapsed
, but the test that I wrote wasn't catching the failure.
I don't think this fix pertains to the system time not being monotonic. That should already be fixed in the |
Ah, you can disregard this argument. I see what you were saying, but I'll push the doc change regardless. |
a4cb4db
to
4507d6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead and squash the fixup and the forthcoming test rename. Otherwise, seems good to go.
lightning/src/util/time.rs
Outdated
@@ -180,7 +180,10 @@ pub mod tests { | |||
#[cfg(not(feature = "no-std"))] | |||
fn monotonic_time_go_backward() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you name this monotonic_time_subtracts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lightning/src/util/time.rs
Outdated
} | ||
|
||
fn elapsed(&self) -> Duration { | ||
self.0.elapsed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, yeah, I confused myself. The subtraction occurs in Instant::elapsed
, but the test that I wrote wasn't catching the failure.
Such implementation allows `MonotonicTime` to go backward up to 10 years on all platforms. On some platforms (e.g. iOS) `Instant` is represented as `u64` of nanoseconds since the boot of the system. Obviously such implementation does not allow to go backward before the time of the boot. Co-authored-by: Andrei <andrei.i@posteo.de> Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
b138ea2
to
47966b8
Compare
47966b8
to
189b070
Compare
Such implementation allows
MonotonicTime
to go backward up to 10 years on all platforms. On some platforms (e.g. iOS)Instant
is represented asu64
of nanoseconds since the boot of the system. Obviously such implementation does not allow to go backward before the time of the boot.Fixes #2311.