Skip to content

Commit

Permalink
Do not increment nAttempts by more than one for every Good connection.
Browse files Browse the repository at this point in the history
This slows the increase of the nAttempts in addrman while partitioned,
 even if the node hasn't yet noticed the partitioning.
  • Loading branch information
gmaxwell authored and Fuzzbawls committed Mar 24, 2020
1 parent b988ce6 commit 40e4116
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
void CAddrMan::Good_(const CService& addr, int64_t nTime)
{
int nId;

nLastGood = nTime;

CAddrInfo* pinfo = Find(addr, &nId);

// if not found, bail out
Expand Down Expand Up @@ -329,7 +332,10 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)

// update info
info.nLastTry = nTime;
if (fCountFailure) info.nAttempts++;
if (fCountFailure && info.nLastCountAttempt < nLastGood) {
info.nLastCountAttempt = nTime;
info.nAttempts++;
}
}

CAddrInfo CAddrMan::Select_(bool newOnly)
Expand Down
8 changes: 8 additions & 0 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class CAddrInfo : public CAddress
//! last try whatsoever by us (memory only)
int64_t nLastTry;

//! last counted attempt (memory only)
int64_t nLastCountAttempt;

private:
//! where knowledge about this address first came from
CNetAddr source;
Expand Down Expand Up @@ -67,6 +70,7 @@ class CAddrInfo : public CAddress
{
nLastSuccess = 0;
nLastTry = 0;
nLastCountAttempt = 0;
nAttempts = 0;
nRefCount = 0;
fInTried = false;
Expand Down Expand Up @@ -205,6 +209,9 @@ class CAddrMan
//! list of "new" buckets
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];

//! last time Good was called (memory only)
int64_t nLastGood;

protected:
//! secret key to randomize bucket select with
uint256 nKey;
Expand Down Expand Up @@ -458,6 +465,7 @@ class CAddrMan
nIdCount = 0;
nTried = 0;
nNew = 0;
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
}

CAddrMan()
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ void ThreadOpenConnections()
}

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

Expand Down

0 comments on commit 40e4116

Please sign in to comment.