@@ -365,7 +365,8 @@ class CAddrMan
365365 s >> info;
366366 int nKBucket = info.GetTriedBucket (nKey, m_asmap);
367367 int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
368- if (vvTried[nKBucket][nKBucketPos] == -1 ) {
368+ if (info.IsValid ()
369+ && vvTried[nKBucket][nKBucketPos] == -1 ) {
369370 info.nRandomPos = vRandom.size ();
370371 info.fInTried = true ;
371372 vRandom.push_back (nIdCount);
@@ -419,6 +420,9 @@ class CAddrMan
419420 const int entry_index{bucket_entry.second };
420421 CAddrInfo& info = mapInfo[entry_index];
421422
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+
422426 // The entry shouldn't appear in more than
423427 // ADDRMAN_NEW_BUCKETS_PER_ADDRESS. If it has already, just skip
424428 // this bucket_entry.
@@ -441,7 +445,7 @@ class CAddrMan
441445 }
442446 }
443447
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 ).
445449 int nLostUnk = 0 ;
446450 for (auto it = mapInfo.cbegin (); it != mapInfo.cend (); ) {
447451 if (it->second .fInTried == false && it->second .nRefCount == 0 ) {
@@ -453,11 +457,9 @@ class CAddrMan
453457 }
454458 }
455459 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);
457461 }
458462
459- RemoveInvalid ();
460-
461463 Check ();
462464 }
463465
@@ -770,9 +772,6 @@ class CAddrMan
770772 // ! Update an entry's service bits.
771773 void SetServices_ (const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs);
772774
773- // ! Remove invalid addresses.
774- void RemoveInvalid () EXCLUSIVE_LOCKS_REQUIRED(cs);
775-
776775 friend class CAddrManTest ;
777776};
778777
0 commit comments