Skip to content

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Feb 8, 2021

I have a followup that should remove the last of our boost:posix_time usage in ParseISO8601DateTime, but that will likely need more cross-platform testing/discussion, so have just split them up as this change is straight forward.

@maflcko
Copy link
Member

maflcko commented Feb 8, 2021

Duplicate of #18282?

@fanquake
Copy link
Member Author

Duplicate of #18282?

Do you want to reopen that and include the epoch assertion/sanity check? Otherwise I can update this PR.

@maflcko
Copy link
Member

maflcko commented Feb 10, 2021

My plan was to wait till c++20, because it means less code to write.

@fanquake
Copy link
Member Author

My plan was to wait till c++20, because it means less code to write.

I'm not sure that waiting the many years until the project will actually be able to use C++20, while preventing the removal of Boost, and use of std library features is worth not having to write a few additional lines of code. Especially since the assumption we have to make here is just a Unix time epoch. If it was something more controversial, or involved having to write hundreds of lines of additional code, which would incur a high maintenance overhead, I might agree, but that shouldn't be the case here.

@maflcko
Copy link
Member

maflcko commented Feb 10, 2021

Obviously no objection to adding the sanity check now and removing it when we switch to c++20. I just meant to say that I am not going to write (rebase) it.

@laanwj
Copy link
Member

laanwj commented Feb 10, 2021

Concept ACK

Let's go with a sanity check. I know I disagreed on this in https://github.com/bitcoin/bitcoin/pull/9566/files#r96350569 but as we age we get tired of the same old things and just want to move forward.

@practicalswift
Copy link
Contributor

practicalswift commented Feb 11, 2021

With the simple runtime sanity check from #9566 (9bd32ce) we're guaranteed that we get UTC.

Concept ACK (assuming the sanity check is added of course)

@ajtowns
Copy link
Contributor

ajtowns commented Feb 12, 2021

Concept ACK; agree with adding the sanity check and not waiting for C++20.

theuni and others added 2 commits February 17, 2021 12:26
std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed
to use the Unix epoch timestamp, but in practice they almost certainly will.
Any differing behavior will be assumed to be an error, unless certain
platforms prove to consistently deviate, at which point we'll cope with it
by adding offsets.

Do a quick runtime check to verify that
time_t(0) == std::chrono::system_clock's epoch time == unix epoch.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
@fanquake
Copy link
Member Author

I've changed this to pull in @theuni's sanity check (with some adjustments by @ajtowns , and some review comments from #9566 addressed). I've also dropped my commit in favour of @MarcoFalke change from #18282.

@practicalswift
Copy link
Contributor

practicalswift commented Feb 17, 2021

Tested ACK 9266f74

Startup fails as expected if the sanity check doesn't pass:

$ src/bitcoind
Error: Clock epoch mismatch. Aborting.
Error: Initialization sanity check failed. Bitcoin Core is shutting down.

After this PR is merged the only remaining user of boost::posix_time is ParseISO8601DateTime.

@elichai wrote a Boost-free replacement for ParseISO8601DateTime (then called DecodeDumpTime) two years ago in #17245. That replacement could be re-submitted as a new PR to allow for permanent removal of the boost/date_time/posix_time/posix_time.hpp dependency 🎉

@laanwj
Copy link
Member

laanwj commented Feb 17, 2021

Code review ACK 9266f74

@laanwj laanwj merged commit 372dd8d into bitcoin:master Feb 17, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 18, 2021
@fanquake fanquake deleted the no_boost_gettime branch February 18, 2021 04:48
nuttycom pushed a commit to nuttycom/zcash that referenced this pull request Jul 7, 2022
std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed
to use the Unix epoch timestamp, but in practice they almost certainly will.
Any differing behavior will be assumed to be an error, unless certain
platforms prove to consistently deviate, at which point we'll cope with it
by adding offsets.

Do a quick runtime check to verify that
time_t(0) == std::chrono::system_clock's epoch time == unix epoch.

Co-authored-by: Anthony Towns <aj@erisian.com.au>

Zcash: The first commit of bitcoin/bitcoin#21110; we intend to handle
the changes made by the second commit of that PR in a separate fashion;
see zcash#6042.

(cherry picked from commit bitcoin/bitcoin@3c2e16b)
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 22, 2022
…ion time could be off by one

Summary:
util/time.* uses multiple clocks depending on circumstances like if mock time is set or if templated
GetTime<>() is called. This can result in unexpected behavior where registerProof() uses a different
clock than when SetMockTime(GetTime()...) is called in unit tests.

Example failure: https://build.bitcoinabc.org/viewLog.html?buildId=416835&buildTypeId=BitcoinABC_BitcoinAbcStaging&tab=buildLog&_focus=1325

This patch makes this specific unit test predictable by setting mock time before any proofs are registered.

The root cause may be fixed with additional backports to util/time.* that make the clock selection more
consistent (see backport [[bitcoin/bitcoin#24871 | core#24871]] and [[bitcoin/bitcoin#21110 | core#21110]]).

Test Plan:
  ninja check-avalanche

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11786
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 22, 2022
Summary:
`std::chrono::system_clock.time_since_epoch` and `time_t(0)` are not guaranteed to use the Unix epoch timestamp, but in practice they almost certainly will. Any differing behavior will be  assumed to be an error, unless certain platforms prove to consistently deviate, at which point we'll cope with it by adding offsets.

Do a quick runtime check to verify that `time_t(0) == std::chrono::system_clock`'s epoch time `==` unix epoch.

Co-authored-by: Anthony Towns <aj@erisian.com.au>

This is a backport of [[ bitcoin/bitcoin#21110 | core#21110]] [1/2]
bitcoin/bitcoin@3c2e16b

Note: see D5448 for usage of `#ifdef _WIN32` to determine `gmtime_s` availability. It this turns out to not work in the future, we can try to backport [[bitcoin/bitcoin#18358 | core#18358]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11789
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 22, 2022
Summary:
remove Boost posix_time usage from GetTime*

This is a backport of [[bitcoin/bitcoin#21110 | core#21110]] [2/2]
bitcoin/bitcoin@9266f74

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11790
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
@hebasto
Copy link
Member

hebasto commented Jan 4, 2024

@fanquake

I have a followup that should remove the last of our boost:posix_time usage in ParseISO8601DateTime...

I'm not sure that waiting the many years until the project will actually be able to use C++20...

As std::chrono::parse is available now, do you mind submitting your follow up? If not, I can do it :)

@fanquake
Copy link
Member Author

fanquake commented Jan 5, 2024

As std::chrono::parse is available now,

I'm not sure if that is true? See discussion in #29081 (comment). Happy for you to submit a PR in any case.

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.

7 participants