MCPcopy Create free account
hub / github.com/ElementsProject/elements / UpdatedBlockTip

Method UpdatedBlockTip

src/net_processing.cpp:1612–1645  ·  view source on GitHub ↗

* Update our best height and announce any block hashes which weren't previously * in m_chainman.ActiveChain() to our peers. */

Source from the content-addressed store, hash-verified

1610 * in m_chainman.ActiveChain() to our peers.
1611 */
1612void PeerManagerImpl::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
1613{
1614 SetBestHeight(pindexNew->nHeight);
1615 SetServiceFlagsIBDCache(!fInitialDownload);
1616
1617 // Don't relay inventory during initial block download.
1618 if (fInitialDownload) return;
1619
1620 // Find the hashes of all blocks that weren't previously in the best chain.
1621 std::vector<uint256> vHashes;
1622 const CBlockIndex *pindexToAnnounce = pindexNew;
1623 while (pindexToAnnounce != pindexFork) {
1624 vHashes.push_back(pindexToAnnounce->GetBlockHash());
1625 pindexToAnnounce = pindexToAnnounce->pprev;
1626 if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
1627 // Limit announcements in case of a huge reorganization.
1628 // Rely on the peer's synchronization mechanism in that case.
1629 break;
1630 }
1631 }
1632
1633 {
1634 LOCK(m_peer_mutex);
1635 for (auto& it : m_peer_map) {
1636 Peer& peer = *it.second;
1637 LOCK(peer.m_block_inv_mutex);
1638 for (const uint256& hash : reverse_iterate(vHashes)) {
1639 peer.m_blocks_for_headers_relay.push_back(hash);
1640 }
1641 }
1642 }
1643
1644 m_connman.WakeMessageHandler();
1645}
1646
1647/**
1648 * Handle invalid block rejection and consequent peer discouragement, maintain which

Callers 1

ActivateBestChainMethod · 0.45

Calls 6

SetServiceFlagsIBDCacheFunction · 0.85
reverse_iterateFunction · 0.85
WakeMessageHandlerMethod · 0.80
push_backMethod · 0.45
GetBlockHashMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected