0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

refactor: Make FindNextBlocks friendlier

No behavior change.
This commit is contained in:
furszy 2023-07-20 20:44:36 -03:00
parent 5b8c5970bd
commit 73127722a2
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623

View file

@ -1473,14 +1473,28 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
// We consider the chain that this peer is on invalid. // We consider the chain that this peer is on invalid.
return; return;
} }
if (!CanServeWitnesses(peer) && DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) { if (!CanServeWitnesses(peer) && DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) {
// We wouldn't download this block or its descendants from this peer. // We wouldn't download this block or its descendants from this peer.
return; return;
} }
if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) { if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) {
if (activeChain && pindex->HaveNumChainTxs()) if (activeChain && pindex->HaveNumChainTxs()) {
state->pindexLastCommonBlock = pindex; state->pindexLastCommonBlock = pindex;
} else if (!IsBlockRequested(pindex->GetBlockHash())) { }
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;
}
continue;
}
// The block is not already downloaded, and not yet in flight. // The block is not already downloaded, and not yet in flight.
if (pindex->nHeight > nWindowEnd) { if (pindex->nHeight > nWindowEnd) {
// We reached the end of the window. // We reached the end of the window.
@ -1490,14 +1504,11 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
} }
return; return;
} }
vBlocks.push_back(pindex); vBlocks.push_back(pindex);
if (vBlocks.size() == count) { if (vBlocks.size() == count) {
return; return;
} }
} else if (waitingfor == -1) {
// This is the first already-in-flight block.
waitingfor = mapBlocksInFlight.lower_bound(pindex->GetBlockHash())->second.first;
}
} }
} }
} }