@@ -1530,7 +1530,6 @@ static void RelayAddress(const CNode& originator,
15301530
15311531void PeerManagerImpl::ProcessGetBlockData (CNode& pfrom, Peer& peer, const CInv& inv)
15321532{
1533- bool send = false ;
15341533 std::shared_ptr<const CBlock> a_recent_block;
15351534 std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block;
15361535 bool fWitnessesPresentInARecentCompactBlock ;
@@ -1566,35 +1565,37 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
15661565
15671566 LOCK (cs_main);
15681567 const CBlockIndex* pindex = m_chainman.m_blockman .LookupBlockIndex (inv.hash );
1569- if (pindex) {
1570- send = BlockRequestAllowed (pindex);
1571- if (!send) {
1572- LogPrint (BCLog::NET, " %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom.GetId ());
1573- }
1568+ if (!pindex) {
1569+ return ;
1570+ }
1571+ if (!BlockRequestAllowed (pindex)) {
1572+ LogPrint (BCLog::NET, " %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom.GetId ());
1573+ return ;
15741574 }
15751575 const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
15761576 // disconnect node in case we have reached the outbound limit for serving historical blocks
1577- if (send &&
1578- m_connman.OutboundTargetReached (true ) &&
1577+ if (m_connman.OutboundTargetReached (true ) &&
15791578 (((pindexBestHeader != nullptr ) && (pindexBestHeader->GetBlockTime () - pindex->GetBlockTime () > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk ()) &&
15801579 !pfrom.HasPermission (PF_DOWNLOAD) // nodes with the download permission may exceed target
15811580 ) {
15821581 LogPrint (BCLog::NET, " historical block serving limit reached, disconnect peer=%d\n " , pfrom.GetId ());
15831582 pfrom.fDisconnect = true ;
1584- send = false ;
1583+ return ;
15851584 }
15861585 // Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
1587- if (send && !pfrom.HasPermission (PF_NOBAN) && (
1586+ if (!pfrom.HasPermission (PF_NOBAN) && (
15881587 (((pfrom.GetLocalServices () & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((pfrom.GetLocalServices () & NODE_NETWORK) != NODE_NETWORK) && (m_chainman.ActiveChain ().Tip ()->nHeight - pindex->nHeight > (int )NODE_NETWORK_LIMITED_MIN_BLOCKS + 2 /* add two blocks buffer extension for possible races */ ) )
15891588 )) {
15901589 LogPrint (BCLog::NET, " Ignore block request below NODE_NETWORK_LIMITED threshold, disconnect peer=%d\n " , pfrom.GetId ());
15911590 // disconnect node and prevent it from stalling (would otherwise wait for the missing block)
15921591 pfrom.fDisconnect = true ;
1593- send = false ;
1592+ return ;
15941593 }
15951594 // Pruned nodes may have deleted the block, so check whether
15961595 // it's available before trying to send.
1597- if (send && (pindex->nStatus & BLOCK_HAVE_DATA))
1596+ if (!(pindex->nStatus & BLOCK_HAVE_DATA)) {
1597+ return ;
1598+ }
15981599 {
15991600 std::shared_ptr<const CBlock> pblock;
16001601 if (a_recent_block && a_recent_block->GetHash () == pindex->GetBlockHash ()) {
0 commit comments