@@ -313,6 +313,7 @@ struct CNodeState {
313313 fPreferHeaders = false ;
314314 fPreferHeaderAndIDs = false ;
315315 fProvidesHeaderAndIDs = false ;
316+ fHaveWitness = false ;
316317 }
317318};
318319
@@ -4812,6 +4813,14 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
48124813 }
48134814}
48144815
4816+ uint32_t GetFetchFlags (CNode* pfrom, CBlockIndex* pprev, const Consensus::Params& chainparams) {
4817+ uint32_t nFetchFlags = 0 ;
4818+ if (IsWitnessEnabled (pprev, chainparams) && State (pfrom->GetId ())->fHaveWitness ) {
4819+ nFetchFlags |= MSG_WITNESS_FLAG;
4820+ }
4821+ return nFetchFlags;
4822+ }
4823+
48154824bool static ProcessMessage (CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams)
48164825{
48174826 LogPrint (" net" , " received: %s (%u bytes) peer=%d\n " , SanitizeString (strCommand), vRecv.size (), pfrom->id );
@@ -4918,6 +4927,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
49184927
49194928 pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);
49204929
4930+ if ((pfrom->nServices & NODE_WITNESS))
4931+ {
4932+ LOCK (cs_main);
4933+ State (pfrom->GetId ())->fHaveWitness = true ;
4934+ }
4935+
49214936 // Potentially mark this peer as a preferred download peer.
49224937 {
49234938 LOCK (cs_main);
@@ -5119,17 +5134,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51195134
51205135 LOCK (cs_main);
51215136
5137+ uint32_t nFetchFlags = GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ());
5138+
51225139 std::vector<CInv> vToFetch;
51235140
51245141 for (unsigned int nInv = 0 ; nInv < vInv.size (); nInv++)
51255142 {
5126- const CInv &inv = vInv[nInv];
5143+ CInv &inv = vInv[nInv];
51275144
51285145 boost::this_thread::interruption_point ();
51295146
51305147 bool fAlreadyHave = AlreadyHave (inv);
51315148 LogPrint (" net" , " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom->id );
51325149
5150+ if (inv.type == MSG_TX) {
5151+ inv.type |= nFetchFlags;
5152+ }
5153+
51335154 if (inv.type == MSG_BLOCK) {
51345155 UpdateBlockAvailability (pfrom->GetId (), inv.hash );
51355156 if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count (inv.hash )) {
@@ -5144,7 +5165,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51445165 pfrom->PushMessage (NetMsgType::GETHEADERS, chainActive.GetLocator (pindexBestHeader), inv.hash );
51455166 CNodeState *nodestate = State (pfrom->GetId ());
51465167 if (CanDirectFetch (chainparams.GetConsensus ()) &&
5147- nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5168+ nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER &&
5169+ (!IsWitnessEnabled (chainActive.Tip (), chainparams.GetConsensus ()) || State (pfrom->GetId ())->fHaveWitness )) {
5170+ inv.type |= nFetchFlags;
51485171 if (nodestate->fProvidesHeaderAndIDs )
51495172 vToFetch.push_back (CInv (MSG_CMPCT_BLOCK, inv.hash ));
51505173 else
@@ -5730,7 +5753,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
57305753 // Calculate all the blocks we'd need to switch to pindexLast, up to a limit.
57315754 while (pindexWalk && !chainActive.Contains (pindexWalk) && vToFetch.size () <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
57325755 if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
5733- !mapBlocksInFlight.count (pindexWalk->GetBlockHash ())) {
5756+ !mapBlocksInFlight.count (pindexWalk->GetBlockHash ()) &&
5757+ (!IsWitnessEnabled (pindexWalk->pprev , chainparams.GetConsensus ()) || State (pfrom->GetId ())->fHaveWitness )) {
57345758 // We don't have this block, and it's not yet in flight.
57355759 vToFetch.push_back (pindexWalk);
57365760 }
@@ -5752,7 +5776,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
57525776 // Can't download any more from this peer
57535777 break ;
57545778 }
5755- vGetData.push_back (CInv (MSG_BLOCK, pindex->GetBlockHash ()));
5779+ uint32_t nFetchFlags = GetFetchFlags (pfrom, pindex->pprev , chainparams.GetConsensus ());
5780+ vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
57565781 MarkBlockAsInFlight (pfrom->GetId (), pindex->GetBlockHash (), chainparams.GetConsensus (), pindex);
57575782 LogPrint (" net" , " Requesting block %s from peer=%d\n " ,
57585783 pindex->GetBlockHash ().ToString (), pfrom->id );
@@ -6598,10 +6623,13 @@ bool SendMessages(CNode* pto)
65986623 NodeId staller = -1 ;
65996624 FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller);
66006625 BOOST_FOREACH (CBlockIndex *pindex, vToDownload) {
6601- vGetData.push_back (CInv (MSG_BLOCK, pindex->GetBlockHash ()));
6602- MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
6603- LogPrint (" net" , " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
6604- pindex->nHeight , pto->id );
6626+ if (State (pto->GetId ())->fHaveWitness || !IsWitnessEnabled (pindex->pprev , consensusParams)) {
6627+ uint32_t nFetchFlags = GetFetchFlags (pto, pindex->pprev , consensusParams);
6628+ vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
6629+ MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
6630+ LogPrint (" net" , " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
6631+ pindex->nHeight , pto->id );
6632+ }
66056633 }
66066634 if (state.nBlocksInFlight == 0 && staller != -1 ) {
66076635 if (State (staller)->nStallingSince == 0 ) {
0 commit comments