diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-03-21 09:59:03 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-03-21 10:00:40 +0100 |
commit | 6c72f3192a2b4e6851b03e1ec34c53fc014ba24a (patch) | |
tree | f9ccfc622320672fffeafaee35ad7ac913cb3a64 /src | |
parent | 75e34ed718fd24fa742e0355d69fbb60bafdb02e (diff) | |
parent | fa61dd44f99323d10b0122c13224bc5cdb5e3d2a (diff) | |
download | bitcoin-6c72f3192a2b4e6851b03e1ec34c53fc014ba24a.tar.xz |
Merge bitcoin/bitcoin#23880: p2p: Serialize cmpctblock at most once in NewPoWValidBlock
fa61dd44f99323d10b0122c13224bc5cdb5e3d2a p2p: Serialize cmpctblock at most once in NewPoWValidBlock (MarcoFalke)
Pull request description:
Instead of serializing for each peer, serialize at most once and copy the raw data for each peer.
ACKs for top commit:
shaavan:
reACK fa61dd44f99323d10b0122c13224bc5cdb5e3d2a
theStack:
Code-review ACK fa61dd44f99323d10b0122c13224bc5cdb5e3d2a
Tree-SHA512: ed029aeaea67fdac8ddb865069f8166bc0dd8480418c405628e3e1a43b61161584a09a1814668bcd220602e8732e188be2bfed9242aa81bdbd92c64c702ed138
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 59cd83e493..77efac3364 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -41,6 +41,7 @@ #include <algorithm> #include <atomic> #include <chrono> +#include <future> #include <memory> #include <optional> #include <typeinfo> @@ -1596,6 +1597,8 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha bool fWitnessEnabled = DeploymentActiveAt(*pindex, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT); uint256 hashBlock(pblock->GetHash()); + const std::shared_future<CSerializedNetMsg> lazy_ser{ + std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })}; { LOCK(cs_most_recent_block); @@ -1605,10 +1608,9 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled; } - m_connman.ForEachNode([this, &pcmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { + m_connman.ForEachNode([this, pindex, fWitnessEnabled, &lazy_ser, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { AssertLockHeld(::cs_main); - // TODO: Avoid the repeated-serialization here if (pnode->GetCommonVersion() < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect) return; ProcessBlockAvailability(pnode->GetId()); @@ -1620,7 +1622,9 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", "PeerManager::NewPoWValidBlock", hashBlock.ToString(), pnode->GetId()); - m_connman.PushMessage(pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock)); + + const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()}; + m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type}); state.pindexBestHeaderSent = pindex; } }); |