Skip to content

Assert now > 0 in GetTime GetTimeMillis GetTimeMicros#7094

Merged
laanwj merged 1 commit into
bitcoin:masterfrom
pstratem:2015-11-24-assert-time
Nov 30, 2015
Merged

Assert now > 0 in GetTime GetTimeMillis GetTimeMicros#7094
laanwj merged 1 commit into
bitcoin:masterfrom
pstratem:2015-11-24-assert-time

Conversation

@pstratem

Copy link
Copy Markdown

Previously all of these functions could return negative values (for different
readons). Large portions of the codebase currently assume that these
functions return positive values.

Previously all of these functions could return negative values (for different
readons).  Large portions of the codebase currently assume that these
functions return positive values.
@pstratem

Copy link
Copy Markdown
Author

(Besides if your time is before 1970-1-1 you will reject every single block as being too far in the future)

@dcousens

Copy link
Copy Markdown
Contributor

Sure? Concept ACK.
Any motivation for this @pstratem ?

@pstratem

Copy link
Copy Markdown
Author

@dcousens I was reviewing another PR and noticed that it (sort of) relied on this behavior.

Went and looked a bit and noticed basically every caller does.

@dcousens

Copy link
Copy Markdown
Contributor

utACK

@laanwj

laanwj commented Nov 25, 2015

Copy link
Copy Markdown
Member

Anything concerning time deltas is a different issue. I certainly think a monotonic clock would be useful for some measurements (such as pings).

However this code change would just make sure that the absolute time is positive. More of a sanity check of the OS and boost (eg time() returns -1 on error).

@jtimon

jtimon commented Nov 27, 2015

Copy link
Copy Markdown
Contributor

utACK

@sipa

sipa commented Nov 27, 2015

Copy link
Copy Markdown
Member

In what cases do we expect these assertions to fail?

@paveljanik

Copy link
Copy Markdown
Contributor

IIUIC, it is only for "just to be sure".

E.g. on Linux kernel, you can't make time to fail, especially in the case when NULL is used as an argument. If non-NULL is passed, it can fail when kernel's put_user fails (and in such case, more bad things can happen ;-). The other question is boost...

ACK

@laanwj

laanwj commented Nov 30, 2015

Copy link
Copy Markdown
Member

@paveljanik I guess time() could fail if the relevant syscall is somehow blocked off, say, through seccomp_bpf. And yes boost... who knows
All cases in which it's better to fail fast.

@laanwj laanwj merged commit 1bb289f into bitcoin:master Nov 30, 2015
laanwj added a commit that referenced this pull request Nov 30, 2015
1bb289f Assert now > 0 in GetTime GetTimeMillis GetTimeMicros (Patick Strateman)
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jan 10, 2016
Previously all of these functions could return negative values (for different
readons).  Large portions of the codebase currently assume that these
functions return positive values.

Github-Pull: bitcoin#7094
Rebased-From: 1bb289f
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jan 10, 2016
Previously all of these functions could return negative values (for different
readons).  Large portions of the codebase currently assume that these
functions return positive values.

Github-Pull: bitcoin#7094
Rebased-From: 1bb289f
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants