aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Maxwell <gmaxwell@gmail.com>2012-05-06 16:58:31 -0700
committerGregory Maxwell <gmaxwell@gmail.com>2012-05-06 16:58:31 -0700
commitf49d4f0e9397403fcb0d4f1a415bffc8d7c553f1 (patch)
tree1cd5083e3ce61324dd1a9828c33dca4fbe239d48 /src
parent7d5bb4294670a93bf4bdfe458e888a1e0fc7aee0 (diff)
parent686013337339cbcfe0966e662c59fcdb3c22c108 (diff)
downloadbitcoin-f49d4f0e9397403fcb0d4f1a415bffc8d7c553f1.tar.xz
Merge pull request #1196 from sipa/fix_948
Prevent stuck download: correct solution
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c1c57d1d2b..821bfbb476 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2391,6 +2391,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return error("message inv size() = %d", vInv.size());
}
+ // find last block in inv vector
+ unsigned int nLastBlock = (unsigned int)(-1);
+ for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) {
+ if (vInv[vInv.size() - 1 - nInv].type == MSG_BLOCK)
+ nLastBlock = vInv.size() - 1 - nInv;
+ }
CTxDB txdb("r");
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
{
@@ -2407,9 +2413,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// 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))
+ if (fAlreadyHave && nInv == nLastBlock) {
+ // bypass mapAskFor, and send request directly; it must go through.
+ std::vector<CInv> vGetData(1,inv);
+ pfrom->PushMessage("getdata", vGetData);
+ }
+
+ if (!fAlreadyHave)
pfrom->AskFor(inv);
- if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
+ else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));
// Track requests for our stuff