diff options
author | fanquake <fanquake@gmail.com> | 2022-06-09 12:24:28 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-06-09 12:28:25 +0100 |
commit | 9edc5133d49978db75cf68be1a2046236c007d9f (patch) | |
tree | 2d391370f3f33b4dc7c9355be08a18a6b380a53b /src | |
parent | 455780b1aebae21ebd5d83d2f0ff6a2264ac9608 (diff) | |
parent | 8888bd43c100f9f0ca1122fcc896fb7b999d61c6 (diff) | |
download | bitcoin-9edc5133d49978db75cf68be1a2046236c007d9f.tar.xz |
Merge bitcoin/bitcoin#25303: refactor: Remove redundant addrman time checks
8888bd43c100f9f0ca1122fcc896fb7b999d61c6 Remove redundant nLastTry check (MarcoFalke)
00001e57fe74c061aa9cbc72b07252335cb566e0 Remove redundant nTime checks (MarcoFalke)
Pull request description:
Split out from https://github.com/bitcoin/bitcoin/pull/24697 because it makes sense on its own.
ACKs for top commit:
dergoegge:
re-ACK 8888bd43c100f9f0ca1122fcc896fb7b999d61c6
naumenkogs:
utACK 8888bd43c100f9f0ca1122fcc896fb7b999d61c6
Tree-SHA512: 32c6cde1c71e943c76b7991c2c24caf29ae467ab4ea2d758483a0cee64625190d1a833b468e8eab1f834beeb2c365af96552c14b05270f08cf63790e0707581d
Diffstat (limited to 'src')
-rw-r--r-- | src/addrman.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index ed823eeb05..204bb544c5 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -66,14 +66,16 @@ 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; - 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 +559,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) |