aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-03-18 23:47:26 +0100
committerLuke Dashjr <luke-jr+git@utopios.org>2012-05-07 02:44:45 +0000
commiteb3f661add15837434c286476a32e05f279a1919 (patch)
tree973c0add06fc8ad808951be37907b0d834365b7c /src/main.cpp
parent607739befb6d4a647f03ed049b12222b1530f43c (diff)
downloadbitcoin-eb3f661add15837434c286476a32e05f279a1919.tar.xz
Prevent stuck block download in large reorganisations
In cases of very large reorganisations (hundreds of blocks), a situation may appear where an 'inv' is sent as response to a 'getblocks', but the last block mentioned in the inv is already known to the receiver node. However, the supplying node uses a request for this last block as a trigger to send the rest of the inv blocks. If it never comes, the block chain download is stuck. This commit makes the receiver node always request the last inv'ed block, even if it is already known, to prevent this problem.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 67d6638e0e..167e2821c0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2178,8 +2178,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return error("message inv size() = %d", vInv.size());
CTxDB txdb("r");
- BOOST_FOREACH(const CInv& inv, vInv)
+ for (int nInv = 0; nInv < vInv.size(); nInv++)
{
+ const CInv &inv = vInv[nInv];
+
if (fShutdown)
return true;
pfrom->AddInventoryKnown(inv);
@@ -2188,9 +2190,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (fDebug)
printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");
- if (!fAlreadyHave)
+ // Always request the last block in an inv bundle (even if we already have it), as it is the
+ // trigger for the other side to send further invs. If we are stuck on a (very long) side chain,
+ // this is necessary to connect earlier received orphan blocks to the chain again.
+ if (!fAlreadyHave || (inv.type == MSG_BLOCK && nInv==vInv.size()-1))
pfrom->AskFor(inv);
- else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
+ if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));
// Track requests for our stuff