Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Simplify network-adjusted time warning logic #29623
Simplify network-adjusted time warning logic #29623
Changes from all commits
038fd97
55361a1
ee178df
7d9c3ec
92e72b5
c6be144
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
After 2ef71c7,
timedata
is not a thing anymore, so this may need updatingThere 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.
updated to
Don't use time offset samples
, thanks.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 don't think this was covered (or it may have been regressed)
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.
Sorry, I think it must have regressed with this update in the next line - will fix if I have to retouch.
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.
e6d7bcf doesn't look like
chrono_literals
is required hereThere 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 it is for
if (m_offsets.size() < 5) return 0s;
?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 removed it and this seems to run fine, at least in my system
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.
We
#include <util/time.h>
which hasusing namespace std::chrono_literals;
which is why it compiles. I thought we would prefer (IWYU-style) to be explicit about used namespaces, but upon further investigation the purpose of #20602 seems to have been to avoid that, so I'll remove this if I re-touch.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.
nit in 9f2904b: This may keep printing the warning, even if the user adjusted the clock, because the offsets are not discarded when the clock changes.
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.
The log message has been updated to highlight that the message may persist for a while, thanks.
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.
Grepping in my node's log for how frequent outbound connections are made - it would take about 1.5 days to make 200 new outbound connections. Since this is about the median, I guess 101 new connections after fixing the clock will be enough for us to stop the warning. That is like 20ish hours. Quite long. Can we do better?
Currently we only save the difference between our time and the peer's time at the start of the connection and we have no clue that this difference has changed due to our clock being adjusted/corrected. If we save the value of the system_clock and steady_clock at the start of the connection, in addition to the peer's offset, at a later time we can deduce that our clock has been adjusted and add that diff/adjustment to the peer's offset to immediately figure out that "now our clock is in sync with that peer's clock".
So, instead of
peer_offset
, it would be a matter of using the following instead:peer_offset + steady_clock_diff - system_clock_diff
, assuming:steady_clock_diff = steady_clock_now - steady_clock_when_connected
system_clock_diff = system_clock_now - system_clock_when_connected
.Example:
Lets say our clock is wrong, 15 minutes ahead. When we connect to a peer at
17:00:00
our time they send us a time that is 15 minutes ago and we save:peer_offset = -15min
,system_clock_when_connected = 17:00:00
,steady_clock_when_connected = 1000
(some obscure value [seconds]).One hour later, our clock has been fixed/corrected, by moving it 15 min backwards (or stopping to move for 15 min). So,
system_clock_now = 17:45:00
,steady_clock_now = 4600
(the obscure value 1000 plus 3600 because 1 hour has passed).And then:
steady_clock_diff = 4600 - 1000 = 60 min
system_clock_diff = 17:45:00 - 17:00:00 = 45 min
The difference between those is 15 minutes and adding that to
peer_offset
gives us offset 0, meaning that now our clock is in sync with the peer's clock.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.
Using both system and steady clock is an interesting idea and one I hadn't considered, thanks. I'm going to look into this a bit more and will follow up shortly.
FYI this PR reduces 200 -> 50 outbounds so your calculations are a bit off.