Skip to content

Commit c65bf50

Browse files
committed
Remove fUseWTXID parameter from CBlockHeaderAndShortTxIDs constructor
All uses of CBlockHeaderAndShortTxIDs in the product code are constructed with fUseWTXID=true, so remove the parameter. There is one use of the CBlockHeaderAndShortTxIDs constructor with fUseWTXID=false in the unit tests. This is used to construct a CBlockHeaderAndShortTxIDs for a block with only the coinbase transaction, so setting fUseWTXID to true or false makes no difference. Suggested in bitcoin/bitcoin#20799 (review)
1 parent 6b87fa5 commit c65bf50

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/blockencodings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
#include <unordered_map>
1818

19-
CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block, bool fUseWTXID) :
19+
CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block) :
2020
nonce(GetRand<uint64_t>()),
2121
shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
2222
FillShortTxIDSelector();
2323
//TODO: Use our mempool prior to block acceptance to predictively fill more than just the coinbase
2424
prefilledtxn[0] = {0, block.vtx[0]};
2525
for (size_t i = 1; i < block.vtx.size(); i++) {
2626
const CTransaction& tx = *block.vtx[i];
27-
shorttxids[i - 1] = GetShortID(fUseWTXID ? tx.GetWitnessHash() : tx.GetHash());
27+
shorttxids[i - 1] = GetShortID(tx.GetWitnessHash());
2828
}
2929
}
3030

src/blockencodings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CBlockHeaderAndShortTxIDs {
104104
// Dummy for deserialization
105105
CBlockHeaderAndShortTxIDs() {}
106106

107-
CBlockHeaderAndShortTxIDs(const CBlock& block, bool fUseWTXID);
107+
CBlockHeaderAndShortTxIDs(const CBlock& block);
108108

109109
uint64_t GetShortID(const uint256& txhash) const;
110110

src/net_processing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
16321632
*/
16331633
void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock)
16341634
{
1635-
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
1635+
auto pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
16361636
const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
16371637

16381638
LOCK(cs_main);
@@ -1978,7 +1978,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
19781978
if (a_recent_compact_block && a_recent_compact_block->header.GetHash() == pindex->GetBlockHash()) {
19791979
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CMPCTBLOCK, *a_recent_compact_block));
19801980
} else {
1981-
CBlockHeaderAndShortTxIDs cmpctblock(*pblock, true);
1981+
CBlockHeaderAndShortTxIDs cmpctblock{*pblock};
19821982
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
19831983
}
19841984
} else {
@@ -4771,7 +4771,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47714771
CBlock block;
47724772
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
47734773
assert(ret);
4774-
CBlockHeaderAndShortTxIDs cmpctblock(block, true);
4774+
CBlockHeaderAndShortTxIDs cmpctblock{block};
47754775
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
47764776
}
47774777
state.pindexBestHeaderSent = pBestIndex;

src/test/blockencodings_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
6464

6565
// Do a simple ShortTxIDs RT
6666
{
67-
CBlockHeaderAndShortTxIDs shortIDs(block, true);
67+
CBlockHeaderAndShortTxIDs shortIDs{block};
6868

6969
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
7070
stream << shortIDs;
@@ -122,7 +122,7 @@ class TestHeaderAndShortIDs {
122122
stream >> *this;
123123
}
124124
explicit TestHeaderAndShortIDs(const CBlock& block) :
125-
TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs(block, true)) {}
125+
TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs{block}) {}
126126

127127
uint64_t GetShortID(const uint256& txhash) const {
128128
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
@@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
279279

280280
// Test simple header round-trip with only coinbase
281281
{
282-
CBlockHeaderAndShortTxIDs shortIDs(block, false);
282+
CBlockHeaderAndShortTxIDs shortIDs{block};
283283

284284
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
285285
stream << shortIDs;

0 commit comments

Comments
 (0)