From 1f8f7d477ae0d33bd96f7936889c17bd40805fb9 Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Fri, 30 Jan 2026 16:18:50 +0100 Subject: [PATCH] Change BlockRequestAllowed() to take ref The input parameter of `PeerManagerImpl::BlockRequestAllowed()` changed to reference from pointer. The change is local to the class. --- src/net_processing.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 7354eb57e90..7da26174a76 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1017,7 +1017,7 @@ private: * and in best equivalent proof of work) than the best header chain we know * about and we fully-validated them at some point. */ - bool BlockRequestAllowed(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool BlockRequestAllowed(const CBlockIndex& block_index) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool AlreadyHaveBlock(const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main); void ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex, !m_most_recent_block_mutex); @@ -1922,13 +1922,13 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati } } -bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex) +bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex& block_index) { AssertLockHeld(cs_main); - if (m_chainman.ActiveChain().Contains(pindex)) return true; - return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (m_chainman.m_best_header != nullptr) && - (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) && - (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT); + if (m_chainman.ActiveChain().Contains(&block_index)) return true; + return block_index.IsValid(BLOCK_VALID_SCRIPTS) && (m_chainman.m_best_header != nullptr) && + (m_chainman.m_best_header->GetBlockTime() - block_index.GetBlockTime() < STALE_RELAY_AGE_LIMIT) && + (GetBlockProofEquivalentTime(*m_chainman.m_best_header, block_index, *m_chainman.m_best_header, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT); } util::Expected PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index) @@ -2340,7 +2340,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& if (!pindex) { return; } - if (!BlockRequestAllowed(pindex)) { + if (!BlockRequestAllowed(*pindex)) { LogDebug(BCLog::NET, "%s: ignoring request from peer=%i for old block that isn't in the main chain\n", __func__, pfrom.GetId()); return; } @@ -3255,7 +3255,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer, stop_index = m_chainman.m_blockman.LookupBlockIndex(stop_hash); // Check that the stop block exists and the peer would be allowed to fetch it. - if (!stop_index || !BlockRequestAllowed(stop_index)) { + if (!stop_index || !BlockRequestAllowed(*stop_index)) { LogDebug(BCLog::NET, "peer requested invalid block hash: %s, %s\n", stop_hash.ToString(), node.DisconnectMsg(fLogIPs)); node.fDisconnect = true; @@ -4404,8 +4404,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, if (!pindex) { return; } - - if (!BlockRequestAllowed(pindex)) { + if (!BlockRequestAllowed(*pindex)) { LogDebug(BCLog::NET, "%s: ignoring request from peer=%i for old block header that isn't in the main chain\n", __func__, pfrom.GetId()); return; }