aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-05-18 12:28:07 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-05-18 12:28:19 +0200
commit8e8bebc040a936798472f82043d59a22e2a67928 (patch)
tree819f360200f36ef7c99d2990d137d52ef9a4aa06 /src/main.cpp
parentc74837b724d1d15f9bba0bd0686d478dd6832a17 (diff)
parentf93c2a1b7ee912f0651ebb4c8a5eca220e434f4a (diff)
Merge #8054: net: Avoid duplicate getheaders requests.
f93c2a1 net: Avoid duplicate getheaders requests. (Daniel Kraft)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a1c027bef3..86cc5afc02 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5084,6 +5084,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true;
}
+ // If we already know the last header in the message, then it contains
+ // no new information for us. In this case, we do not request
+ // more headers later. This prevents multiple chains of redundant
+ // getheader requests from running in parallel if triggered by incoming
+ // blocks while the node is still in initial headers sync.
+ const bool hasNewHeaders = (mapBlockIndex.count(headers.back().GetHash()) == 0);
+
CBlockIndex *pindexLast = NULL;
BOOST_FOREACH(const CBlockHeader& header, headers) {
CValidationState state;
@@ -5104,7 +5111,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (pindexLast)
UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash());
- if (nCount == MAX_HEADERS_RESULTS && pindexLast) {
+ if (nCount == MAX_HEADERS_RESULTS && pindexLast && hasNewHeaders) {
// Headers message had its maximum size; the peer may have more headers.
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
// from there instead.