Skip to content

Commit ff38148

Browse files
committed
Merge #15486: [addrman, net] Ensure tried collisions resolve, and allow feeler connections to existing outbound netgroups
20e6ea2 [addrman] Improve collision logging and address nits (Suhas Daftuar) f71fdda [addrman] Ensure collisions eventually get resolved (Suhas Daftuar) 4991e3c [net] feeler connections can be made to outbound peers in same netgroup (Suhas Daftuar) 4d83401 [addrman] Improve tried table collision logging (Suhas Daftuar) Pull request description: The restriction on outbound peers sharing the same network group is not intended to apply to feeler connections, so fix this. This fixes an issue where a tried table collision with an entry to a netgroup we already have an outbound connection to could cause feelers to stop working, because the tried collision buffer (`m_tried_collisions`) would never be drained. Also, ensure that all entries don't linger in `m_tried_collisions` by evicting an old entry if its collisions is unresolved after 40 minutes. Tree-SHA512: 553fe2b01b82cd7f0f62f90c6781e373455a45b254e3bec085b5e6b16690aa9f3938e8c50e7136f19dafa250ed4578a26227d944b76daf9ce4ef0c75802389b6
2 parents 12408d3 + 20e6ea2 commit ff38148

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/addrman.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
239239

240240
// Will moving this address into tried evict another entry?
241241
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) {
242-
LogPrint(BCLog::ADDRMAN, "Collision inserting element into tried table, moving %s to m_tried_collisions=%d\n", addr.ToString(), m_tried_collisions.size());
242+
// Output the entry we'd be colliding with, for debugging purposes
243+
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
244+
LogPrint(BCLog::ADDRMAN, "Collision inserting element into tried table (%s), moving %s to m_tried_collisions=%d\n", colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "", addr.ToString(), m_tried_collisions.size());
243245
if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
244246
m_tried_collisions.insert(nId);
245247
}
@@ -561,12 +563,19 @@ void CAddrMan::ResolveCollisions_()
561563

562564
// Give address at least 60 seconds to successfully connect
563565
if (GetAdjustedTime() - info_old.nLastTry > 60) {
564-
LogPrint(BCLog::ADDRMAN, "Swapping %s for %s in tried table\n", info_new.ToString(), info_old.ToString());
566+
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());
565567

566568
// Replaces an existing address already in the tried table with the new address
567569
Good_(info_new, false, GetAdjustedTime());
568570
erase_collision = true;
569571
}
572+
} else if (GetAdjustedTime() - info_new.nLastSuccess > ADDRMAN_TEST_WINDOW) {
573+
// If the collision hasn't resolved in some reasonable amount of time,
574+
// just evict the old entry -- we must not be able to
575+
// connect to it for some reason.
576+
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToString(), info_new.ToString());
577+
Good_(info_new, false, GetAdjustedTime());
578+
erase_collision = true;
570579
}
571580
} else { // Collision is not actually a collision anymore
572581
Good_(info_new, false, GetAdjustedTime());

src/addrman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class CAddrInfo : public CAddress
166166
//! the maximum number of tried addr collisions to store
167167
#define ADDRMAN_SET_TRIED_COLLISION_SIZE 10
168168

169+
//! the maximum time we'll spend trying to resolve a tried table collision, in seconds
170+
static const int64_t ADDRMAN_TEST_WINDOW = 40*60; // 40 minutes
171+
169172
/**
170173
* Stochastical (IP) address manager
171174
*/

src/net.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,9 +1765,15 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17651765
addr = addrman.Select(fFeeler);
17661766
}
17671767

1768-
// if we selected an invalid address, restart
1769-
if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr))
1768+
// Require outbound connections, other than feelers, to be to distinct network groups
1769+
if (!fFeeler && setConnected.count(addr.GetGroup())) {
17701770
break;
1771+
}
1772+
1773+
// if we selected an invalid or local address, restart
1774+
if (!addr.IsValid() || IsLocal(addr)) {
1775+
break;
1776+
}
17711777

17721778
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
17731779
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates

0 commit comments

Comments
 (0)