@@ -1029,8 +1029,8 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
10291029 return state.DoS (10 , false , REJECT_INVALID, " bad-txns-vin-empty" );
10301030 if (tx.vout .empty ())
10311031 return state.DoS (10 , false , REJECT_INVALID, " bad-txns-vout-empty" );
1032- // Size limits
1033- if (::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
1032+ // Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
1033+ if (::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS ) > MAX_BLOCK_SIZE)
10341034 return state.DoS (100 , false , REJECT_INVALID, " bad-txns-oversize" );
10351035
10361036 // Check for negative or overflow output values
@@ -3396,7 +3396,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
33963396 // because we receive the wrong transactions for it.
33973397
33983398 // Size limits
3399- if (block.vtx .empty () || block.vtx .size () > MAX_BLOCK_SIZE || ::GetSerializeSize (block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
3399+ if (block.vtx .empty () || block.vtx .size () > MAX_BLOCK_SIZE || ::GetSerializeSize (block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS ) > MAX_BLOCK_SIZE)
34003400 return state.DoS (100 , false , REJECT_INVALID, " bad-blk-length" , false , " size limits failed" );
34013401
34023402 // First transaction must be coinbase, the rest must not be
@@ -4508,6 +4508,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
45084508 switch (inv.type )
45094509 {
45104510 case MSG_TX:
4511+ case MSG_WITNESS_TX:
45114512 {
45124513 assert (recentRejects);
45134514 if (chainActive.Tip ()->GetBlockHash () != hashRecentRejectsChainTip)
@@ -4528,6 +4529,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
45284529 pcoinsTip->HaveCoinsInCache (inv.hash );
45294530 }
45304531 case MSG_BLOCK:
4532+ case MSG_WITNESS_BLOCK:
45314533 return mapBlockIndex.count (inv.hash );
45324534 }
45334535 // Don't know what it is, just say we already got one
@@ -4552,7 +4554,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
45524554 boost::this_thread::interruption_point ();
45534555 it++;
45544556
4555- if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK)
4557+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv. type == MSG_WITNESS_BLOCK )
45564558 {
45574559 bool send = false ;
45584560 BlockMap::iterator mi = mapBlockIndex.find (inv.hash );
@@ -4593,6 +4595,8 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
45934595 if (!ReadBlockFromDisk (block, (*mi).second , consensusParams))
45944596 assert (!" cannot load block from disk" );
45954597 if (inv.type == MSG_BLOCK)
4598+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block);
4599+ else if (inv.type == MSG_WITNESS_BLOCK)
45964600 pfrom->PushMessage (NetMsgType::BLOCK, block);
45974601 else if (inv.type == MSG_FILTERED_BLOCK)
45984602 {
@@ -4609,7 +4613,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
46094613 // however we MUST always provide at least what the remote peer needs
46104614 typedef std::pair<unsigned int , uint256> PairType;
46114615 BOOST_FOREACH (PairType& pair, merkleBlock.vMatchedTxn )
4612- pfrom->PushMessage ( NetMsgType::TX, block.vtx [pair.first ]);
4616+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, block.vtx [pair.first ]);
46134617 }
46144618 // else
46154619 // no response
@@ -4622,9 +4626,9 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
46224626 // instead we respond with the full, non-compact block.
46234627 if (mi->second ->nHeight >= chainActive.Height () - 10 ) {
46244628 CBlockHeaderAndShortTxIDs cmpctblock (block);
4625- pfrom->PushMessage ( NetMsgType::CMPCTBLOCK, cmpctblock);
4629+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::CMPCTBLOCK, cmpctblock);
46264630 } else
4627- pfrom->PushMessage ( NetMsgType::BLOCK, block);
4631+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block);
46284632 }
46294633
46304634 // Trigger the peer node to send a getblocks request for the next batch of inventory
@@ -4640,20 +4644,20 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
46404644 }
46414645 }
46424646 }
4643- else if (inv.type == MSG_TX)
4647+ else if (inv.type == MSG_TX || inv. type == MSG_WITNESS_TX )
46444648 {
46454649 // Send stream from relay memory
46464650 bool push = false ;
46474651 auto mi = mapRelay.find (inv.hash );
46484652 if (mi != mapRelay.end ()) {
4649- pfrom->PushMessage ( NetMsgType::TX, *mi->second );
4653+ pfrom->PushMessageWithFlag (inv. type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 , NetMsgType::TX, *mi->second );
46504654 push = true ;
46514655 } else if (pfrom->timeLastMempoolReq ) {
46524656 auto txinfo = mempool.info (inv.hash );
46534657 // To protect privacy, do not answer getdata using the mempool when
46544658 // that TX couldn't have been INVed in reply to a MEMPOOL request.
46554659 if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq ) {
4656- pfrom->PushMessage ( NetMsgType::TX, *txinfo.tx );
4660+ pfrom->PushMessageWithFlag (inv. type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 , NetMsgType::TX, *txinfo.tx );
46574661 push = true ;
46584662 }
46594663 }
@@ -4665,7 +4669,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
46654669 // Track requests for our stuff.
46664670 GetMainSignals ().Inventory (inv.hash );
46674671
4668- if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK)
4672+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv. type == MSG_WITNESS_BLOCK )
46694673 break ;
46704674 }
46714675 }
@@ -5146,7 +5150,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51465150 }
51475151 resp.txn [i] = block.vtx [req.indexes [i]];
51485152 }
5149- pfrom->PushMessage ( NetMsgType::BLOCKTXN, resp);
5153+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCKTXN, resp);
51505154 }
51515155
51525156
0 commit comments