Skip to content

Instantly share code, notes, and snippets.

@brunoerg
Created April 17, 2023 16:25
Show Gist options
  • Select an option

  • Save brunoerg/a00471cfc21139c6f1d4fa44ce4e2ed1 to your computer and use it in GitHub Desktop.

Select an option

Save brunoerg/a00471cfc21139c6f1d4fa44ce4e2ed1 to your computer and use it in GitHub Desktop.
Non-killed mutants for addrman

Not killed mutants

5

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..d033297b1 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -264,7 +264,7 @@ void AddrManImpl::Unserialize(Stream& s_)
     s >> nKey;
     s >> nNew;
     s >> nTried;
-    int nUBuckets = 0;
+    int nUBuckets = 83052;
     s >> nUBuckets;
     if (format >= Format::V1_DETERMINISTIC) {
         nUBuckets ^= (1 << 30);

117

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..4b40092e0 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -873,7 +873,7 @@ void AddrManImpl::ResolveCollisions_()
 
             // Which tried bucket to move the entry to.
             int tried_bucket = info_new.GetTriedBucket(nKey, m_netgroupman);
-            int tried_bucket_pos = info_new.GetBucketPosition(nKey, false, tried_bucket);
+            int tried_bucket_pos = info_new.GetBucketPosition(nKey, true, tried_bucket);
             if (!info_new.IsValid()) { // id_new may no longer map to a valid address
                 erase_collision = true;
             } else if (vvTried[tried_bucket][tried_bucket_pos] != -1) { // The position in the tried bucket is not empty

74

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..474c389e9 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -99,7 +99,7 @@ double AddrInfo::GetChance(NodeSeconds now) const
     }
 
     // deprioritize 66% after each failed attempt, but at most 1/28th to avoid the search taking forever or overly penalizing outages.
-    fChance *= pow(0.66, std::min(nAttempts, 8));
+    fChance *= pow(0.66, std::max(nAttempts, 8));
 
     return fChance;
 }

