Skip to content

Commit 3dbf852

Browse files
committed
Remove positive SERIALIZE_TRANSACTION_WITNESS flag
1 parent 4840f6d commit 3dbf852

22 files changed

+81
-85
lines changed

src/core_read.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool fTryNoWitne
110110
}
111111
}
112112

113-
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
113+
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
114114
try {
115115
ssData >> tx;
116116
}
@@ -127,7 +127,7 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
127127
return false;
128128

129129
std::vector<unsigned char> blockData(ParseHex(strHexBlk));
130-
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
130+
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
131131
try {
132132
ssBlock >> block;
133133
}

src/core_write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
118118

119119
string EncodeHexTx(const CTransaction& tx)
120120
{
121-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
121+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
122122
ssTx << tx;
123123
return HexStr(ssTx.begin(), ssTx.end());
124124
}

src/main.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(c
622622
// have been mined or received.
623623
// 10,000 orphans, each of which is at most 5,000 bytes big is
624624
// at most 500 megabytes of orphans:
625-
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
625+
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
626626
if (sz > 5000)
627627
{
628628
LogPrint("mempool", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
@@ -1487,7 +1487,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
14871487
if (fTxIndex) {
14881488
CDiskTxPos postx;
14891489
if (pblocktree->ReadTxIndex(hash, postx)) {
1490-
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
1490+
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
14911491
if (file.IsNull())
14921492
return error("%s: OpenBlockFile failed", __func__);
14931493
CBlockHeader header;
@@ -1546,7 +1546,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
15461546
bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart)
15471547
{
15481548
// Open history file to append
1549-
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
1549+
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
15501550
if (fileout.IsNull())
15511551
return error("WriteBlockToDisk: OpenBlockFile failed");
15521552

@@ -1569,7 +1569,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
15691569
block.SetNull();
15701570

15711571
// Open history file to read
1572-
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
1572+
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
15731573
if (filein.IsNull())
15741574
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
15751575

@@ -1959,7 +1959,7 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
19591959
fileout << blockundo;
19601960

19611961
// calculate & write checksum
1962-
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
1962+
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
19631963
hasher << hashBlock;
19641964
hasher << blockundo;
19651965
fileout << hasher.GetHash();
@@ -1985,7 +1985,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
19851985
}
19861986

19871987
// Verify checksum
1988-
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
1988+
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
19891989
hasher << hashBlock;
19901990
hasher << blockundo;
19911991
if (hashChecksum != hasher.GetHash())
@@ -2431,7 +2431,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24312431
UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
24322432

24332433
vPos.push_back(std::make_pair(tx.GetHash(), pos));
2434-
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
2434+
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
24352435
}
24362436
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
24372437
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);
@@ -3608,7 +3608,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
36083608

36093609
// Write block to history file
36103610
try {
3611-
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
3611+
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
36123612
CDiskBlockPos blockPos;
36133613
if (dbp != NULL)
36143614
blockPos = *dbp;
@@ -4215,7 +4215,7 @@ bool InitBlockIndex(const CChainParams& chainparams)
42154215
try {
42164216
CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
42174217
// Start new block file
4218-
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
4218+
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
42194219
CDiskBlockPos blockPos;
42204220
CValidationState state;
42214221
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime()))
@@ -4246,7 +4246,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
42464246
int nLoaded = 0;
42474247
try {
42484248
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
4249-
CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE+8, SER_DISK, CLIENT_VERSION | SERIALIZE_TRANSACTION_WITNESS);
4249+
CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE+8, SER_DISK, CLIENT_VERSION);
42504250
uint64_t nRewind = blkdat.GetPos();
42514251
while (!blkdat.eof()) {
42524252
boost::this_thread::interruption_point();
@@ -4671,7 +4671,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
46714671
if (inv.type == MSG_BLOCK)
46724672
pfrom->PushMessageWithFlag(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block);
46734673
else if (inv.type == MSG_WITNESS_BLOCK)
4674-
pfrom->PushMessageWithFlag(SERIALIZE_TRANSACTION_WITNESS, NetMsgType::BLOCK, block);
4674+
pfrom->PushMessage(NetMsgType::BLOCK, block);
46754675
else // MSG_FILTERED_BLOCK)
46764676
{
46774677
LOCK(pfrom->cs_filter);
@@ -4714,14 +4714,14 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
47144714
LOCK(cs_mapRelay);
47154715
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
47164716
if (mi != mapRelay.end()) {
4717-
pfrom->PushMessageWithFlag(inv.type == MSG_WITNESS_TX ? SERIALIZE_TRANSACTION_WITNESS : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, (*mi).second);
4717+
pfrom->PushMessageWithFlag(inv.type == MSG_WITNESS_TX ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, (*mi).second);
47184718
pushed = true;
47194719
}
47204720
}
47214721
if (!pushed && (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX)) {
47224722
CTransaction tx;
47234723
if (mempool.lookup(inv.hash, tx)) {
4724-
pfrom->PushMessageWithFlag(inv.type == MSG_WITNESS_TX ? SERIALIZE_TRANSACTION_WITNESS : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, tx);
4724+
pfrom->PushMessageWithFlag(inv.type == MSG_WITNESS_TX ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, tx);
47254725
pushed = true;
47264726
}
47274727
}
@@ -5226,7 +5226,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
52265226
vector<uint256> vWorkQueue;
52275227
vector<uint256> vEraseQueue;
52285228
CTransaction tx;
5229-
WithOrVersion(&vRecv, SERIALIZE_TRANSACTION_WITNESS) >> tx;
5229+
vRecv >> tx;
52305230

52315231
CInv inv(MSG_TX, tx.GetHash());
52325232
pfrom->AddInventoryKnown(inv);
@@ -5463,7 +5463,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54635463
else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
54645464
{
54655465
CBlock block;
5466-
WithOrVersion(&vRecv, SERIALIZE_TRANSACTION_WITNESS) >> block;
5466+
vRecv >> block;
54675467

54685468
CInv inv(MSG_BLOCK, block.GetHash());
54695469
LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id);

src/primitives/block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ int64_t GetBlockCost(const CBlock& block)
3838
// using only serialization with and without witness data. As witness_size
3939
// is equal to total_size - stripped_size, this formula is identical to:
4040
// cost = (stripped_size * 3) + total_size.
41-
return ::GetSerializeSize(block, SER_NETWORK, SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(block, SER_NETWORK, SERIALIZE_TRANSACTION_WITNESS);
41+
return ::GetSerializeSize(block, SER_NETWORK, SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION);
4242
}

src/primitives/transaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void CTransaction::UpdateHash() const
7474

7575
uint256 CTransaction::GetWitnessHash() const
7676
{
77-
return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_WITNESS);
77+
return SerializeHash(*this, SER_GETHASH, 0);
7878
}
7979

8080
CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { }
@@ -151,5 +151,5 @@ std::string CTransaction::ToString() const
151151

152152
int64_t GetTransactionCost(const CTransaction& tx)
153153
{
154-
return ::GetSerializeSize(tx, SER_NETWORK, SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR -1) + ::GetSerializeSize(tx, SER_NETWORK, SERIALIZE_TRANSACTION_WITNESS);
154+
return ::GetSerializeSize(tx, SER_NETWORK, SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR -1) + ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
155155
}

src/primitives/transaction.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "serialize.h"
1212
#include "uint256.h"
1313

14-
static const int SERIALIZE_TRANSACTION_WITNESS = 0x40000000;
15-
static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x20000000;
14+
static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000;
1615

1716
static const int WITNESS_SCALE_FACTOR = 4;
1817

@@ -293,8 +292,6 @@ template<typename Stream, typename Operation, typename TxType>
293292
inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, int nType, int nVersion) {
294293
READWRITE(*const_cast<int32_t*>(&tx.nVersion));
295294
unsigned char flags = 0;
296-
/* Verify that exactly one of SERIALIZE_TRANSACTION_WITNESS and SERIALIZE_TRANSACTION_NO_WITESS is set */
297-
assert(!(nVersion & SERIALIZE_TRANSACTION_WITNESS) ^ !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS));
298295
if (ser_action.ForRead()) {
299296
const_cast<std::vector<CTxIn>*>(&tx.vin)->clear();
300297
const_cast<std::vector<CTxOut>*>(&tx.vout)->clear();

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
332332
return TransactionCommitFailed;
333333

334334
CTransaction* t = (CTransaction*)newTx;
335-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
335+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
336336
ssTx << *t;
337337
transaction_array.append(&(ssTx[0]), ssTx.size());
338338
}

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static bool rest_block(HTTPRequest* req,
228228
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
229229
}
230230

