aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2023-07-20 20:44:36 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-02-01 16:23:58 -0300
commit73127722a2d2b5c8da4102284f9d0cf504a2e72d (patch)
tree5fa894e038572f27ec11464d49857709566de944 /src/net_processing.cpp
parent5b8c5970bdfc817cac9b59f699925c4426c59b61 (diff)
downloadbitcoin-73127722a2d2b5c8da4102284f9d0cf504a2e72d.tar.xz
refactor: Make FindNextBlocks friendlier
No behavior change.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 1cf72771b5..e211ee3b2c 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1473,30 +1473,41 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
// We consider the chain that this peer is on invalid.
return;
}
+
if (!CanServeWitnesses(peer) && DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) {
// We wouldn't download this block or its descendants from this peer.
return;
}
+
if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) {
- if (activeChain && pindex->HaveNumChainTxs())
+ if (activeChain && pindex->HaveNumChainTxs()) {
state->pindexLastCommonBlock = pindex;
- } else if (!IsBlockRequested(pindex->GetBlockHash())) {
- // The block is not already downloaded, and not yet in flight.
- if (pindex->nHeight > nWindowEnd) {
- // We reached the end of the window.
- if (vBlocks.size() == 0 && waitingfor != peer.m_id) {
- // We aren't able to fetch anything, but we would be if the download window was one larger.
- if (nodeStaller) *nodeStaller = waitingfor;
- }
- return;
}
- vBlocks.push_back(pindex);
- if (vBlocks.size() == count) {
- return;
+ continue;
+ }
+
+ // Is block in-flight?
+ if (IsBlockRequested(pindex->GetBlockHash())) {
+ if (waitingfor == -1) {
+ // This is the first already-in-flight block.
+ waitingfor = mapBlocksInFlight.lower_bound(pindex->GetBlockHash())->second.first;
}
- } else if (waitingfor == -1) {
- // This is the first already-in-flight block.
- waitingfor = mapBlocksInFlight.lower_bound(pindex->GetBlockHash())->second.first;
+ continue;
+ }
+
+ // The block is not already downloaded, and not yet in flight.
+ if (pindex->nHeight > nWindowEnd) {
+ // We reached the end of the window.
+ if (vBlocks.size() == 0 && waitingfor != peer.m_id) {
+ // We aren't able to fetch anything, but we would be if the download window was one larger.
+ if (nodeStaller) *nodeStaller = waitingfor;
+ }
+ return;
+ }
+
+ vBlocks.push_back(pindex);
+ if (vBlocks.size() == count) {
+ return;
}
}
}