Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,684 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Update our best height and announce any block hashes which weren't previously | * Update our best height and announce any block hashes which weren't previously | ||||
* in ::ChainActive() to our peers. | * in ::ChainActive() to our peers. | ||||
*/ | */ | ||||
void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, | void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, | ||||
const CBlockIndex *pindexFork, | const CBlockIndex *pindexFork, | ||||
bool fInitialDownload) { | bool fInitialDownload) { | ||||
const int nNewHeight = pindexNew->nHeight; | m_connman.SetBestHeight(pindexNew->nHeight); | ||||
m_connman.SetBestHeight(nNewHeight); | |||||
SetServiceFlagsIBDCache(!fInitialDownload); | SetServiceFlagsIBDCache(!fInitialDownload); | ||||
if (!fInitialDownload) { | |||||
// Find the hashes of all blocks that weren't previously in the best | // Don't relay inventory during initial block download. | ||||
// chain. | if (fInitialDownload) { | ||||
return; | |||||
} | |||||
// Find the hashes of all blocks that weren't previously in the best chain. | |||||
std::vector<BlockHash> vHashes; | std::vector<BlockHash> vHashes; | ||||
const CBlockIndex *pindexToAnnounce = pindexNew; | const CBlockIndex *pindexToAnnounce = pindexNew; | ||||
while (pindexToAnnounce != pindexFork) { | while (pindexToAnnounce != pindexFork) { | ||||
vHashes.push_back(pindexToAnnounce->GetBlockHash()); | vHashes.push_back(pindexToAnnounce->GetBlockHash()); | ||||
pindexToAnnounce = pindexToAnnounce->pprev; | pindexToAnnounce = pindexToAnnounce->pprev; | ||||
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) { | if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) { | ||||
// Limit announcements in case of a huge reorganization. Rely on | // Limit announcements in case of a huge reorganization. Rely on the | ||||
// the peer's synchronization mechanism in that case. | // peer's synchronization mechanism in that case. | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Relay inventory, but don't relay old inventory during initial block | |||||
// download. | // Relay to all peers | ||||
m_connman.ForEachNode([nNewHeight, &vHashes](CNode *pnode) { | m_connman.ForEachNode([&vHashes](CNode *pnode) { | ||||
LOCK(pnode->cs_inventory); | LOCK(pnode->cs_inventory); | ||||
if (nNewHeight > (pnode->nStartingHeight != -1 | |||||
? pnode->nStartingHeight - 2000 | |||||
: 0)) { | |||||
for (const BlockHash &hash : reverse_iterate(vHashes)) { | for (const BlockHash &hash : reverse_iterate(vHashes)) { | ||||
pnode->vBlockHashesToAnnounce.push_back(hash); | pnode->vBlockHashesToAnnounce.push_back(hash); | ||||
} | } | ||||
} | |||||
}); | }); | ||||
m_connman.WakeMessageHandler(); | m_connman.WakeMessageHandler(); | ||||
} | } | ||||
} | |||||
/** | /** | ||||
* Handle invalid block rejection and consequent peer banning, maintain which | * Handle invalid block rejection and consequent peer banning, maintain which | ||||
* peers announce compact blocks. | * peers announce compact blocks. | ||||
*/ | */ | ||||
void PeerManager::BlockChecked(const CBlock &block, | void PeerManager::BlockChecked(const CBlock &block, | ||||
const BlockValidationState &state) { | const BlockValidationState &state) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 4,284 Lines • Show Last 20 Lines |