Skip to content

Commit 9edc513

Browse files
committed
Merge bitcoin/bitcoin#25303: refactor: Remove redundant addrman time checks
8888bd4 Remove redundant nLastTry check (MarcoFalke) 00001e5 Remove redundant nTime checks (MarcoFalke) Pull request description: Split out from bitcoin/bitcoin#24697 because it makes sense on its own. ACKs for top commit: dergoegge: re-ACK 8888bd4 naumenkogs: utACK 8888bd4 Tree-SHA512: 32c6cde1c71e943c76b7991c2c24caf29ae467ab4ea2d758483a0cee64625190d1a833b468e8eab1f834beeb2c365af96552c14b05270f08cf63790e0707581d
2 parents 455780b + 8888bd4 commit 9edc513

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/addrman.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) con
6666

6767
bool AddrInfo::IsTerrible(int64_t nNow) const
6868
{
69-
if (nLastTry && nLastTry >= nNow - 60) // never remove things tried in the last minute
69+
if (nNow - nLastTry <= 60) { // never remove things tried in the last minute
7070
return false;
71+
}
7172

7273
if (nTime > nNow + 10 * 60) // came in a flying DeLorean
7374
return true;
7475

75-
if (nTime == 0 || nNow - nTime > ADDRMAN_HORIZON_DAYS * 24 * 60 * 60) // not seen in recent history
76+
if (nNow - nTime > ADDRMAN_HORIZON_DAYS * 24 * 60 * 60) { // not seen in recent history
7677
return true;
78+
}
7779

7880
if (nLastSuccess == 0 && nAttempts >= ADDRMAN_RETRIES) // tried N times and never a success
7981
return true;
@@ -557,15 +559,17 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
557559
// periodically update nTime
558560
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
559561
int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
560-
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
562+
if (pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty) {
561563
pinfo->nTime = std::max((int64_t)0, addr.nTime - nTimePenalty);
564+
}
562565

563566
// add services
564567
pinfo->nServices = ServiceFlags(pinfo->nServices | addr.nServices);
565568

566569
// do not update if no new information is present
567-
if (!addr.nTime || (pinfo->nTime && addr.nTime <= pinfo->nTime))
570+
if (addr.nTime <= pinfo->nTime) {
568571
return false;
572+
}
569573

570574
// do not update if the entry was already in the "tried" table
571575
if (pinfo->fInTried)

0 commit comments

Comments
 (0)