@@ -1241,7 +1241,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
1241
1241
if (fTxIndex ) {
1242
1242
CDiskTxPos postx;
1243
1243
if (pblocktree->ReadTxIndex (hash, postx)) {
1244
- CAutoFile file (OpenBlockFile (postx, true ), SER_DISK, CLIENT_VERSION);
1244
+ CAutoFile file (OpenBlockFile (postx, true ), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
1245
1245
if (file.IsNull ())
1246
1246
return error (" %s: OpenBlockFile failed" , __func__);
1247
1247
CBlockHeader header;
@@ -1300,7 +1300,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
1300
1300
bool WriteBlockToDisk (const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart)
1301
1301
{
1302
1302
// Open history file to append
1303
- CAutoFile fileout (OpenBlockFile (pos), SER_DISK, CLIENT_VERSION);
1303
+ CAutoFile fileout (OpenBlockFile (pos), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
1304
1304
if (fileout.IsNull ())
1305
1305
return error (" WriteBlockToDisk: OpenBlockFile failed" );
1306
1306
@@ -1323,7 +1323,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
1323
1323
block.SetNull ();
1324
1324
1325
1325
// Open history file to read
1326
- CAutoFile filein (OpenBlockFile (pos, true ), SER_DISK, CLIENT_VERSION);
1326
+ CAutoFile filein (OpenBlockFile (pos, true ), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
1327
1327
if (filein.IsNull ())
1328
1328
return error (" ReadBlockFromDisk: OpenBlockFile failed for %s" , pos.ToString ());
1329
1329
@@ -1697,7 +1697,7 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
1697
1697
fileout << blockundo;
1698
1698
1699
1699
// calculate & write checksum
1700
- CHashWriter hasher (SER_GETHASH, PROTOCOL_VERSION);
1700
+ CHashWriter hasher (SER_GETHASH, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS );
1701
1701
hasher << hashBlock;
1702
1702
hasher << blockundo;
1703
1703
fileout << hasher.GetHash ();
@@ -1723,7 +1723,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
1723
1723
}
1724
1724
1725
1725
// Verify checksum
1726
- CHashWriter hasher (SER_GETHASH, PROTOCOL_VERSION);
1726
+ CHashWriter hasher (SER_GETHASH, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS );
1727
1727
hasher << hashBlock;
1728
1728
hasher << blockundo;
1729
1729
if (hashChecksum != hasher.GetHash ())
@@ -2101,7 +2101,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2101
2101
UpdateCoins (tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo .back (), pindex->nHeight );
2102
2102
2103
2103
vPos.push_back (std::make_pair (tx.GetHash (), pos));
2104
- pos.nTxOffset += ::GetSerializeSize (tx, SER_DISK, CLIENT_VERSION);
2104
+ pos.nTxOffset += ::GetSerializeSize (tx, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
2105
2105
}
2106
2106
int64_t nTime3 = GetTimeMicros (); nTimeConnect += nTime3 - nTime2;
2107
2107
LogPrint (" bench" , " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n " , (unsigned )block.vtx .size (), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx .size (), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1 ), nTimeConnect * 0.000001 );
@@ -3153,7 +3153,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
3153
3153
3154
3154
// Write block to history file
3155
3155
try {
3156
- unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION);
3156
+ unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
3157
3157
CDiskBlockPos blockPos;
3158
3158
if (dbp != NULL )
3159
3159
blockPos = *dbp;
@@ -3673,7 +3673,7 @@ bool InitBlockIndex(const CChainParams& chainparams)
3673
3673
try {
3674
3674
CBlock &block = const_cast <CBlock&>(chainparams.GenesisBlock ());
3675
3675
// Start new block file
3676
- unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION);
3676
+ unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
3677
3677
CDiskBlockPos blockPos;
3678
3678
CValidationState state;
3679
3679
if (!FindBlockPos (state, blockPos, nBlockSize+8 , 0 , block.GetBlockTime ()))
@@ -3704,7 +3704,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
3704
3704
int nLoaded = 0 ;
3705
3705
try {
3706
3706
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
3707
- CBufferedFile blkdat (fileIn, 2 *MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8 , SER_DISK, CLIENT_VERSION);
3707
+ CBufferedFile blkdat (fileIn, 2 *MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8 , SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS );
3708
3708
uint64_t nRewind = blkdat.GetPos ();
3709
3709
while (!blkdat.eof ()) {
3710
3710
boost::this_thread::interruption_point ();
@@ -4063,6 +4063,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
4063
4063
switch (inv.type )
4064
4064
{
4065
4065
case MSG_TX:
4066
+ case MSG_WITNESS_TX:
4066
4067
{
4067
4068
assert (recentRejects);
4068
4069
if (chainActive.Tip ()->GetBlockHash () != hashRecentRejectsChainTip)
@@ -4081,6 +4082,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
4081
4082
pcoinsTip->HaveCoins (inv.hash );
4082
4083
}
4083
4084
case MSG_BLOCK:
4085
+ case MSG_WITNESS_BLOCK:
4084
4086
return mapBlockIndex.count (inv.hash );
4085
4087
}
4086
4088
// Don't know what it is, just say we already got one
@@ -4105,7 +4107,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4105
4107
boost::this_thread::interruption_point ();
4106
4108
it++;
4107
4109
4108
- if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
4110
+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv. type == MSG_WITNESS_BLOCK )
4109
4111
{
4110
4112
bool send = false ;
4111
4113
BlockMap::iterator mi = mapBlockIndex.find (inv.hash );
@@ -4147,6 +4149,8 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4147
4149
assert (!" cannot load block from disk" );
4148
4150
if (inv.type == MSG_BLOCK)
4149
4151
pfrom->PushMessage (NetMsgType::BLOCK, block);
4152
+ if (inv.type == MSG_WITNESS_BLOCK)
4153
+ pfrom->PushMessageWithFlag (SERIALIZE_TRANSACTION_WITNESS, NetMsgType::BLOCK, block);
4150
4154
else // MSG_FILTERED_BLOCK)
4151
4155
{
4152
4156
LOCK (pfrom->cs_filter );
@@ -4181,25 +4185,22 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4181
4185
}
4182
4186
}
4183
4187
}
4184
- else if (inv.IsKnownType () )
4188
+ else if (inv.type == MSG_TX || inv. type == MSG_WITNESS_TX )
4185
4189
{
4186
4190
// Send stream from relay memory
4187
4191
bool pushed = false ;
4188
4192
{
4189
- LOCK (cs_mapRelay );
4190
- map<CInv, CDataStream >::iterator mi = mapRelay .find (inv);
4191
- if (mi != mapRelay .end ()) {
4192
- pfrom->PushMessage (inv.GetCommand () , (*mi).second );
4193
+ LOCK (cs_mapRelayTx );
4194
+ map<uint256, CTransaction >::iterator mi = mapRelayTx .find (inv. hash );
4195
+ if (mi != mapRelayTx .end ()) {
4196
+ pfrom->PushMessageWithFlag (inv.type == MSG_WITNESS_TX ? SERIALIZE_TRANSACTION_WITNESS : 0 , NetMsgType::TX , (*mi).second );
4193
4197
pushed = true ;
4194
4198
}
4195
4199
}
4196
- if (!pushed && inv.type == MSG_TX) {
4200
+ if (!pushed && ( inv.type == MSG_TX || inv. type == MSG_WITNESS_TX) ) {
4197
4201
CTransaction tx;
4198
4202
if (mempool.lookup (inv.hash , tx)) {
4199
- CDataStream ss (SER_NETWORK, PROTOCOL_VERSION);
4200
- ss.reserve (1000 );
4201
- ss << tx;
4202
- pfrom->PushMessage (NetMsgType::TX, ss);
4203
+ pfrom->PushMessageWithFlag (inv.type == MSG_WITNESS_TX ? SERIALIZE_TRANSACTION_WITNESS : 0 , NetMsgType::TX, tx);
4203
4204
pushed = true ;
4204
4205
}
4205
4206
}
@@ -4211,7 +4212,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4211
4212
// Track requests for our stuff.
4212
4213
GetMainSignals ().Inventory (inv.hash );
4213
4214
4214
- if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
4215
+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv. type == MSG_WITNESS_BLOCK )
4215
4216
break ;
4216
4217
}
4217
4218
}
@@ -4683,7 +4684,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4683
4684
vector<uint256> vWorkQueue;
4684
4685
vector<uint256> vEraseQueue;
4685
4686
CTransaction tx;
4686
- vRecv >> tx;
4687
+ WithOrVersion (& vRecv, SERIALIZE_TRANSACTION_WITNESS) >> tx;
4687
4688
4688
4689
CInv inv (MSG_TX, tx.GetHash ());
4689
4690
pfrom->AddInventoryKnown (inv);
@@ -4912,7 +4913,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4912
4913
else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex ) // Ignore blocks received while importing
4913
4914
{
4914
4915
CBlock block;
4915
- vRecv >> block;
4916
+ WithOrVersion (& vRecv, SERIALIZE_TRANSACTION_WITNESS) >> block;
4916
4917
4917
4918
CInv inv (MSG_BLOCK, block.GetHash ());
4918
4919
LogPrint (" net" , " received block %s peer=%d\n " , inv.hash .ToString (), pfrom->id );
@@ -5537,11 +5538,11 @@ bool SendMessages(CNode* pto)
5537
5538
vInvWait.reserve (pto->vInventoryToSend .size ());
5538
5539
BOOST_FOREACH (const CInv& inv, pto->vInventoryToSend )
5539
5540
{
5540
- if (inv.type == MSG_TX && pto->filterInventoryKnown .contains (inv.hash ))
5541
+ if (( inv.type == MSG_TX || inv. type == MSG_WITNESS_TX) && pto->filterInventoryKnown .contains (inv.hash ))
5541
5542
continue ;
5542
5543
5543
5544
// trickle out tx inv to protect privacy
5544
- if (inv.type == MSG_TX && !fSendTrickle )
5545
+ if (( inv.type == MSG_TX || inv. type == MSG_WITNESS_TX) && !fSendTrickle )
5545
5546
{
5546
5547
// 1/4 of tx invs blast to all immediately
5547
5548
static uint256 hashSalt;
0 commit comments