Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,648 Lines • ▼ Show 20 Lines | if (!fInitialDownload) { | ||||
// Limit announcements in case of a huge reorganization. Rely on | // Limit announcements in case of a huge reorganization. Rely on | ||||
// the peer's synchronization mechanism in that case. | // the peer's synchronization mechanism in that case. | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Relay inventory, but don't relay old inventory during initial block | // Relay inventory, but don't relay old inventory during initial block | ||||
// download. | // download. | ||||
m_connman.ForEachNode([nNewHeight, &vHashes](CNode *pnode) { | m_connman.ForEachNode([nNewHeight, &vHashes](CNode *pnode) { | ||||
LOCK(pnode->cs_inventory); | |||||
if (nNewHeight > (pnode->nStartingHeight != -1 | if (nNewHeight > (pnode->nStartingHeight != -1 | ||||
? pnode->nStartingHeight - 2000 | ? pnode->nStartingHeight - 2000 | ||||
: 0)) { | : 0)) { | ||||
for (const BlockHash &hash : reverse_iterate(vHashes)) { | for (const BlockHash &hash : reverse_iterate(vHashes)) { | ||||
pnode->PushBlockHash(hash); | pnode->vBlockHashesToAnnounce.push_back(hash); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
m_connman.WakeMessageHandler(); | m_connman.WakeMessageHandler(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | if (send && pindex->nStatus.hasData()) { | ||||
&pfrom, | &pfrom, | ||||
msgMaker.Make(nSendFlags, NetMsgType::BLOCK, *pblock)); | msgMaker.Make(nSendFlags, NetMsgType::BLOCK, *pblock)); | ||||
} | } | ||||
} | } | ||||
// Trigger the peer node to send a getblocks request for the next batch | // Trigger the peer node to send a getblocks request for the next batch | ||||
// of inventory. | // of inventory. | ||||
if (hash == pfrom.hashContinue) { | if (hash == pfrom.hashContinue) { | ||||
// Bypass PushBlockInventory, this must send even if redundant, and | // Send immediately. This must send even if redundant, and | ||||
// we want it right after the last block so they don't wait for | // we want it right after the last block so they don't wait for | ||||
// other stuff first. | // other stuff first. | ||||
std::vector<CInv> vInv; | std::vector<CInv> vInv; | ||||
vInv.push_back( | vInv.push_back( | ||||
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); | CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); | ||||
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | ||||
pfrom.hashContinue = BlockHash(); | pfrom.hashContinue = BlockHash(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,252 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::GETBLOCKS) { | ||||
pindex->nHeight <= ::ChainActive().Tip()->nHeight - | pindex->nHeight <= ::ChainActive().Tip()->nHeight - | ||||
nPrunedBlocksLikelyToHave)) { | nPrunedBlocksLikelyToHave)) { | ||||
LogPrint( | LogPrint( | ||||
BCLog::NET, | BCLog::NET, | ||||
" getblocks stopping, pruned or too old block at %d %s\n", | " getblocks stopping, pruned or too old block at %d %s\n", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString()); | pindex->nHeight, pindex->GetBlockHash().ToString()); | ||||
break; | break; | ||||
} | } | ||||
pfrom.PushBlockInventory(pindex->GetBlockHash()); | WITH_LOCK(pfrom.cs_inventory, pfrom.vInventoryBlockToSend.push_back( | ||||
pindex->GetBlockHash())); | |||||
if (--nLimit <= 0) { | if (--nLimit <= 0) { | ||||
// When this block is requested, we'll send an inv that'll | // When this block is requested, we'll send an inv that'll | ||||
// trigger the peer to getblocks the next batch of inventory. | // trigger the peer to getblocks the next batch of inventory. | ||||
LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", | LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString()); | pindex->nHeight, pindex->GetBlockHash().ToString()); | ||||
pfrom.hashContinue = pindex->GetBlockHash(); | pfrom.hashContinue = pindex->GetBlockHash(); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,884 Lines • ▼ Show 20 Lines | if (pingSend) { | ||||
BCLog::NET, | BCLog::NET, | ||||
"Announcing block %s not on main chain (tip=%s)\n", | "Announcing block %s not on main chain (tip=%s)\n", | ||||
hashToAnnounce.ToString(), | hashToAnnounce.ToString(), | ||||
::ChainActive().Tip()->GetBlockHash().ToString()); | ::ChainActive().Tip()->GetBlockHash().ToString()); | ||||
} | } | ||||
// If the peer's chain has this block, don't inv it back. | // If the peer's chain has this block, don't inv it back. | ||||
if (!PeerHasHeader(&state, pindex)) { | if (!PeerHasHeader(&state, pindex)) { | ||||
pto->PushBlockInventory(hashToAnnounce); | pto->vInventoryBlockToSend.push_back(hashToAnnounce); | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"%s: sending inv peer=%d hash=%s\n", __func__, | "%s: sending inv peer=%d hash=%s\n", __func__, | ||||
pto->GetId(), hashToAnnounce.ToString()); | pto->GetId(), hashToAnnounce.ToString()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
pto->vBlockHashesToAnnounce.clear(); | pto->vBlockHashesToAnnounce.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |