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
Avoid panicking on wallclock time going backwards across restart #1603
Avoid panicking on wallclock time going backwards across restart #1603
Conversation
67c9e54
to
70bc165
Compare
lightning/src/routing/scoring.rs
Outdated
// 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 reload it | ||
// 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 juse use `now` | ||
// instead to avoid panicing later. |
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.
what if there's some actual bug and we end up hiding it because of this? (if diff is alot and weird)
shouldn't the solution be to use saturating_duration_since
for now ?
(that will also mean that we will clean it up when duration_since
is not panicking)
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 suppose we could? That would hide system time going backwards at runtime, too, though. I don't really feel strongly either way, I'm happy to do either, both would hide the same error, though, I believe.
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.
main intention was for cleanup, but i guess it could be safer to do it at one place at read time.
first question was about if we should do a tolerance check on difference.
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.
Ah, right, okay, yea, I didn't this its critical enough to overthink it and add tolerance checks or anything like that - worst case we don't decay the scorer data quick enough, as long as time is moving forward we'll still decay it, though.
Codecov Report
@@ Coverage Diff @@
## main #1603 +/- ##
==========================================
+ Coverage 91.07% 91.29% +0.21%
==========================================
Files 80 80
Lines 44128 48731 +4603
Branches 44128 48731 +4603
==========================================
+ Hits 40190 44488 +4298
- Misses 3938 4243 +305
Continue to review full report at Codecov.
|
fc5f68f
to
5ceeb27
Compare
Pushed a squshed fixup to address spelling:
|
lightning/src/routing/scoring.rs
Outdated
// 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 |
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.
Perhaps you meant "when we were written and reload it here"?
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.
Yeah, the "are reloading here" part doesn't make sense grammatically to me. Also, the second "we" is referring to something other than the first "we". Maybe s/when we were written/when written?
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.
Yea, sorry, that whole sentence just really made absolutely no sense. I rewrote it.
lightning/src/routing/scoring.rs
Outdated
@@ -1177,10 +1177,20 @@ impl<T: Time> Readable for ChannelLiquidity<T> { | |||
(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 write `last_updated` as wallclock time when we were written and create an |
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'd recommend re-writing the second sentence as:
Because last_updated
is written as a wallclock time but when read needs to be constructed as an Instant
representing that wallclock time, we may hit that panic if the current wallclock time is before the wallclock time when written.
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.
Hmm, that doesn't tell me clearly what the panic is. I ended up writing a much more verbose version that explains in detail what's going on, let me know which you prefer.
Because we serialize `Instant`s using wallclock time in `ProbabilisticScorer`, if time goes backwards across restarts we may end up with `Instant`s in the future, which causes rustc prior to 1.60 to panic when calculating durations. Here we simply avoid this by setting the time to `now` if we get a time in the future.
55831d0
to
497fd65
Compare
Squashed without further changes, note that all the changes from the first PR version were in the comment anyway. |
Because we serialize
Instant
s using wallclock time inProbabilisticScorer
, if time goes backwards across restarts wemay end up with
Instant
s in the future, which causes rustc priorto 1.60 to panic when calculating durations. Here we simply avoid
this by setting the time to
now
if we get a time in the future.