231-
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
231+
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
232232
ssBlock << block;
233233

234234
switch (rf) {
@@ -367,7 +367,7 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
367367
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
368368
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
369369

370-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
370+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
371371
ssTx << tx;
372372

373373
switch (rf) {

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
100100
confirmations = chainActive.Height() - blockindex->nHeight + 1;
101101
result.push_back(Pair("confirmations", confirmations));
102102
result.push_back(Pair("strippedsize", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS)));
103-
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS)));
103+
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
104104
result.push_back(Pair("cost", (int)::GetBlockCost(block)));
105105
result.push_back(Pair("height", blockindex->nHeight));
106106
result.push_back(Pair("version", block.nVersion));
@@ -430,7 +430,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
430430

431431
if (!fVerbose)
432432
{
433-
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
433+
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
434434
ssBlock << block;
435435
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
436436
return strHex;

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
6363
{
6464
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
6565
entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex()));
66-
entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS)));
66+
entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)));
6767
entry.push_back(Pair("vsize", (int)::GetVirtualTransactionSize(tx)));
6868
entry.push_back(Pair("version", tx.nVersion));
6969
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
@@ -627,7 +627,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
627627
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
628628

629629
vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
630-
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
630+
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
631631
vector<CMutableTransaction> txVariants;
632632
while (!ssData.empty()) {
633633
try {

0 commit comments

Comments
 (0)