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()
This implements two of the suggestions from code reviews of PR 20799:
1977@@ -1978,7 +1978,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
1978 if (a_recent_compact_block && a_recent_compact_block->header.GetHash() == pindex->GetBlockHash()) {
1979 m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CMPCTBLOCK, *a_recent_compact_block));
1980 } else {
1981- CBlockHeaderAndShortTxIDs cmpctblock(*pblock, true);
1982+ CBlockHeaderAndShortTxIDs cmpctblock(*pblock);
0 CBlockHeaderAndShortTxIDs cmpctblock{*pblock};
nit: {}
1631@@ -1632,7 +1632,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
1632 */
1633 void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock)
1634 {
1635- std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
1636+ std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock);
0 std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
nit: space
0 auto pcmpctblock{std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock)};
nit: Or maybe even use auto
:sweat_smile:
I’ve changed to auto
.
Or maybe even inline into lazy_ser to avoid constructing it when there is no need to. (Might minimally speed up IBD?)
I’m not sure how this would work. pcmpctblock
is required further down the function outside the lazy_ser lambda. I have moved the instantiation below the early exits, which I think addresses your point about speeding up IBD.
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 https://github.com/bitcoin/bitcoin/pull/20799#pullrequestreview-963480278
1639@@ -1643,10 +1640,11 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
1640
1641 if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) return;
1642
1643- uint256 hashBlock(pblock->GetHash());
1644+ auto pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
1645 const std::shared_future<CSerializedNetMsg> lazy_ser{
1646- std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
1647+ std::async(std::launch::deferred, [&] { return CNetMsgMaker(PROTOCOL_VERSION).Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
0 std::async(std::launch::deferred, [&] { return CNetMsgMaker{PROTOCOL_VERSION}.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
nit
1644+ auto pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
1645 const std::shared_future<CSerializedNetMsg> lazy_ser{
1646- std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
1647+ std::async(std::launch::deferred, [&] { return CNetMsgMaker(PROTOCOL_VERSION).Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
1648
1649+ uint256 hashBlock{pblock->GetHash()};
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.
Suggested in https://github.com/bitcoin/bitcoin/pull/20799#discussion_r867782119
1639@@ -1643,10 +1640,11 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
1640
1641 if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) return;
1642
1643- uint256 hashBlock(pblock->GetHash());
1644+ auto pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
NewPoWValidBlock
while we are in IBD (see here), so 40ae3107956e2425c4a3cf0cb3a4a2d6d952894c won’t really affect IBD speed. Consider dropping that commit or changing the commit message if there is another motivation for the change.