@@ -365,7 +365,8 @@ class CAddrMan
365
365
s >> info;
366
366
int nKBucket = info.GetTriedBucket (nKey, m_asmap);
367
367
int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
368
- if (vvTried[nKBucket][nKBucketPos] == -1 ) {
368
+ if (info.IsValid ()
369
+ && vvTried[nKBucket][nKBucketPos] == -1 ) {
369
370
info.nRandomPos = vRandom.size ();
370
371
info.fInTried = true ;
371
372
vRandom.push_back (nIdCount);
@@ -419,6 +420,9 @@ class CAddrMan
419
420
const int entry_index{bucket_entry.second };
420
421
CAddrInfo& info = mapInfo[entry_index];
421
422
423
+ // Don't store the entry in the new bucket if it's not a valid address for our addrman
424
+ if (!info.IsValid ()) continue ;
425
+
422
426
// The entry shouldn't appear in more than
423
427
// ADDRMAN_NEW_BUCKETS_PER_ADDRESS. If it has already, just skip
424
428
// this bucket_entry.
@@ -441,7 +445,7 @@ class CAddrMan
441
445
}
442
446
}
443
447
444
- // Prune new entries with refcount 0 (as a result of collisions).
448
+ // Prune new entries with refcount 0 (as a result of collisions or invalid address ).
445
449
int nLostUnk = 0 ;
446
450
for (auto it = mapInfo.cbegin (); it != mapInfo.cend (); ) {
447
451
if (it->second .fInTried == false && it->second .nRefCount == 0 ) {
@@ -453,11 +457,9 @@ class CAddrMan
453
457
}
454
458
}
455
459
if (nLost + nLostUnk > 0 ) {
456
- LogPrint (BCLog::ADDRMAN, " addrman lost %i new and %i tried addresses due to collisions\n " , nLostUnk, nLost);
460
+ LogPrint (BCLog::ADDRMAN, " addrman lost %i new and %i tried addresses due to collisions or invalid addresses \n " , nLostUnk, nLost);
457
461
}
458
462
459
- RemoveInvalid ();
460
-
461
463
Check ();
462
464
}
463
465
@@ -770,9 +772,6 @@ class CAddrMan
770
772
// ! Update an entry's service bits.
771
773
void SetServices_ (const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs);
772
774
773
- // ! Remove invalid addresses.
774
- void RemoveInvalid () EXCLUSIVE_LOCKS_REQUIRED(cs);
775
-
776
775
friend class CAddrManTest ;
777
776
};
778
777
0 commit comments