mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Merge eec9366f7d into merged_master (Bitcoin PR #20624)
This commit is contained in:
commit
da04e75e02
1 changed files with 24 additions and 25 deletions
|
|
@ -1290,34 +1290,33 @@ void PeerManager::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_
|
|||
* in ::ChainActive() to our peers.
|
||||
*/
|
||||
void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
||||
const int nNewHeight = pindexNew->nHeight;
|
||||
m_connman.SetBestHeight(nNewHeight);
|
||||
|
||||
m_connman.SetBestHeight(pindexNew->nHeight);
|
||||
SetServiceFlagsIBDCache(!fInitialDownload);
|
||||
if (!fInitialDownload) {
|
||||
// Find the hashes of all blocks that weren't previously in the best chain.
|
||||
std::vector<uint256> vHashes;
|
||||
const CBlockIndex *pindexToAnnounce = pindexNew;
|
||||
while (pindexToAnnounce != pindexFork) {
|
||||
vHashes.push_back(pindexToAnnounce->GetBlockHash());
|
||||
pindexToAnnounce = pindexToAnnounce->pprev;
|
||||
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
|
||||
// Limit announcements in case of a huge reorganization.
|
||||
// Rely on the peer's synchronization mechanism in that case.
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't relay inventory during initial block download.
|
||||
if (fInitialDownload) return;
|
||||
|
||||
// Find the hashes of all blocks that weren't previously in the best chain.
|
||||
std::vector<uint256> vHashes;
|
||||
const CBlockIndex *pindexToAnnounce = pindexNew;
|
||||
while (pindexToAnnounce != pindexFork) {
|
||||
vHashes.push_back(pindexToAnnounce->GetBlockHash());
|
||||
pindexToAnnounce = pindexToAnnounce->pprev;
|
||||
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
|
||||
// Limit announcements in case of a huge reorganization.
|
||||
// Rely on the peer's synchronization mechanism in that case.
|
||||
break;
|
||||
}
|
||||
// Relay inventory, but don't relay old inventory during initial block download.
|
||||
m_connman.ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
|
||||
LOCK(pnode->cs_inventory);
|
||||
if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
|
||||
for (const uint256& hash : reverse_iterate(vHashes)) {
|
||||
pnode->vBlockHashesToAnnounce.push_back(hash);
|
||||
}
|
||||
}
|
||||
});
|
||||
m_connman.WakeMessageHandler();
|
||||
}
|
||||
|
||||
// Relay to all peers
|
||||
m_connman.ForEachNode([&vHashes](CNode* pnode) {
|
||||
LOCK(pnode->cs_inventory);
|
||||
for (const uint256& hash : reverse_iterate(vHashes)) {
|
||||
pnode->vBlockHashesToAnnounce.push_back(hash);
|
||||
}
|
||||
});
|
||||
m_connman.WakeMessageHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue