Mercurial > hg > bitcoin
changeset 114:837ab126734d draft
minor fix to batched initial download in case requester has more than 500 block non-main branch
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> |
---|---|
date | Tue, 24 Nov 2009 21:04:50 +0000 |
parents | 987d4e9225f9 |
children | 9b5fad6e31e6 |
files | main.cpp main.h serialize.h |
diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/main.cpp +++ b/main.cpp @@ -1960,8 +1960,8 @@ // Send the rest of the chain if (pindex) pindex = pindex->pnext; - printf("getblocks %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,16).c_str()); - int nLimit = 500; + int nLimit = 500 + locator.GetDistanceBack(); + printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,16).c_str(), nLimit); for (; pindex; pindex = pindex->pnext) { if (pindex->GetBlockHash() == hashStop)
--- a/main.h +++ b/main.h @@ -1298,6 +1298,27 @@ vHave.push_back(hashGenesisBlock); } + int GetDistanceBack() + { + // Retrace how far back it was in the sender's branch + int nDistance = 0; + int nStep = 1; + foreach(const uint256& hash, vHave) + { + map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end()) + { + CBlockIndex* pindex = (*mi).second; + if (pindex->IsInMainChain()) + return nDistance; + } + nDistance += nStep; + if (nDistance > 10) + nStep *= 2; + } + return nDistance; + } + CBlockIndex* GetBlockIndex() { // Find the first block the caller has in the main chain