refactor: Use current_time over redundant call to Now()
What changed, and why it matters
This is a minor code cleanup in Bitcoin Core's network address handling. It replaces two separate calls that both retrieved the current time with a single shared call. There is no security-relevant change; the behavior is functionally identical.
No security action needed. This is a routine refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In PeerManagerImpl::ProcessAddrs(), the patch removes a redundant Now
Changed components
src/net_processing.cppPeerManagerImpl::ProcessAddrsInspect captured patch +3 / −4
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 2916b366..28d7d2c1 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -5640,7 +5640,6 @@ void PeerManagerImpl::ProcessAddrs(std::string_view msg_type, CNode& pfrom, Peer
// Store the new addresses
std::vector<CAddress> vAddrOk;
- const auto current_a_time{Now<NodeSeconds>()};
// Update/increment addr rate limiting bucket.
const auto current_time{NodeClock::now()};
@@ -5676,8 +5675,8 @@ void PeerManagerImpl::ProcessAddrs(std::string_view msg_type, CNode& pfrom, Peer
if (!MayHaveUsefulAddressDB(addr.nServices) && !HasAllDesirableServiceFlags(addr.nServices))
continue;
- if (addr.nTime <= NodeSeconds{100000000s} || addr.nTime > current_a_time + 10min) {
- addr.nTime = current_a_time - 5 * 24h;
+ if (addr.nTime <= NodeSeconds{100000000s} || addr.nTime > current_time + 10min) {
+ addr.nTime = std::chrono::time_point_cast<std::chrono::seconds>(current_time - 5 * 24h);
}
AddAddressKnown(peer, addr);
if (m_banman && (m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr))) {
@@ -5686,7 +5685,7 @@ void PeerManagerImpl::ProcessAddrs(std::string_view msg_type, CNode& pfrom, Peer
}
++num_proc;
const bool reachable{g_reachable_nets.Contains(addr)};
- if (addr.nTime > current_a_time - 10min && !peer.m_getaddr_sent && vAddr.size() <= 10 && addr.IsRoutable()) {
+ if (addr.nTime > current_time - 10min && !peer.m_getaddr_sent && vAddr.size() <= 10 && addr.IsRoutable()) {
// Relay to a limited number of other nodes
RelayAddress(pfrom.GetId(), addr, reachable);
}
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.