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);
CBlockHeaderAndShortTxIDs cmpctblock{*pblock};
nit: {}
Done (here and all other lines I touched)
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);
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock);
nit: space
auto pcmpctblock{std::make_shared<const CBlockHeaderAndShortTxIDs>(*pblock)};
nit: Or maybe even use auto :sweat_smile:
nit: Or maybe even inline into lazy_ser to avoid constructing it when there is no need to. (Might minimally speed up IBD?)
Removed space
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.
Yeah, I missed that assignment. Seems fine to just move it down for now.
lgtm
Concept ACK. I will give a full ACK once you resolve Marko's suggestions, which I endorse too.
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
Thanks for the review @MarcoFalke and @naumenkogs. I've addressed all your comments.
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); })};
std::async(std::launch::deferred, [&] { return CNetMsgMaker{PROTOCOL_VERSION}.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
nit
Done
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()};
I think it is fine to leave untouched lines as-is.
I moved this variable assignment down to where it's first used, so it's not untouched.
still lgtm
ACK 8184dcbdd18d8b732dc285a05884ecda115062e1
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);
It looks like we don't call 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.
Good catch! I've dropped the commit (this function could be tidied up a bit in terms of commenting/variable instantiation, but that doesn't seem strictly related to this PR).
Code review ACK bf6526f4a0ab30f77952ecdee90cd77dd9ba06f6
ACK bf6526f4a0ab30f77952ecdee90cd77dd9ba06f6