271

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..411ef76cd 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -500,7 +500,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
     // remove the entry from all new buckets
     const int start_bucket{info.GetNewBucket(nKey, m_netgroupman)};
     for (int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; ++n) {
-        const int bucket{(start_bucket + n) % ADDRMAN_NEW_BUCKET_COUNT};
+        const int bucket{(start_bucket - n) % ADDRMAN_NEW_BUCKET_COUNT};
         const int pos{info.GetBucketPosition(nKey, true, bucket)};
         if (vvNew[bucket][pos] == nId) {
             vvNew[bucket][pos] = -1;

113

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..2ff704664 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -654,7 +654,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
     if (info.fInTried) return false;
 
     // if it is not in new, something bad happened
-    if (!Assume(info.nRefCount > 0)) return false;
+    if (!Assume(info.nRefCount > 0)) return true;
 
 
     // which tried bucket to move the entry to

187

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..a2b2b1d85 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -343,7 +343,7 @@ void AddrManImpl::Unserialize(Stream& s_)
     if (format >= Format::V2_ASMAP) {
         s >> serialized_asmap_checksum;
     }
-    const bool restore_bucketing{nUBuckets == ADDRMAN_NEW_BUCKET_COUNT &&
+    const bool restore_bucketing{nUBuckets != ADDRMAN_NEW_BUCKET_COUNT &&
         serialized_asmap_checksum == supplied_asmap_checksum};
 
     if (!restore_bucketing) {

188

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..72a43038a 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -344,7 +344,7 @@ void AddrManImpl::Unserialize(Stream& s_)
         s >> serialized_asmap_checksum;
     }
     const bool restore_bucketing{nUBuckets == ADDRMAN_NEW_BUCKET_COUNT &&
-        serialized_asmap_checksum == supplied_asmap_checksum};
+        serialized_asmap_checksum != supplied_asmap_checksum};
 
     if (!restore_bucketing) {
         LogPrint(BCLog::ADDRMAN, "Bucketing method was updated, re-bucketing addrman entries from disk\n");

196

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..cefcadbc9 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -505,7 +505,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
         if (vvNew[bucket][pos] == nId) {
             vvNew[bucket][pos] = -1;
             info.nRefCount--;
-            if (info.nRefCount == 0) break;
+            if (info.nRefCount != 0) break;
         }
     }
     nNew--;
(END)

158

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..63c5453ba 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -708,7 +708,7 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, NodeSeconds
 
     // update info
     info.m_last_try = time;
-    if (fCountFailure && info.m_last_count_attempt < m_last_good) {
+    if (fCountFailure && info.m_last_count_attempt > m_last_good) {
         info.m_last_count_attempt = time;
         info.nAttempts++;
     }

134

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..c963c13ab 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -688,7 +688,7 @@ bool AddrManImpl::Add_(const std::vector<CAddress>& vAddr, const CNetAddr& sourc
     for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++) {
         added += AddSingle(*it, source, time_penalty) ? 1 : 0;
     }
-    if (added > 0) {
+    if (added < 0) {
         LogPrint(BCLog::ADDRMAN, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToStringAddr(), nTried, nNew);
     }
     return added > 0;

76

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..6bf0c9209 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -572,7 +572,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
         const bool currently_online{NodeClock::now() - addr.nTime < 24h};
         const auto update_interval{currently_online ? 1h : 24h};
         if (pinfo->nTime < addr.nTime - update_interval - time_penalty) {
-            pinfo->nTime = std::max(NodeSeconds{0s}, addr.nTime - time_penalty);
+            pinfo->nTime = std::min(NodeSeconds{0s}, addr.nTime - time_penalty);
         }
 
         // add services

154

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..2f4d8d980 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -569,7 +569,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
 
     if (pinfo) {
         // periodically update nTime
-        const bool currently_online{NodeClock::now() - addr.nTime < 24h};
+        const bool currently_online{NodeClock::now() - addr.nTime > 24h};
         const auto update_interval{currently_online ? 1h : 24h};
         if (pinfo->nTime < addr.nTime - update_interval - time_penalty) {
             pinfo->nTime = std::max(NodeSeconds{0s}, addr.nTime - time_penalty);

11

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9fbb69a2c 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -381,7 +381,7 @@ void AddrManImpl::Unserialize(Stream& s_)
     }
 
     // Prune new entries with refcount 0 (as a result of collisions or invalid address).
-    int nLostUnk = 0;
+    int nLostUnk = 29943;
     for (auto it = mapInfo.cbegin(); it != mapInfo.cend(); ) {
         if (it->second.fInTried == false && it->second.nRefCount == 0) {
             const auto itCopy = it++;

222

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..7d0301b49 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -669,7 +669,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
         // Output the entry we'd be colliding with, for debugging purposes
         auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
         LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
-                 colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "",
+                 colliding_entry == mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "",
                  addr.ToStringAddrPort(),
                  m_tried_collisions.size());
         return false;

21

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..fddb7e73e 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -592,7 +592,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
             return false;
 
         // stochastic test: previous nRefCount == N: 2^N times harder to increase it
-        int nFactor = 1;
+        int nFactor = 0;
         for (int n = 0; n < pinfo->nRefCount; n++)
             nFactor *= 2;
         if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))

231

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..7ba910dda 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -876,7 +876,7 @@ void AddrManImpl::ResolveCollisions_()
             int tried_bucket_pos = info_new.GetBucketPosition(nKey, false, tried_bucket);
             if (!info_new.IsValid()) { // id_new may no longer map to a valid address
                 erase_collision = true;
-            } else if (vvTried[tried_bucket][tried_bucket_pos] != -1) { // The position in the tried bucket is not empty
+                        } else if (vvTried[tried_bucket][tried_bucket_pos] == -1) { // The position in the tried bucket is not empty
 
                 // Get the to-be-evicted address that is being tested
                 int id_old = vvTried[tried_bucket][tried_bucket_pos];

53

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..0a039c90f 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1104,7 +1104,7 @@ int AddrManImpl::CheckAddrman() const
         return -20;
     }
     for (const auto& [net, count] : m_network_counts) {
-        if (local_counts[net].n_new != count.n_new || local_counts[net].n_tried != count.n_tried) {
+                if (local_counts[net].n_tried != count.n_tried || local_counts[net].n_tried != count.n_tried) {
             return -21;
         }
     }

197

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9351a2ed8 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -563,7 +563,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
     AddrInfo* pinfo = Find(addr, &nId);
 
     // Do not set a penalty for a source's self-announcement
-    if (addr == source) {
+    if (addr != source) {
         time_penalty = 0s;
     }

156

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..fb15473e5 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -593,7 +593,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
 
         // stochastic test: previous nRefCount == N: 2^N times harder to increase it
         int nFactor = 1;
-        for (int n = 0; n < pinfo->nRefCount; n++)
+        for (int n = 0; n > pinfo->nRefCount; n++)
             nFactor *= 2;
         if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
             return false;

110

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..1f54b2ffd 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -596,7 +596,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
         for (int n = 0; n < pinfo->nRefCount; n++)
             nFactor *= 2;
         if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
-            return false;
+            return true;
     } else {
         pinfo = Create(addr, source, &nId);
         pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime - time_penalty);

120

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..15ec0901c 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -906,7 +906,7 @@ void AddrManImpl::ResolveCollisions_()
                     erase_collision = true;
                 }
             } else { // Collision is not actually a collision anymore
-                Good_(info_new, false, Now<NodeSeconds>());
+                Good_(info_new, true, Now<NodeSeconds>());
                 erase_collision = true;
             }
         }

130

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..4aee80c8f 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -391,7 +391,7 @@ void AddrManImpl::Unserialize(Stream& s_)
             ++it;
         }
     }
