Revert "time: add runtime sanity check"

This reverts commit 3c2e16be22.
This commit is contained in:
MarcoFalke 2023-12-14 18:19:58 +01:00
parent 7af95afa8b
commit fa2c486afc
No known key found for this signature in database
4 changed files with 0 additions and 53 deletions

View File

@ -6,7 +6,6 @@
#include <key.h>
#include <random.h>
#include <util/time.h>
#include <util/translation.h>
#include <memory>
@ -23,10 +22,6 @@ util::Result<void> SanityChecks(const Context&)
return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
}
if (!ChronoSanityCheck()) {
return util::Error{Untranslated("Clock epoch mismatch. Aborting.")};
}
return {};
}

View File

@ -4,7 +4,6 @@
#include <key.h>
#include <test/util/setup_common.h>
#include <util/time.h>
#include <boost/test/unit_test.hpp>
@ -13,7 +12,6 @@ BOOST_FIXTURE_TEST_SUITE(sanity_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(basic_sanity)
{
BOOST_CHECK_MESSAGE(ECC_InitSanityCheck() == true, "secp256k1 sanity test");
BOOST_CHECK_MESSAGE(ChronoSanityCheck() == true, "chrono epoch test");
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -24,49 +24,6 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread
static std::atomic<int64_t> nMockTime(0); //!< For testing
bool ChronoSanityCheck()
{
// std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed
// to use the Unix epoch timestamp, prior to C++20, 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.
// Create a new clock from time_t(0) and make sure that it represents 0
// seconds from the system_clock's time_since_epoch. Then convert that back
// to a time_t and verify that it's the same as before.
const time_t time_t_epoch{};
auto clock = std::chrono::system_clock::from_time_t(time_t_epoch);
if (std::chrono::duration_cast<std::chrono::seconds>(clock.time_since_epoch()).count() != 0) {
return false;
}
time_t time_val = std::chrono::system_clock::to_time_t(clock);
if (time_val != time_t_epoch) {
return false;
}
// Check that the above zero time is actually equal to the known unix timestamp.
struct tm epoch;
#ifdef HAVE_GMTIME_R
if (gmtime_r(&time_val, &epoch) == nullptr) {
#else
if (gmtime_s(&epoch, &time_val) != 0) {
#endif
return false;
}
if ((epoch.tm_sec != 0) ||
(epoch.tm_min != 0) ||
(epoch.tm_hour != 0) ||
(epoch.tm_mday != 1) ||
(epoch.tm_mon != 0) ||
(epoch.tm_year != 70)) {
return false;
}
return true;
}
NodeClock::time_point NodeClock::now() noexcept
{
const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)};

View File

@ -116,7 +116,4 @@ struct timeval MillisToTimeval(int64_t nTimeout);
*/
struct timeval MillisToTimeval(std::chrono::milliseconds ms);
/** Sanity check epoch match normal Unix epoch */
bool ChronoSanityCheck();
#endif // BITCOIN_UTIL_TIME_H