Skip to content

Commit 7312772

Browse files
committed
refactor: Make FindNextBlocks friendlier
No behavior change.
1 parent 5b8c597 commit 7312772

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/net_processing.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,30 +1473,41 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
14731473
// We consider the chain that this peer is on invalid.
14741474
return;
14751475
}
1476+
14761477
if (!CanServeWitnesses(peer) && DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) {
14771478
// We wouldn't download this block or its descendants from this peer.
14781479
return;
14791480
}
1481+
14801482
if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) {
1481-
if (activeChain && pindex->HaveNumChainTxs())
1483+
if (activeChain && pindex->HaveNumChainTxs()) {
14821484
state->pindexLastCommonBlock = pindex;
1483-
} else if (!IsBlockRequested(pindex->GetBlockHash())) {
1484-
// The block is not already downloaded, and not yet in flight.
1485-
if (pindex->nHeight > nWindowEnd) {
1486-
// We reached the end of the window.
1487-
if (vBlocks.size() == 0 && waitingfor != peer.m_id) {
1488-
// We aren't able to fetch anything, but we would be if the download window was one larger.
1489-
if (nodeStaller) *nodeStaller = waitingfor;
1490-
}
1491-
return;
14921485
}
1493-
vBlocks.push_back(pindex);
1494-
if (vBlocks.size() == count) {
1495-
return;
1486+
continue;
1487+
}
1488+
1489+
// Is block in-flight?
1490+
if (IsBlockRequested(pindex->GetBlockHash())) {
1491+
if (waitingfor == -1) {
1492+
// This is the first already-in-flight block.
1493+
waitingfor = mapBlocksInFlight.lower_bound(pindex->GetBlockHash())->second.first;
14961494
}
1497-
} else if (waitingfor == -1) {
1498-
// This is the first already-in-flight block.
1499-
waitingfor = mapBlocksInFlight.lower_bound(pindex->GetBlockHash())->second.first;
1495+
continue;
1496+
}
1497+
1498+
// The block is not already downloaded, and not yet in flight.
1499+
if (pindex->nHeight > nWindowEnd) {
1500+
// We reached the end of the window.
1501+
if (vBlocks.size() == 0 && waitingfor != peer.m_id) {
1502+
// We aren't able to fetch anything, but we would be if the download window was one larger.
1503+
if (nodeStaller) *nodeStaller = waitingfor;
1504+
}
1505+
return;
1506+
}
1507+
1508+
vBlocks.push_back(pindex);
1509+
if (vBlocks.size() == count) {
1510+
return;
15001511
}
15011512
}
15021513
}

0 commit comments

Comments
 (0)