aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-11-24 21:04:50 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-11-24 21:04:50 +0000
commit52f4cb48590a706caf7a492e8d94b85620d5cd33 (patch)
treeb394260db71c75751026b76be87c3703eddf437c
parentc5c7911dab8732861affbe66849a100da62f7464 (diff)
downloadbitcoin-52f4cb48590a706caf7a492e8d94b85620d5cd33.tar.xz
minor fix to batched initial download in case requester has more than 500 block non-main branch
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@41 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--main.cpp4
-rw-r--r--main.h21
-rw-r--r--serialize.h2
3 files changed, 24 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 89b42f76e0..ae20e08dd0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1960,8 +1960,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// 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)
diff --git a/main.h b/main.h
index 79f14c6861..822045a573 100644
--- a/main.h
+++ b/main.h
@@ -1298,6 +1298,27 @@ public:
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
diff --git a/serialize.h b/serialize.h
index aae821b6d2..b2d948df96 100644
--- a/serialize.h
+++ b/serialize.h
@@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile;
static const int VERSION = 106;
-static const char* pszSubVer = " linux-test8";
+static const char* pszSubVer = " linux-test9";