From 00001e57fe74c061aa9cbc72b07252335cb566e0 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 11 Apr 2022 13:37:05 +0200 Subject: [PATCH 1/2] Remove redundant nTime checks nTime is always initialized on deserialization or default-initialized with TIME_INIT, so special casing 0 does not make sense. --- src/addrman.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index ed823eeb05d..678396993b7 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -72,8 +72,9 @@ bool AddrInfo::IsTerrible(int64_t nNow) const if (nTime > nNow + 10 * 60) // came in a flying DeLorean return true; - if (nTime == 0 || nNow - nTime > ADDRMAN_HORIZON_DAYS * 24 * 60 * 60) // not seen in recent history + if (nNow - nTime > ADDRMAN_HORIZON_DAYS * 24 * 60 * 60) { // not seen in recent history return true; + } if (nLastSuccess == 0 && nAttempts >= ADDRMAN_RETRIES) // tried N times and never a success return true; @@ -557,15 +558,17 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_ // periodically update nTime bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60); int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60); - if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty)) + if (pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty) { pinfo->nTime = std::max((int64_t)0, addr.nTime - nTimePenalty); + } // add services pinfo->nServices = ServiceFlags(pinfo->nServices | addr.nServices); // do not update if no new information is present - if (!addr.nTime || (pinfo->nTime && addr.nTime <= pinfo->nTime)) + if (addr.nTime <= pinfo->nTime) { return false; + } // do not update if the entry was already in the "tried" table if (pinfo->fInTried) From 8888bd43c100f9f0ca1122fcc896fb7b999d61c6 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 11 Apr 2022 14:24:47 +0200 Subject: [PATCH 2/2] Remove redundant nLastTry check All other places calculate "now - nLastTry", which is safe and correct to do when nLastTry is 0. So do the same here. --- src/addrman.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 678396993b7..204bb544c51 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -66,8 +66,9 @@ int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) con bool AddrInfo::IsTerrible(int64_t nNow) const { - if (nLastTry && nLastTry >= nNow - 60) // never remove things tried in the last minute + if (nNow - nLastTry <= 60) { // never remove things tried in the last minute return false; + } if (nTime > nNow + 10 * 60) // came in a flying DeLorean return true;