From 4790f197e43bfbdb2e73698510295a4220c3227e Mon Sep 17 00:00:00 2001 From: fanquake Date: Tue, 28 Jun 2022 18:18:06 +0100 Subject: [PATCH] Merge bitcoin/bitcoin#25480: Replace CountSecondsDouble with Ticks fa956e7508986991008e2f6126ab307924b3f353 Replace CountSecondsDouble with Ticks (MacroFake) Pull request description: Seems odd to have two ways to say exactly the same thing when one is sufficient. ACKs for top commit: fanquake: ACK fa956e7508986991008e2f6126ab307924b3f353 shaavan: ACK fa956e7508986991008e2f6126ab307924b3f353 w0xlt: ACK https://github.com/bitcoin/bitcoin/pull/25480/commits/fa956e7508986991008e2f6126ab307924b3f353 Tree-SHA512: b599470e19b693da1ed1102d1e86b08cb03adaddf2048752b6d050fdf86055be117ff0ae10b6953d03e00eaaf7b0cfa350137968b67d6c5b3ca68c5aa50ca6aa --- src/net_processing.cpp | 2 +- src/rpc/net.cpp | 6 +++--- src/util/time.h | 5 ----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 57b300933f8d83..73f3d39a58b1c6 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3995,7 +3995,7 @@ void PeerManagerImpl::ProcessMessage( if (peer->m_addr_token_bucket < MAX_ADDR_PROCESSING_TOKEN_BUCKET) { // Don't increment bucket if it's already full const auto time_diff = std::max(current_time - peer->m_addr_token_timestamp, 0us); - const double increment = CountSecondsDouble(time_diff) * MAX_ADDR_RATE_PER_SECOND; + const double increment = Ticks(time_diff) * MAX_ADDR_RATE_PER_SECOND; peer->m_addr_token_bucket = std::min(peer->m_addr_token_bucket + increment, MAX_ADDR_PROCESSING_TOKEN_BUCKET); } peer->m_addr_token_timestamp = current_time; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 5a67baecab6f2c..21215aef838eba 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -222,13 +222,13 @@ static RPCHelpMan getpeerinfo() obj.pushKV("conntime", count_seconds(stats.m_connected)); obj.pushKV("timeoffset", stats.nTimeOffset); if (stats.m_last_ping_time > 0us) { - obj.pushKV("pingtime", CountSecondsDouble(stats.m_last_ping_time)); + obj.pushKV("pingtime", Ticks(stats.m_last_ping_time)); } if (stats.m_min_ping_time < std::chrono::microseconds::max()) { - obj.pushKV("minping", CountSecondsDouble(stats.m_min_ping_time)); + obj.pushKV("minping", Ticks(stats.m_min_ping_time)); } if (fStateStats && statestats.m_ping_wait > 0s) { - obj.pushKV("pingwait", CountSecondsDouble(statestats.m_ping_wait)); + obj.pushKV("pingwait", Ticks(statestats.m_ping_wait)); } obj.pushKV("version", stats.nVersion); // Use the sanitized form of subver here, to avoid tricksy remote peers from diff --git a/src/util/time.h b/src/util/time.h index 32bdebb2050663..762262858b64ff 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -58,11 +58,6 @@ constexpr int64_t count_microseconds(std::chrono::microseconds t) { return t.cou using HoursDouble = std::chrono::duration; using SecondsDouble = std::chrono::duration; -/** - * Helper to count the seconds in any std::chrono::duration type - */ -inline double CountSecondsDouble(SecondsDouble t) { return t.count(); } - /** * DEPRECATED * Use either ClockType::now() or Now() if a cast is needed.