diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2022-01-25 16:10:01 +0100 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2022-05-16 15:26:37 +0200 |
commit | 8edd0d31ac683378135a9839e5d4172b82f8f5b8 (patch) | |
tree | 0ec28adf637c97a8b59b05b633634689f85df72b | |
parent | aa3200d8967215dc93ea75e19db0aca537ec3d35 (diff) |
refactor: reduce scope of lock `m_most_recent_block_mutex`
This avoids calling the non-trivial method
`CConnman::PushMessage` within the critical section.
-rw-r--r-- | src/net_processing.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 349d7fd8fb..8f875e6d27 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4759,15 +4759,16 @@ bool PeerManagerImpl::SendMessages(CNode* pto) LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__, vHeaders.front().GetHash().ToString(), pto->GetId()); - bool fGotBlockFromCache = false; + std::optional<CSerializedNetMsg> cached_cmpctblock_msg; { LOCK(m_most_recent_block_mutex); if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) { - m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block)); - fGotBlockFromCache = true; + cached_cmpctblock_msg = msgMaker.Make(NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block); } } - if (!fGotBlockFromCache) { + if (cached_cmpctblock_msg.has_value()) { + m_connman.PushMessage(pto, std::move(cached_cmpctblock_msg.value())); + } else { CBlock block; bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams); assert(ret); |