-    if (nLost + nLostUnk > 0) {
+    if (nLost + nLostUnk < 0) {
         LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
     }

116

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..3b32ce4af 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -863,7 +863,7 @@ void AddrManImpl::ResolveCollisions_()
     for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
         int id_new = *it;
 
-        bool erase_collision = false;
+        bool erase_collision = true;
 
         // If id_new not found in mapInfo remove it from m_tried_collisions
         if (mapInfo.count(id_new) != 1) {

111

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..ccda82d45 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -639,7 +639,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
     AddrInfo* pinfo = Find(addr, &nId);
 
     // if not found, bail out
-    if (!pinfo) return false;
+        if (!pinfo) return true;
 
     AddrInfo& info = *pinfo;

91

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..6a205e936 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -867,7 +867,7 @@ void AddrManImpl::ResolveCollisions_()
 
         // If id_new not found in mapInfo remove it from m_tried_collisions
         if (mapInfo.count(id_new) != 1) {
-            erase_collision = true;
+            erase_collision = false;
         } else {
             AddrInfo& info_new = mapInfo[id_new];

200

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..8c4f434ea 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -608,7 +608,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
     if (vvNew[nUBucket][nUBucketPos] != nId) {
         if (!fInsert) {
             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {
+            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount != 0)) {
                 // Overwrite the existing new table entry.
                 fInsert = true;
             }

141

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..dc6a4b3e7 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -94,7 +94,7 @@ double AddrInfo::GetChance(NodeSeconds now) const
     double fChance = 1.0;
 
     // deprioritize very recent attempts away
-    if (now - m_last_try < 10min) {
+        if (now - m_last_try > 10min) {
         fChance *= 0.01;
     }

308

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..7a28c354d 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -599,7 +599,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
             return false;
     } else {
         pinfo = Create(addr, source, &nId);
-        pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime - time_penalty);
+        pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime + time_penalty);
     }
 
     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);

69

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..38a376a28 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -361,7 +361,7 @@ void AddrManImpl::Unserialize(Stream& s_)
         // The entry shouldn't appear in more than
         // ADDRMAN_NEW_BUCKETS_PER_ADDRESS. If it has already, just skip
         // this bucket_entry.
-        if (info.nRefCount >= ADDRMAN_NEW_BUCKETS_PER_ADDRESS) continue;
+        if (info.nRefCount >= ADDRMAN_NEW_BUCKETS_PER_ADDRESS) break;
 
         int bucket_position = info.GetBucketPosition(nKey, true, bucket);
         if (restore_bucketing && vvNew[bucket][bucket_position] == -1) {

92

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..27382d821 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -875,7 +875,7 @@ void AddrManImpl::ResolveCollisions_()
             int tried_bucket = info_new.GetTriedBucket(nKey, m_netgroupman);
             int tried_bucket_pos = info_new.GetBucketPosition(nKey, false, tried_bucket);
             if (!info_new.IsValid()) { // id_new may no longer map to a valid address
-                erase_collision = true;
+                erase_collision = false;
             } else if (vvTried[tried_bucket][tried_bucket_pos] != -1) { // The position in the tried bucket is not empty
 
                 // Get the to-be-evicted address that is being tested

14

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..e1fad328c 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -593,7 +593,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
 
         // stochastic test: previous nRefCount == N: 2^N times harder to increase it
         int nFactor = 1;
-        for (int n = 0; n < pinfo->nRefCount; n++)
+        for (int n = 2161; n < pinfo->nRefCount; n++)
             nFactor *= 2;
         if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
             return false;

80

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..04e40268e 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -79,7 +79,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const
     }
 
     if (TicksSinceEpoch<std::chrono::seconds>(m_last_success) == 0 && nAttempts >= ADDRMAN_RETRIES) { // tried N times and never a success
-        return true;
+                return false;
     }
 
     if (now - m_last_success > ADDRMAN_MIN_FAIL && nAttempts >= ADDRMAN_MAX_FAILURES) { // N successive failures in the last week

132

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9b1240b7a 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -608,7 +608,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
     if (vvNew[nUBucket][nUBucketPos] != nId) {
         if (!fInsert) {
             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {
+            if (infoExisting.IsTerrible() || (infoExisting.nRefCount < 1 && pinfo->nRefCount == 0)) {
                 // Overwrite the existing new table entry.
                 fInsert = true;
             }

81

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..b7886138d 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -83,7 +83,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const
     }
 
     if (now - m_last_success > ADDRMAN_MIN_FAIL && nAttempts >= ADDRMAN_MAX_FAILURES) { // N successive failures in the last week
-        return true;
+                return false;
     }
 
     return false;

63

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9865b5665 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -528,7 +528,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
         infoOld.fInTried = false;
         vvTried[nKBucket][nKBucketPos] = -1;
         nTried--;
-        m_network_counts[infoOld.GetNetwork()].n_tried--;
+                m_network_counts[NET_INTERNAL].n_tried--;
 
         // find which new bucket it belongs to
         int nUBucket = infoOld.GetNewBucket(nKey, m_netgroupman);

78

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..e1309ea87 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -71,7 +71,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const
     }
 
     if (nTime > now + 10min) { // came in a flying DeLorean
-        return true;
+                return false;
     }
 
     if (now - nTime > ADDRMAN_HORIZON) { // not seen in recent history

73

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..0b0fa31ac 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -813,7 +813,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
         if (network != std::nullopt && ai.GetNetClass() != network) continue;
 
         // Filter for quality
-        if (ai.IsTerrible(now)) continue;
+        if (ai.IsTerrible(now)) break;
 
         addresses.push_back(ai);
     }

266

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..8c16fd3f2 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -391,7 +391,7 @@ void AddrManImpl::Unserialize(Stream& s_)
             ++it;
         }
     }
-    if (nLost + nLostUnk > 0) {
+    if (nLost - nLostUnk > 0) {
         LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
     }

131

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..8c16fd3f2 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -391,7 +391,7 @@ void AddrManImpl::Unserialize(Stream& s_)
             ++it;
         }
     }
-    if (nLost + nLostUnk > 0) {
+    if (nLost - nLostUnk > 0) {
         LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
     }

160

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..822f3db46 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -745,7 +745,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
             assert(it_found != mapInfo.end());
             const AddrInfo& info{it_found->second};
             // With probability GetChance() * fChanceFactor, return the entry.
-            if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
+                        if (insecure_rand.randbits(30) > fChanceFactor * info.GetChance() * (1 << 30)) {
                 LogPrint(BCLog::ADDRMAN, "Selected %s from tried\n", info.ToStringAddrPort());
                 return {info, info.m_last_try};
             }

108

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..4b424d827 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -585,7 +585,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
 
         // do not update if the entry was already in the "tried" table
         if (pinfo->fInTried)
-            return false;
+            return true;
 
         // do not update if the max reference count is reached
         if (pinfo->nRefCount == ADDRMAN_NEW_BUCKETS_PER_ADDRESS)

127

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..5aa31909a 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -254,7 +254,7 @@ void AddrManImpl::Unserialize(Stream& s_)
             compat, INCOMPATIBILITY_BASE));
     }
     const uint8_t lowest_compatible = compat - INCOMPATIBILITY_BASE;
