@@ -3134,7 +3134,10 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
31343134 pindexNew->nFile = pos.nFile ;
31353135 pindexNew->nDataPos = pos.nPos ;
31363136 pindexNew->nUndoPos = 0 ;
3137- pindexNew->nStatus |= BLOCK_HAVE_DATA | BLOCK_OPT_WITNESS;
3137+ pindexNew->nStatus |= BLOCK_HAVE_DATA;
3138+ if (IsWitnessEnabled (pindexNew->pprev , Params ().GetConsensus ())) {
3139+ pindexNew->nStatus |= BLOCK_OPT_WITNESS;
3140+ }
31383141 pindexNew->RaiseValidity (BLOCK_VALID_TRANSACTIONS);
31393142 setDirtyBlockIndex.insert (pindexNew);
31403143
@@ -4752,6 +4755,14 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
47524755 }
47534756}
47544757
4758+ uint32_t GetFetchFlags (CNode* pfrom, CBlockIndex* pprev, const Consensus::Params& chainparams) {
4759+ uint32_t nFetchFlags = 0 ;
4760+ if (IsWitnessEnabled (pprev, chainparams) && State (pfrom->GetId ())->fHaveWitness ) {
4761+ nFetchFlags |= MSG_WITNESS_FLAG;
4762+ }
4763+ return nFetchFlags;
4764+ }
4765+
47554766bool static ProcessMessage (CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams)
47564767{
47574768 RandAddSeedPerfmon ();
@@ -5034,20 +5045,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50345045
50355046 LOCK (cs_main);
50365047
5048+ uint32_t nFetchFlags = GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ());
5049+
50375050 std::vector<CInv> vToFetch;
50385051
50395052 for (unsigned int nInv = 0 ; nInv < vInv.size (); nInv++)
50405053 {
50415054 CInv &inv = vInv[nInv];
5055+ inv.type |= nFetchFlags;
50425056
50435057 boost::this_thread::interruption_point ();
50445058 pfrom->AddInventoryKnown (inv);
50455059
50465060 bool fAlreadyHave = AlreadyHave (inv);
50475061 LogPrint (" net" , " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom->id );
50485062
5049- if (inv.type == MSG_TX && State (pfrom-> GetId ())-> fHaveWitness ) {
5050- inv.type = MSG_WITNESS_TX ;
5063+ if (inv.type == MSG_TX) {
5064+ inv.type |= nFetchFlags ;
50515065 }
50525066
50535067 if (inv.type == MSG_BLOCK) {
@@ -5066,9 +5080,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50665080 if (CanDirectFetch (chainparams.GetConsensus ()) &&
50675081 nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER &&
50685082 (!IsWitnessEnabled (chainActive.Tip (), chainparams.GetConsensus ()) || State (pfrom->GetId ())->fHaveWitness )) {
5069- if (State (pfrom->GetId ())->fHaveWitness ) {
5070- inv.type = MSG_WITNESS_BLOCK;
5071- }
5083+ inv.type |= nFetchFlags;
50725084 vToFetch.push_back (inv);
50735085 // Mark block as in flight already, even though the actual "getdata" message only goes out
50745086 // later (within the same cs_main lock, though).
@@ -5442,7 +5454,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54425454 // Can't download any more from this peer
54435455 break ;
54445456 }
5445- vGetData.push_back (CInv (State (pfrom->GetId ())->fHaveWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK, pindex->GetBlockHash ()));
5457+ uint32_t nFetchFlags = GetFetchFlags (pfrom, pindex->pprev , chainparams.GetConsensus ());
5458+ vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
54465459 MarkBlockAsInFlight (pfrom->GetId (), pindex->GetBlockHash (), chainparams.GetConsensus (), pindex);
54475460 LogPrint (" net" , " Requesting block %s from peer=%d\n " ,
54485461 pindex->GetBlockHash ().ToString (), pfrom->id );
@@ -6156,7 +6169,8 @@ bool SendMessages(CNode* pto)
61566169 FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller);
61576170 BOOST_FOREACH (CBlockIndex *pindex, vToDownload) {
61586171 if (State (pto->GetId ())->fHaveWitness || !IsWitnessEnabled (pindex->pprev , consensusParams)) {
6159- vGetData.push_back (CInv (State (pto->GetId ())->fHaveWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK, pindex->GetBlockHash ()));
6172+ uint32_t nFetchFlags = GetFetchFlags (pto, pindex->pprev , consensusParams);
6173+ vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
61606174 MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
61616175 LogPrint (" net" , " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
61626176 pindex->nHeight , pto->id );
0 commit comments