Skip to content

Commit fdb82a3

Browse files
committed
Merge bitcoin/bitcoin#25147: Net processing: follow ups to #20799 (removing support for v1 compact blocks)
bf6526f [test] Remove segwit argument from build_block_on_tip() (John Newbery) c65bf50 Remove fUseWTXID parameter from CBlockHeaderAndShortTxIDs constructor (John Newbery) Pull request description: This implements two of the suggestions from code reviews of PR 20799: - Remove fUseWTXID parameter from CBlockHeaderAndShortTxIDs constructor - Remove segwit argument from build_block_on_tip() ACKs for top commit: dergoegge: Code review ACK bf6526f naumenkogs: ACK bf6526f Tree-SHA512: d553791d1364b9e655183755e829b195c9b47f59c62371dbae49d9c0f8d84fec58cf18f4dde89591672ef5658e18c9cf0206c2efd70606980f87e506bc3bd4e5
2 parents 986bae8 + bf6526f commit fdb82a3

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
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
@@ -1666,7 +1666,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
16661666
*/
16671667
void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock)
16681668
{
1669-
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
1669+
auto pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
16701670
const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
16711671

16721672
LOCK(cs_main);
@@ -2013,7 +2013,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
20132013
if (a_recent_compact_block && a_recent_compact_block->header.GetHash() == pindex->GetBlockHash()) {
20142014
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CMPCTBLOCK, *a_recent_compact_block));
20152015
} else {
2016-
CBlockHeaderAndShortTxIDs cmpctblock(*pblock, true);
2016+
CBlockHeaderAndShortTxIDs cmpctblock{*pblock};
20172017
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
20182018
}
20192019
} else {
@@ -4814,7 +4814,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
48144814
CBlock block;
48154815
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
48164816
assert(ret);
4817-
CBlockHeaderAndShortTxIDs cmpctblock(block, true);
4817+
CBlockHeaderAndShortTxIDs cmpctblock{block};
48184818
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
48194819
}
48204820
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;

test/functional/p2p_compactblocks.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ def set_test_params(self):
146146
]]
147147
self.utxos = []
148148

149-
def build_block_on_tip(self, node, segwit=False):
149+
def build_block_on_tip(self, node):
150150
block = create_block(tmpl=node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS))
151-
if segwit:
152-
add_witness_commitment(block)
153151
block.solve()
154152
return block
155153

@@ -381,7 +379,7 @@ def test_compactblock_requests(self, test_node):
381379
# Try announcing a block with an inv or header, expect a compactblock
382380
# request
383381
for announce in ["inv", "header"]:
384-
block = self.build_block_on_tip(node, segwit=True)
382+
block = self.build_block_on_tip(node)
385383

386384
if announce == "inv":
387385
test_node.send_message(msg_inv([CInv(MSG_BLOCK, block.sha256)]))

0 commit comments

Comments
 (0)