mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 08:51:55 +02:00
refactor: reduce scope of lock m_most_recent_block_mutex
This avoids calling the non-trivial method `CConnman::PushMessage` within the critical section.
This commit is contained in:
parent
aa3200d896
commit
8edd0d31ac
@ -4759,15 +4759,16 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||||||
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__,
|
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__,
|
||||||
vHeaders.front().GetHash().ToString(), pto->GetId());
|
vHeaders.front().GetHash().ToString(), pto->GetId());
|
||||||
|
|
||||||
bool fGotBlockFromCache = false;
|
std::optional<CSerializedNetMsg> cached_cmpctblock_msg;
|
||||||
{
|
{
|
||||||
LOCK(m_most_recent_block_mutex);
|
LOCK(m_most_recent_block_mutex);
|
||||||
if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) {
|
if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) {
|
||||||
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block));
|
cached_cmpctblock_msg = msgMaker.Make(NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block);
|
||||||
fGotBlockFromCache = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!fGotBlockFromCache) {
|
if (cached_cmpctblock_msg.has_value()) {
|
||||||
|
m_connman.PushMessage(pto, std::move(cached_cmpctblock_msg.value()));
|
||||||
|
} else {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
|
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user