diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-10-20 12:06:42 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-10-20 12:06:44 +0200 |
commit | 488f8517a15403d48c91dda01f740c82aa64ca63 (patch) | |
tree | d6c84c6750a369b899980e0759ea8b0c0b09b579 | |
parent | da7d57fb9501ad8939a2923f2a60fa540eae8cfa (diff) | |
parent | 53b86d0de5440ffb94f6742e26dd1fd9e11952f2 (diff) |
Merge pull request #6829
53b86d0 doc: add comment explaining initial header request (Daniel Kraft)
-rw-r--r-- | src/main.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index baad7fc050..e931d40c94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4955,7 +4955,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + const CBlockIndex *pindexStart = pindexBestHeader; + /* If possible, start at the block preceding the currently + best known header. This ensures that we always get a + non-empty list of headers back as long as the peer + is up-to-date. With a non-empty response, we can initialise + the peer's known best block. This wouldn't be possible + if we requested starting at pindexBestHeader and + got back an empty response. */ + if (pindexStart->pprev) + pindexStart = pindexStart->pprev; LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } |