From cc7d2b8d0a80f76ed090718318db8d1593b58a08 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:07:11 +0000 Subject: [PATCH] merge bitcoin#25102: Remove unused GetTimeSeconds --- src/bitcoin-cli.cpp | 14 ++++++++++---- src/test/fuzz/fuzz.cpp | 6 +++--- src/test/util_tests.cpp | 3 --- src/util/time.cpp | 5 ----- src/util/time.h | 13 ++++++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index cd691e151c..565745d5f7 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,17 +19,19 @@ #include #include #include +#include #include #include #include #include #include +#include #include +#include #include #include #include -#include #include #include @@ -40,8 +43,11 @@ #include #include -#include -#include +// The server returns time values from a mockable system clock, but it is not +// trivial to get the mocked time from the server, nor is it needed for now, so +// just use a plain system_clock. +using CliClock = std::chrono::system_clock; +using CliSeconds = std::chrono::time_point; const std::function G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = urlDecode; @@ -454,7 +460,7 @@ private: if (conn_type == "addr-fetch") return "addr"; return ""; } - const int64_t m_time_now{GetTimeSeconds()}; + const int64_t m_time_now{count_seconds(Now())}; public: static constexpr int ID_PEERINFO = 0; diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 00f874212e..ee91b15ed0 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -188,7 +188,7 @@ int main(int argc, char** argv) return 0; } std::signal(SIGABRT, signal_handler); - int64_t start_time = GetTimeSeconds(); + const auto start_time{Now()}; int tested = 0; for (int i = 1; i < argc; ++i) { fs::path input_path(*(argv + i)); @@ -209,8 +209,8 @@ int main(int argc, char** argv) buffer.clear(); } } - int64_t end_time = GetTimeSeconds(); - std::cout << g_fuzz_target << ": succeeded against " << tested << " files in " << (end_time - start_time) << "s." << std::endl; + const auto end_time{Now()}; + std::cout << g_fuzz_target << ": succeeded against " << tested << " files in " << count_seconds(end_time - start_time) << "s." << std::endl; #endif return 0; } diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index ea9c735178..f396c4f7e0 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -297,9 +297,6 @@ BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime) BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0); BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0); BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777); - - auto time = GetTimeSeconds(); - BOOST_CHECK_EQUAL(ParseISO8601DateTime(FormatISO8601DateTime(time)), time); } BOOST_AUTO_TEST_CASE(util_FormatISO8601Date) diff --git a/src/util/time.cpp b/src/util/time.cpp index fa0ad5b5a4..1f2609080f 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -111,11 +111,6 @@ int64_t GetTimeMicros() return int64_t{GetSystemTime().count()}; } -int64_t GetTimeSeconds() -{ - return int64_t{GetSystemTime().count()}; -} - int64_t GetTime() { return GetTime().count(); } std::string FormatISO8601DateTime(int64_t nTime) { diff --git a/src/util/time.h b/src/util/time.h index 36300b29fd..b05cfe449d 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -22,15 +22,20 @@ using SteadyMicroseconds = std::chrono::time_point +constexpr int64_t count_seconds(std::chrono::time_point t) +{ + return t.time_since_epoch().count(); +} constexpr int64_t count_seconds(std::chrono::seconds t) { return t.count(); } constexpr int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); } constexpr int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); } @@ -52,8 +57,6 @@ int64_t GetTime(); int64_t GetTimeMillis(); /** Returns the system time (not mockable) */ int64_t GetTimeMicros(); -/** Returns the system time (not mockable) */ -int64_t GetTimeSeconds(); // Like GetTime(), but not mockable /** * DEPRECATED