aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-03-21 12:16:28 -0700
committerGavin Andresen <gavinandresen@gmail.com>2012-03-21 12:16:28 -0700
commitb2fe3a5ca690299a55f52beee3932f0126b79363 (patch)
treee5df3d800e785af5193cd81d47dbb9b1b2ca94a9 /src
parent3979a2ee6c156d183cd0126bce7db352b9234726 (diff)
parent0aa89c08ff271f34271e6fd2eb1ef04afdbcab3a (diff)
Merge pull request #948 from sipa/unstuck
Prevent stuck block download in large reorganisations
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3a78c66b8f..491044eedc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2359,8 +2359,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
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);
@@ -2369,9 +2371,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