-    if (lowest_compatible > FILE_FORMAT) {
+    if (lowest_compatible < FILE_FORMAT) {
         throw InvalidAddrManVersionError(strprintf(
             "Unsupported format of addrman database: %u. It is compatible with formats >=%u, "
             "but the maximum supported by this version of %s is %u.",

45

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..fc4c9258e 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -540,7 +540,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
         infoOld.nRefCount = 1;
         vvNew[nUBucket][nUBucketPos] = nIdEvict;
         nNew++;
-        m_network_counts[infoOld.GetNetwork()].n_new++;
+                m_network_counts[infoOld.GetNetwork()].n_tried++;
         LogPrint(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
                  infoOld.ToStringAddrPort(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
     }

307

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..fa0138b73 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -572,7 +572,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
         const bool currently_online{NodeClock::now() - addr.nTime < 24h};
         const auto update_interval{currently_online ? 1h : 24h};
         if (pinfo->nTime < addr.nTime - update_interval - time_penalty) {
-            pinfo->nTime = std::max(NodeSeconds{0s}, addr.nTime - time_penalty);
+                        pinfo->nTime = std::max(NodeSeconds{0s}, addr.nTime + time_penalty);
         }
 
         // add services

189

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..957b633c1 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -364,7 +364,7 @@ void AddrManImpl::Unserialize(Stream& s_)
         if (info.nRefCount >= ADDRMAN_NEW_BUCKETS_PER_ADDRESS) continue;
 
         int bucket_position = info.GetBucketPosition(nKey, true, bucket);
-        if (restore_bucketing && vvNew[bucket][bucket_position] == -1) {
+        if (restore_bucketing && vvNew[bucket][bucket_position] != -1) {
             // Bucketing has not changed, using existing bucket positions for the new table
             vvNew[bucket][bucket_position] = entry_index;
             ++info.nRefCount;

185

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..1cb163c81 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -78,7 +78,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const
         return true;
     }
 
-    if (TicksSinceEpoch<std::chrono::seconds>(m_last_success) == 0 && nAttempts >= ADDRMAN_RETRIES) { // tried N times and never a success
+        if (TicksSinceEpoch<std::chrono::seconds>(m_last_success) != 0 && nAttempts >= ADDRMAN_RETRIES) { // tried N times and never a success
         return true;
     }

106

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..17b31cfa9 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -557,7 +557,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
     AssertLockHeld(cs);
 
     if (!addr.IsRoutable())
-        return false;
+        return true;
 
     int nId;
     AddrInfo* pinfo = Find(addr, &nId);

126

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..b4da527e2 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -82,7 +82,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const
         return true;
     }
 
-    if (now - m_last_success > ADDRMAN_MIN_FAIL && nAttempts >= ADDRMAN_MAX_FAILURES) { // N successive failures in the last week
+        if (now - m_last_success < ADDRMAN_MIN_FAIL && nAttempts >= ADDRMAN_MAX_FAILURES) { // N successive failures in the last week
         return true;
     }

219

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..92fb0ab87 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -595,7 +595,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
         int nFactor = 1;
         for (int n = 0; n < pinfo->nRefCount; n++)
             nFactor *= 2;
-        if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
+        if (nFactor > 1 && (insecure_rand.randrange(nFactor) == 0))
             return false;
     } else {
         pinfo = Create(addr, source, &nId);

96

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9f73cf881 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -907,7 +907,7 @@ void AddrManImpl::ResolveCollisions_()
                 }
             } else { // Collision is not actually a collision anymore
                 Good_(info_new, false, Now<NodeSeconds>());
-                erase_collision = true;
+                erase_collision = false;
             }
         }

109

diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..6639e893e 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -589,7 +589,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
 
         // do not update if the max reference count is reached
         if (pinfo->nRefCount == ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
-            return false;
+            return true;
 
         // stochastic test: previous nRefCount == N: 2^N times harder to increase it
         int nFactor = 1;
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..eb2722118 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -470,7 +470,7 @@ void AddrManImpl::Delete(int nId)
     SwapRandom(info.nRandomPos, vRandom.size() - 1);
     m_network_counts[info.GetNetwork()].n_new--;
     vRandom.pop_back();
-    mapAddr.erase(info);
+
     mapInfo.erase(nId);
     nNew--;
 }
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..49f61fb3b 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -651,7 +651,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
     // currently-connected peers.
 
     // if it is already in the tried set, don't do anything else
-    if (info.fInTried) return false;
+
 
     // if it is not in new, something bad happened
     if (!Assume(info.nRefCount > 0)) return false;
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..84417e9b8 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1068,7 +1068,7 @@ int AddrManImpl::CheckAddrman() const
                 if (it == mapInfo.end() || it->second.GetTriedBucket(nKey, m_netgroupman) != n) {
                     return -17;
                 }
-                if (it->second.GetBucketPosition(nKey, false, n) != i) {
+                if (it->second.GetBucketPosition(nKey, false, n) != i) {break;
                     return -18;
                 }
                 setTried.erase(vvTried[n][i]);
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..ea527f226 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1046,7 +1046,7 @@ int AddrManImpl::CheckAddrman() const
         }
         if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
             return -14;
-        if (info.m_last_try < NodeSeconds{0s}) {
+        if (info.m_last_try < NodeSeconds{0s}) {break;
             return -6;
         }
         if (info.m_last_success < NodeSeconds{0s}) {
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..8d85e553a 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1104,7 +1104,7 @@ int AddrManImpl::CheckAddrman() const
         return -20;
     }
     for (const auto& [net, count] : m_network_counts) {
-        if (local_counts[net].n_new != count.n_new || local_counts[net].n_tried != count.n_tried) {
+        if (local_counts[net].n_new != count.n_new || local_counts[net].n_tried != count.n_tried) {break;
             return -21;
         }
     }
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..f206109c4 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -953,7 +953,7 @@ std::optional<AddressPosition> AddrManImpl::FindAddressEntry_(const CAddress& ad
 
     AddrInfo* addr_info = Find(addr);
 
-    if (!addr_info) return std::nullopt;
+    
 
     if(addr_info->fInTried) {
         int bucket{addr_info->GetTriedBucket(nKey, m_netgroupman)};
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..b051e2056 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1049,7 +1049,7 @@ int AddrManImpl::CheckAddrman() const
         if (info.m_last_try < NodeSeconds{0s}) {
             return -6;
         }
-        if (info.m_last_success < NodeSeconds{0s}) {
+        if (info.m_last_success < NodeSeconds{0s}) {break;
             return -8;
         }
     }
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..a5bd589a3 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -933,7 +933,6 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::SelectTriedCollision_()
 
     // If id_new not found in mapInfo remove it from m_tried_collisions
     if (mapInfo.count(id_new) != 1) {
-        m_tried_collisions.erase(it);
         return {};
     }
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..0f8b93d42 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -654,7 +654,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
     if (info.fInTried) return false;
 
     // if it is not in new, something bad happened
-    if (!Assume(info.nRefCount > 0)) return false;
+    
 
 
     // which tried bucket to move the entry to
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..eaefc42a8 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -998,7 +998,7 @@ void AddrManImpl::Check() const
 
     // Run consistency checks 1 in m_consistency_check_ratio times if enabled
     if (m_consistency_check_ratio == 0) return;
-    if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
+    
 
     const int err{CheckAddrman()};
     if (err) {
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..9daf205ab 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1041,7 +1041,7 @@ int AddrManImpl::CheckAddrman() const
             local_counts[info.GetNetwork()].n_new++;
         }
         const auto it{mapAddr.find(info)};
-        if (it == mapAddr.end() || it->second != n) {
+                if (it == mapAddr.end() || it->second != n) {break;
             return -5;
         }
         if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..eaefc42a8 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -998,7 +998,7 @@ void AddrManImpl::Check() const
 
     // Run consistency checks 1 in m_consistency_check_ratio times if enabled
     if (m_consistency_check_ratio == 0) return;
-    if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
+    
 
     const int err{CheckAddrman()};
     if (err) {
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..bb630c905 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -866,7 +866,7 @@ void AddrManImpl::ResolveCollisions_()
         bool erase_collision = false;
 
         // If id_new not found in mapInfo remove it from m_tried_collisions
-        if (mapInfo.count(id_new) != 1) {
+                if (mapInfo.count(id_new) != 1) {break;
             erase_collision = true;
         } else {
             AddrInfo& info_new = mapInfo[id_new];
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..cc946380f 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -813,7 +813,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
         if (network != std::nullopt && ai.GetNetClass() != network) continue;
 
         // Filter for quality
-        if (ai.IsTerrible(now)) continue;
+        
 
         addresses.push_back(ai);
     }
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c3..a1f091cc1 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -361,7 +361,7 @@ void AddrManImpl::Unserialize(Stream& s_)
         // The entry shouldn't appear in more than
         // ADDRMAN_NEW_BUCKETS_PER_ADDRESS. If it has already, just skip
         // this bucket_entry.
-        if (info.nRefCount >= ADDRMAN_NEW_BUCKETS_PER_ADDRESS) continue;
+        
 
         int bucket_position = info.GetBucketPosition(nKey, true, bucket);
         if (restore_bucketing && vvNew[bucket][bucket_position] == -1) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment