* Update our best height and announce any block hashes which weren't previously * in m_chainman.ActiveChain() to our peers. */
| 1610 | * in m_chainman.ActiveChain() to our peers. |
| 1611 | */ |
| 1612 | void 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 |
no test coverage detected