Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
6501}6503// Check that outbound peers have reasonable chains6504// GetTime() is used by this anti-DoS logic so we can test this using mocktime6505ConsiderEviction(node, peer, GetTime<std::chrono::seconds>());6507//6508// Message: getdata (blocks)6509//6510std::vector<CInv> vGetData;6511if (CanServeBlocks(peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer(peer)) || !m_chainman.IsInitialBlockDownload()) && state.vBlocksInFlight.size() < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {6512std::vector<const CBlockIndex*> vToDownload;6513NodeId staller = -1;6514auto get_inflight_budget = [&state]() {6515return std::max(0, MAX_BLOCKS_IN_TRANSIT_PER_PEER - static_cast<int>(state.vBlocksInFlight.size()));6516};6518// If there are multiple chainstates, download blocks for the6519// current chainstate first, to prioritize getting to network tip6520// before downloading historical blocks.6521FindNextBlocksToDownload(peer, get_inflight_budget(), vToDownload, staller);6522auto historical_blocks{m_chainman.GetHistoricalBlockRange()};6523if (historical_blocks && !IsLimitedPeer(peer)) {6524// If the first needed historical block is not an ancestor of the last,6525// we need to start requesting blocks from their last common ancestor.6526const CBlockIndex* from_tip = LastCommonAncestor(historical_blocks->first, historical_blocks->second);6527TryDownloadingHistoricalBlocks(6528peer,6529get_inflight_budget(),6530vToDownload, from_tip, historical_blocks->second);6531}6532for (const CBlockIndex *pindex : vToDownload) {6533uint32_t nFetchFlags = GetFetchFlags(peer);6534vGetData.emplace_back(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash());6535BlockRequested(node.GetId(), *pindex);6536LogDebug(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),6537pindex->nHeight, node.GetId());6538}6539if (state.vBlocksInFlight.empty() && staller != -1) {6540if (State(staller)->m_stalling_since == 0us) {6541State(staller)->m_stalling_since = current_time;6542LogDebug(BCLog::NET, "Stall started peer=%d\n", staller);6543}6544}6545}6547//6548// Message: getdata (transactions)6549//6550{6551LOCK(m_tx_download_mutex);6552for (const GenTxid& gtxid : m_txdownloadman.GetRequestsToSend(node.GetId(), current_time)) {6553vGetData.emplace_back(gtxid.IsWtxid() ? MSG_WTX : (MSG_TX | GetFetchFlags(peer)), gtxid.ToUint256());6554if (vGetData.size() >= MAX_GETDATA_SZ) {6555MakeAndPushMessage(node, NetMsgType::GETDATA, vGetData);6556vGetData.clear();6557}6558}6559}6561if (!vGetData.empty())6562MakeAndPushMessage(node, NetMsgType::GETDATA, vGetData);6563} // release cs_main6564MaybeSendFeefilter(node, peer, current_time);6565return true;6566}