From 3333c5023f7e5636cfe5dd9cff770da98684b86e Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 12 Dec 2025 15:24:17 +0100 Subject: [PATCH] refactor: Use NodeClock::time_point for m_addr_token_timestamp This refactor makes the field a bit more type-safe. --- src/net_processing.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 737d7e70e29..2916b3668a1 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -379,7 +379,7 @@ struct Peer { * permit self-announcement. */ double m_addr_token_bucket GUARDED_BY(NetEventsInterface::g_msgproc_mutex){1.0}; /** When m_addr_token_bucket was last updated */ - std::chrono::microseconds m_addr_token_timestamp GUARDED_BY(NetEventsInterface::g_msgproc_mutex){GetTime()}; + NodeClock::time_point m_addr_token_timestamp GUARDED_BY(NetEventsInterface::g_msgproc_mutex){NodeClock::now()}; /** Total number of addresses that were dropped due to rate limiting. */ std::atomic m_addr_rate_limited{0}; /** Total number of addresses that were processed (excludes rate-limited ones). */ @@ -5643,11 +5643,11 @@ void PeerManagerImpl::ProcessAddrs(std::string_view msg_type, CNode& pfrom, Peer const auto current_a_time{Now()}; // Update/increment addr rate limiting bucket. - const auto current_time{GetTime()}; + const auto current_time{NodeClock::now()}; 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 = Ticks(time_diff) * MAX_ADDR_RATE_PER_SECOND; + const auto time_diff{current_time - peer.m_addr_token_timestamp}; + const double increment{std::max(Ticks(time_diff), 0.0) * 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;