diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-10-14 15:41:23 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-10-14 16:13:42 -0700 |
commit | e11b2ce4c63b87efa60b163b50d155969ccd7e08 (patch) | |
tree | f55b59c79cdbf0665b78cee616ca2776019cad8f /src | |
parent | afc32c5eeada01b141706e32f0405bdb86c00f04 (diff) | |
download | bitcoin-e11b2ce4c63b87efa60b163b50d155969ccd7e08.tar.xz |
Fix large reorgs
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0612f584ac..f5fd7561c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -385,10 +385,11 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl std::vector<CBlockIndex*> vToFetch; CBlockIndex *pindexWalk = state->pindexLastCommonBlock; - // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond our - // current tip. The +1 is so we can detect stalling, namely if we would be able to download that next block if the - // window were 1 larger. - int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, chainActive.Height() + BLOCK_DOWNLOAD_WINDOW + 1); + // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last + // linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to + // download that next block if the window were 1 larger. + int nWindowEnd = state->pindexLastCommonBlock->nHeight + BLOCK_DOWNLOAD_WINDOW; + int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1); NodeId waitingfor = -1; while (pindexWalk->nHeight < nMaxHeight) { // Read up to 128 (or more, if more blocks than that are needed) successors of pindexWalk (towards @@ -411,7 +412,7 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl state->pindexLastCommonBlock = pindex; } else if (mapBlocksInFlight.count(pindex->GetBlockHash()) == 0) { // The block is not already downloaded, and not yet in flight. - if (pindex->nHeight > chainActive.Height() + (int)BLOCK_DOWNLOAD_WINDOW) { + if (pindex->nHeight > nWindowEnd) { // We reached the end of the window. if (vBlocks.size() == 0 && waitingfor != nodeid) { // We aren't able to fetch anything, but we would be if the download window was one larger. |