Skip to content

Commit 488f851

Browse files
committed
Merge pull request #6829
53b86d0 doc: add comment explaining initial header request (Daniel Kraft)
2 parents da7d57f + 53b86d0 commit 488f851

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4955,7 +4955,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
49554955
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
49564956
state.fSyncStarted = true;
49574957
nSyncStarted++;
4958-
CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader;
4958+
const CBlockIndex *pindexStart = pindexBestHeader;
4959+
/* If possible, start at the block preceding the currently
4960+
best known header. This ensures that we always get a
4961+
non-empty list of headers back as long as the peer
4962+
is up-to-date. With a non-empty response, we can initialise
4963+
the peer's known best block. This wouldn't be possible
4964+
if we requested starting at pindexBestHeader and
4965+
got back an empty response. */
4966+
if (pindexStart->pprev)
4967+
pindexStart = pindexStart->pprev;
49594968
LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight);
49604969
pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256());
49614970
}

0 commit comments

Comments
 (0)