|
|
@ -2606,40 +2606,43 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, |
|
|
|
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
|
|
|
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
|
|
|
|
|
|
|
|
|
|
|
// Notifications/callbacks that can run without cs_main
|
|
|
|
// Notifications/callbacks that can run without cs_main
|
|
|
|
if (!fInitialDownload) { |
|
|
|
// Always notify the UI if a new block tip was connected
|
|
|
|
// Find the hashes of all blocks that weren't previously in the best chain.
|
|
|
|
if (pindexFork != pindexNewTip) { |
|
|
|
std::vector<uint256> vHashes; |
|
|
|
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip); |
|
|
|
CBlockIndex *pindexToAnnounce = pindexNewTip; |
|
|
|
|
|
|
|
while (pindexToAnnounce != pindexFork) { |
|
|
|
if (!fInitialDownload) { |
|
|
|
vHashes.push_back(pindexToAnnounce->GetBlockHash()); |
|
|
|
// Find the hashes of all blocks that weren't previously in the best chain.
|
|
|
|
pindexToAnnounce = pindexToAnnounce->pprev; |
|
|
|
std::vector<uint256> vHashes; |
|
|
|
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) { |
|
|
|
CBlockIndex *pindexToAnnounce = pindexNewTip; |
|
|
|
// Limit announcements in case of a huge reorganization.
|
|
|
|
while (pindexToAnnounce != pindexFork) { |
|
|
|
// Rely on the peer's synchronization mechanism in that case.
|
|
|
|
vHashes.push_back(pindexToAnnounce->GetBlockHash()); |
|
|
|
break; |
|
|
|
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.
|
|
|
|
// Relay inventory, but don't relay old inventory during initial block download.
|
|
|
|
int nBlockEstimate = 0; |
|
|
|
int nBlockEstimate = 0; |
|
|
|
if (fCheckpointsEnabled) |
|
|
|
if (fCheckpointsEnabled) |
|
|
|
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints()); |
|
|
|
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints()); |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) { |
|
|
|
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) { |
|
|
|
BOOST_REVERSE_FOREACH(const uint256& hash, vHashes) { |
|
|
|
BOOST_REVERSE_FOREACH(const uint256& hash, vHashes) { |
|
|
|
pnode->PushBlockHash(hash); |
|
|
|
pnode->PushBlockHash(hash); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Notify external listeners about the new tip.
|
|
|
|
// Notify external listeners about the new tip.
|
|
|
|
if (!vHashes.empty()) { |
|
|
|
if (!vHashes.empty()) { |
|
|
|
GetMainSignals().UpdatedBlockTip(pindexNewTip); |
|
|
|
GetMainSignals().UpdatedBlockTip(pindexNewTip); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Always notify the UI if a new block tip was connected
|
|
|
|
|
|
|
|
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip); |
|
|
|
|
|
|
|
} while(pindexMostWork != chainActive.Tip()); |
|
|
|
} while(pindexMostWork != chainActive.Tip()); |
|
|
|
CheckBlockIndex(chainparams.GetConsensus()); |
|
|
|
CheckBlockIndex(chainparams.GetConsensus()); |
|
|
|
|
|
|
|
|
|
|
|