refactor: Use NodeClock::time_point for m_addr_token_timestamp
What changed, and why it matters
This is a minor code cleanup that swaps one internal clock type for another equivalent one. It does not change what the program actually does, so it has no security relevance for users.
No action needed; this is a non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors a single timestamp field and its two uses in net_processing.cpp from std::chrono::microseconds obtained via GetTime<>() to NodeClock::time_point obtained via NodeClock::now(). The arithmetic is adjusted to compute the non-negative seconds difference using Ticks
Changed components
src/net_processing.cpp: Peer::m_addr_token_timestampaddr rate-limiting bucket update in PeerManagerImpl::ProcessAddrsInspect captured patch +4 / −4
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 737d7e70..2916b366 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<std::chrono::microseconds>()};
+ 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<uint64_t> 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<NodeSeconds>()};
// Update/increment addr rate limiting bucket.
- const auto current_time{GetTime<std::chrono::microseconds>()};
+ 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<SecondsDouble>(time_diff) * MAX_ADDR_RATE_PER_SECOND;
+ const auto time_diff{current_time - peer.m_addr_token_timestamp};
+ const double increment{std::max(Ticks<SecondsDouble>(time_diff), 0.0) * MAX_ADDR_RATE_PER_SECOND};
peer.m_addr_token_bucket = std::min<double>(peer.m_addr_token_bucket + increment, MAX_ADDR_PROCESSING_TOKEN_BUCKET);
}
peer.m_addr_token_timestamp = current_time;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.