Skip to content

Commit 6182d10

Browse files
committed
Do not increment nAttempts by more than one for every Good connection.
This slows the increase of the nAttempts in addrman while partitioned, even if the node hasn't yet noticed the partitioning.
1 parent c769c4a commit 6182d10

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/addrman.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
197197
void CAddrMan::Good_(const CService& addr, int64_t nTime)
198198
{
199199
int nId;
200+
201+
nLastGood = nTime;
202+
200203
CAddrInfo* pinfo = Find(addr, &nId);
201204

202205
// if not found, bail out
@@ -327,7 +330,10 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
327330

328331
// update info
329332
info.nLastTry = nTime;
330-
if (fCountFailure) info.nAttempts++;
333+
if (fCountFailure && info.nLastCountAttempt < nLastGood) {
334+
info.nLastCountAttempt = nTime;
335+
info.nAttempts++;
336+
}
331337
}
332338

333339
CAddrInfo CAddrMan::Select_(bool newOnly)

src/addrman.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class CAddrInfo : public CAddress
2929
//! last try whatsoever by us (memory only)
3030
int64_t nLastTry;
3131

32+
//! last counted attempt (memory only)
33+
int64_t nLastCountAttempt;
34+
3235
private:
3336
//! where knowledge about this address first came from
3437
CNetAddr source;
@@ -66,6 +69,7 @@ class CAddrInfo : public CAddress
6669
{
6770
nLastSuccess = 0;
6871
nLastTry = 0;
72+
nLastCountAttempt = 0;
6973
nAttempts = 0;
7074
nRefCount = 0;
7175
fInTried = false;
@@ -200,6 +204,9 @@ class CAddrMan
200204
//! list of "new" buckets
201205
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
202206

207+
//! last time Good was called (memory only)
208+
int64_t nLastGood;
209+
203210
protected:
204211
//! secret key to randomize bucket select with
205212
uint256 nKey;
@@ -458,6 +465,7 @@ class CAddrMan
458465
nIdCount = 0;
459466
nTried = 0;
460467
nNew = 0;
468+
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
461469
}
462470

463471
CAddrMan()

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ void ThreadOpenConnections()
16331633
}
16341634

16351635
if (addrConnect.IsValid())
1636-
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= min(nMaxConnections - 1, 2), &grant);
1636+
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant);
16371637
}
16381638
}
16391639

0 commit comments

Comments
 (0)