Skip to content

Commit 8e8bebc

Browse files
committed
Merge #8054: net: Avoid duplicate getheaders requests.
f93c2a1 net: Avoid duplicate getheaders requests. (Daniel Kraft)
2 parents c74837b + f93c2a1 commit 8e8bebc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5084,6 +5084,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50845084
return true;
50855085
}
50865086

5087+
// If we already know the last header in the message, then it contains
5088+
// no new information for us. In this case, we do not request
5089+
// more headers later. This prevents multiple chains of redundant
5090+
// getheader requests from running in parallel if triggered by incoming
5091+
// blocks while the node is still in initial headers sync.
5092+
const bool hasNewHeaders = (mapBlockIndex.count(headers.back().GetHash()) == 0);
5093+
50875094
CBlockIndex *pindexLast = NULL;
50885095
BOOST_FOREACH(const CBlockHeader& header, headers) {
50895096
CValidationState state;
@@ -5104,7 +5111,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51045111
if (pindexLast)
51055112
UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash());
51065113

5107-
if (nCount == MAX_HEADERS_RESULTS && pindexLast) {
5114+
if (nCount == MAX_HEADERS_RESULTS && pindexLast && hasNewHeaders) {
51085115
// Headers message had its maximum size; the peer may have more headers.
51095116
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
51105117
// from there instead.

0 commit comments

Comments
 (0)