aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-05-07 02:46:14 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2012-05-07 02:46:14 +0000
commitafff998ef055fba71bd88b163223255833bf6eb6 (patch)
treea74777b1dada5e7e807545ed10646b98d67298a9 /src/main.cpp
parent293f2644ffd98742caa30b16405b95a6420e8ba0 (diff)
parent2403bb79bc232ea3f9a78448d0fb4ffcf385d209 (diff)
downloadbitcoin-afff998ef055fba71bd88b163223255833bf6eb6.tar.xz
Merge branch '0.4.x' into 0.5.x
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index be4d487208..a5eac010cc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2213,9 +2213,17 @@ 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");
- 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);
@@ -2224,6 +2232,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (fDebug)
printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");
+ // 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 && 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);
else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))