@@ -687,7 +687,7 @@ class PeerManagerImpl final : public PeerManager
687
687
688
688
689
689
// All of the following cache a recent block, and are protected by m_most_recent_block_mutex
690
- RecursiveMutex m_most_recent_block_mutex;
690
+ Mutex m_most_recent_block_mutex;
691
691
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY (m_most_recent_block_mutex);
692
692
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY (m_most_recent_block_mutex);
693
693
uint256 m_most_recent_block_hash GUARDED_BY (m_most_recent_block_mutex);
@@ -4759,15 +4759,16 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4759
4759
LogPrint (BCLog::NET, " %s sending header-and-ids %s to peer=%d\n " , __func__,
4760
4760
vHeaders.front ().GetHash ().ToString (), pto->GetId ());
4761
4761
4762
- bool fGotBlockFromCache = false ;
4762
+ std::optional<CSerializedNetMsg> cached_cmpctblock_msg ;
4763
4763
{
4764
4764
LOCK (m_most_recent_block_mutex);
4765
4765
if (m_most_recent_block_hash == pBestIndex->GetBlockHash ()) {
4766
- m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block));
4767
- fGotBlockFromCache = true ;
4766
+ cached_cmpctblock_msg = msgMaker.Make (NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block);
4768
4767
}
4769
4768
}
4770
- if (!fGotBlockFromCache ) {
4769
+ if (cached_cmpctblock_msg.has_value ()) {
4770
+ m_connman.PushMessage (pto, std::move (cached_cmpctblock_msg.value ()));
4771
+ } else {
4771
4772
CBlock block;
4772
4773
bool ret = ReadBlockFromDisk (block, pBestIndex, consensusParams);
4773
4774
assert (ret);
0 commit comments