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.
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.
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.
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.
With the simple runtime sanity check from #9566 (https://github.com/bitcoin/bitcoin/pull/9566/commits/9bd32ce6aa50df95fd5aeaece92b8b908c582c73) we’re guaranteed that we get UTC.
Concept ACK (assuming the sanity check is added of course)
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>
Tested ACK 9266f7497f256d780178829e0f3a29ddaeb794ba
Startup fails as expected if the sanity check doesn’t pass:
0$ src/bitcoind
1Error: Clock epoch mismatch. Aborting.
2Error: 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 🎉
I have a followup that should remove the last of our
boost:posix_time
usage inParseISO8601DateTime
…
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 :)
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.