Skip to content

Commit

Permalink
Fixes bitcoin#941: Rotate vNodes by one peer every 60 seconds when se…
Browse files Browse the repository at this point in the history
…nding messages

We do this only during IBD and this has the effect of distributing
the load more evenly between the peers. Previously, because we are
using PV, the very first peer to connect would always be favored and
we would end up downloading a disproportionate amount of blocks from
that peer during IBD.  However, we still will download more from
some peers based on their download response time performance.
  • Loading branch information
ptschip committed Feb 26, 2018
1 parent a9ac868 commit b1fcec4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,18 @@ void ThreadMessageHandler()
vector<CNode *> vNodesCopy;
{
LOCK(cs_vNodes);

// During IBD and because of the multithreading of PV we end up favoring the first peer that
// connected and end up downloading a disproportionate amount of data from that first peer.
// By rotating vNodes evertime we send messages we can alleviate this problem.
// Rotate every 60 seconds so we don't do this too often.
static int64_t nLastRotation = GetTime();
if (IsInitialBlockDownload() && vNodes.size() > 0 && GetTime() - nLastRotation > 60)
{
std::rotate(vNodes.begin(), vNodes.end() - 1, vNodes.end());
nLastRotation = GetTime();
}

vNodesCopy.reserve(vNodes.size());
for (CNode *pnode : vNodes)
{
Expand Down

0 comments on commit b1fcec4

Please sign in to comment.