@@ -532,7 +532,7 @@ CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) {
532
532
533
533
/* * Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
534
534
* 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 ) {
536
536
if (count == 0 )
537
537
return ;
538
538
@@ -589,6 +589,10 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
589
589
// We consider the chain that this peer is on invalid.
590
590
return ;
591
591
}
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
+ }
592
596
if (pindex->nStatus & BLOCK_HAVE_DATA || chainActive.Contains (pindex)) {
593
597
if (pindex->nChainTx )
594
598
state->pindexLastCommonBlock = pindex;
@@ -6713,15 +6717,13 @@ bool SendMessages(CNode* pto)
6713
6717
if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload ()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
6714
6718
vector<CBlockIndex*> vToDownload;
6715
6719
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 );
6717
6721
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 );
6725
6727
}
6726
6728
if (state.nBlocksInFlight == 0 && staller != -1 ) {
6727
6729
if (State (staller)->nStallingSince == 0 ) {
0 commit comments