mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge bitcoin/bitcoin#24062: refactor: replace RecursiveMutex m_most_recent_block_mutex
with Mutex
83003ffe049a432f6fa4127e054f073127e70b90 refactor: replace RecursiveMutex `m_most_recent_block_mutex` with Mutex (Sebastian Falbesoner) 8edd0d31ac683378135a9839e5d4172b82f8f5b8 refactor: reduce scope of lock `m_most_recent_block_mutex` (Sebastian Falbesoner) Pull request description: This PR is related to #19303 and gets rid of the RecursiveMutex `m_most_recent_block_mutex`. All of the critical sections (5 in total) only directly access the guarded elements, i.e. it is not possible that within one section another one is called, and we can use a regular Mutex:b019cdc036/src/net_processing.cpp (L1650-L1655)
b019cdc036/src/net_processing.cpp (L1861-L1865)
b019cdc036/src/net_processing.cpp (L3149-L3152)
b019cdc036/src/net_processing.cpp (L3201-L3206)
b019cdc036/src/net_processing.cpp (L4763-L4769)
The scope of the last critical section is reduced in the first commit, in order to avoid calling the non-trivial method `CConnman::PushMessage` while the lock is held. ACKs for top commit: furszy: Code ACK 83003ffe with a small comment. hebasto: ACK 83003ffe049a432f6fa4127e054f073127e70b90 w0xlt: ACK83003ffe04
Tree-SHA512: 3df290cafd2f6c4d40afb9f14e822a77d9c1828e66f5e2233f3ac1deccc2b0a8290bc5fb8eb992f49d39e887b50bc0e9aad63e05db2d870791a8d409fb95695f
This commit is contained in:
parent
c91f010e0e
commit
de17997621
@ -906,7 +906,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// All of the following cache a recent block, and are protected by m_most_recent_block_mutex
|
// All of the following cache a recent block, and are protected by m_most_recent_block_mutex
|
||||||
RecursiveMutex m_most_recent_block_mutex;
|
Mutex m_most_recent_block_mutex;
|
||||||
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
|
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
|
||||||
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
|
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
|
||||||
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
|
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
|
||||||
@ -5676,15 +5676,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…
Reference in New Issue
Block a user