Skip to content

Commit fa2c486

Browse files
author
MarcoFalke
committed
Revert "time: add runtime sanity check"
This reverts commit 3c2e16b.
1 parent 7af95af commit fa2c486

File tree

4 files changed

+0
-53
lines changed

4 files changed

+0
-53
lines changed

src/kernel/checks.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <key.h>
88
#include <random.h>
9-
#include <util/time.h>
109
#include <util/translation.h>
1110

1211
#include <memory>
@@ -23,10 +22,6 @@ util::Result<void> SanityChecks(const Context&)
2322
return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
2423
}
2524

26-
if (!ChronoSanityCheck()) {
27-
return util::Error{Untranslated("Clock epoch mismatch. Aborting.")};
28-
}
29-
3025
return {};
3126
}
3227

src/test/sanity_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <key.h>
66
#include <test/util/setup_common.h>
7-
#include <util/time.h>
87

98
#include <boost/test/unit_test.hpp>
109

@@ -13,7 +12,6 @@ BOOST_FIXTURE_TEST_SUITE(sanity_tests, BasicTestingSetup)
1312
BOOST_AUTO_TEST_CASE(basic_sanity)
1413
{
1514
BOOST_CHECK_MESSAGE(ECC_InitSanityCheck() == true, "secp256k1 sanity test");
16-
BOOST_CHECK_MESSAGE(ChronoSanityCheck() == true, "chrono epoch test");
1715
}
1816

1917
BOOST_AUTO_TEST_SUITE_END()

src/util/time.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,6 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread
2424

2525
static std::atomic<int64_t> nMockTime(0); //!< For testing
2626

27-
bool ChronoSanityCheck()
28-
{
29-
// std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed
30-
// to use the Unix epoch timestamp, prior to C++20, but in practice they almost
31-
// certainly will. Any differing behavior will be assumed to be an error, unless
32-
// certain platforms prove to consistently deviate, at which point we'll cope
33-
// with it by adding offsets.
34-
35-
// Create a new clock from time_t(0) and make sure that it represents 0
36-
// seconds from the system_clock's time_since_epoch. Then convert that back
37-
// to a time_t and verify that it's the same as before.
38-
const time_t time_t_epoch{};
39-
auto clock = std::chrono::system_clock::from_time_t(time_t_epoch);
40-
if (std::chrono::duration_cast<std::chrono::seconds>(clock.time_since_epoch()).count() != 0) {
41-
return false;
42-
}
43-
44-
time_t time_val = std::chrono::system_clock::to_time_t(clock);
45-
if (time_val != time_t_epoch) {
46-
return false;
47-
}
48-
49-
// Check that the above zero time is actually equal to the known unix timestamp.
50-
struct tm epoch;
51-
#ifdef HAVE_GMTIME_R
52-
if (gmtime_r(&time_val, &epoch) == nullptr) {
53-
#else
54-
if (gmtime_s(&epoch, &time_val) != 0) {
55-
#endif
56-
return false;
57-
}
58-
59-
if ((epoch.tm_sec != 0) ||
60-
(epoch.tm_min != 0) ||
61-
(epoch.tm_hour != 0) ||
62-
(epoch.tm_mday != 1) ||
63-
(epoch.tm_mon != 0) ||
64-
(epoch.tm_year != 70)) {
65-
return false;
66-
}
67-
return true;
68-
}
69-
7027
NodeClock::time_point NodeClock::now() noexcept
7128
{
7229
const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)};

src/util/time.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,4 @@ struct timeval MillisToTimeval(int64_t nTimeout);
116116
*/
117117
struct timeval MillisToTimeval(std::chrono::milliseconds ms);
118118

119-
/** Sanity check epoch match normal Unix epoch */
120-
bool ChronoSanityCheck();
121-
122119
#endif // BITCOIN_UTIL_TIME_H

0 commit comments

Comments
 (0)