Skip to content

Commit 887919c

Browse files
committed
Check for compatibility with download in FindNextBlocksToDownload
1 parent c072b8f commit 887919c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) {
532532

533533
/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
534534
* at most count entries. */
535-
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBlockIndex*>& vBlocks, NodeId& nodeStaller) {
535+
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) {
536536
if (count == 0)
537537
return;
538538

@@ -589,6 +589,10 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
589589
// We consider the chain that this peer is on invalid.
590590
return;
591591
}
592+
if (!State(nodeid)->fHaveWitness && IsWitnessEnabled(pindex->pprev, consensusParams)) {
593+
// We wouldn't download this block or its descendants from this peer.
594+
return;
595+
}
592596
if (pindex->nStatus & BLOCK_HAVE_DATA || chainActive.Contains(pindex)) {
593597
if (pindex->nChainTx)
594598
state->pindexLastCommonBlock = pindex;
@@ -6713,15 +6717,13 @@ bool SendMessages(CNode* pto)
67136717
if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
67146718
vector<CBlockIndex*> vToDownload;
67156719
NodeId staller = -1;
6716-
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
6720+
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams);
67176721
BOOST_FOREACH(CBlockIndex *pindex, vToDownload) {
6718-
if (State(pto->GetId())->fHaveWitness || !IsWitnessEnabled(pindex->pprev, consensusParams)) {
6719-
uint32_t nFetchFlags = GetFetchFlags(pto, pindex->pprev, consensusParams);
6720-
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
6721-
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex);
6722-
LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
6723-
pindex->nHeight, pto->id);
6724-
}
6722+
uint32_t nFetchFlags = GetFetchFlags(pto, pindex->pprev, consensusParams);
6723+
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
6724+
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex);
6725+
LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
6726+
pindex->nHeight, pto->id);
67256727
}
67266728
if (state.nBlocksInFlight == 0 && staller != -1) {
67276729
if (State(staller)->nStallingSince == 0) {

0 commit comments

Comments
 (0)