* Update our best height and announce any block hashes which weren't previously * in chainActive to our peers. */
| 950 | * in chainActive to our peers. |
| 951 | */ |
| 952 | void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { |
| 953 | const int nNewHeight = pindexNew->nHeight; |
| 954 | connman->SetBestHeight(nNewHeight); |
| 955 | |
| 956 | SetServiceFlagsIBDCache(!fInitialDownload); |
| 957 | if (!fInitialDownload) { |
| 958 | // Find the hashes of all blocks that weren't previously in the best chain. |
| 959 | std::vector<uint256> vHashes; |
| 960 | const CBlockIndex *pindexToAnnounce = pindexNew; |
| 961 | while (pindexToAnnounce != pindexFork) { |
| 962 | vHashes.push_back(pindexToAnnounce->GetBlockHash()); |
| 963 | pindexToAnnounce = pindexToAnnounce->pprev; |
| 964 | if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) { |
| 965 | // Limit announcements in case of a huge reorganization. |
| 966 | // Rely on the peer's synchronization mechanism in that case. |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | // Relay inventory, but don't relay old inventory during initial block download. |
| 971 | connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) { |
| 972 | if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) { |
| 973 | for (const uint256& hash : reverse_iterate(vHashes)) { |
| 974 | pnode->PushBlockHash(hash); |
| 975 | } |
| 976 | } |
| 977 | }); |
| 978 | connman->WakeMessageHandler(); |
| 979 | } |
| 980 | |
| 981 | nTimeBestReceived = GetTime(); |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * Handle invalid block rejection and consequent peer banning, maintain which |
no test coverage detected