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

Method UpdatedBlockTip

src/net_processing.cpp:952–982  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

950 * in chainActive to our peers.
951 */
952void 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

Callers 1

ActivateBestChainMethod · 0.45

Calls 10

SetServiceFlagsIBDCacheFunction · 0.85
reverse_iterateFunction · 0.85
GetTimeFunction · 0.85
SetBestHeightMethod · 0.80
ForEachNodeMethod · 0.80
PushBlockHashMethod · 0.80
WakeMessageHandlerMethod · 0.80
push_backMethod · 0.45
GetBlockHashMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected