mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Merge branch '0.4.x' into 0.5.x
This commit is contained in:
19
src/main.cpp
19
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))
|
||||
|
||||
Reference in New Issue
Block a user