MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / UpdatedBlockTip

Method UpdatedBlockTip

src/net_processing.cpp:2187–2219  ·  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

2185 * in m_chainman.ActiveChain() to our peers.
2186 */
2187void PeerManagerImpl::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
2188{
2189 SetBestBlock(pindexNew->nHeight, std::chrono::seconds{pindexNew->GetBlockTime()});
2190
2191 // Don't relay inventory during initial block download.
2192 if (fInitialDownload) return;
2193
2194 // Find the hashes of all blocks that weren't previously in the best chain.
2195 std::vector<uint256> vHashes;
2196 const CBlockIndex *pindexToAnnounce = pindexNew;
2197 while (pindexToAnnounce != pindexFork) {
2198 vHashes.push_back(pindexToAnnounce->GetBlockHash());
2199 pindexToAnnounce = pindexToAnnounce->pprev;
2200 if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
2201 // Limit announcements in case of a huge reorganization.
2202 // Rely on the peer's synchronization mechanism in that case.
2203 break;
2204 }
2205 }
2206
2207 {
2208 LOCK(m_peer_mutex);
2209 for (auto& it : m_peer_map) {
2210 Peer& peer = *it.second;
2211 LOCK(peer.m_block_inv_mutex);
2212 for (const uint256& hash : vHashes | std::views::reverse) {
2213 peer.m_blocks_for_headers_relay.push_back(hash);
2214 }
2215 }
2216 }
2217
2218 m_connman.WakeMessageHandler();
2219}
2220
2221/**
2222 * Handle invalid block rejection and consequent peer discouragement, maintain which

Callers 1

ActivateBestChainMethod · 0.45

Calls 5

WakeMessageHandlerMethod · 0.80
GetBlockTimeMethod · 0.45
push_backMethod · 0.45
GetBlockHashMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected