Skip to content

Commit 5a6e3c1

Browse files
committed
refactor: Propagate negative !m_most_recent_block_mutex capability
Could be verified with $ ./configure CC=clang CXX=clang++ CXXFLAGS='-Wthread-safety -Wthread-safety-negative' $ make clean $ make 2>&1 | grep m_most_recent_block_mutex
1 parent 8c61374 commit 5a6e3c1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,16 @@ class PeerManagerImpl final : public PeerManager
472472
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
473473
void BlockChecked(const CBlock& block, const BlockValidationState& state) override
474474
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
475-
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
475+
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override
476+
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
476477

477478
/** Implement NetEventsInterface */
478479
void InitializeNode(CNode* pnode) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
479480
void FinalizeNode(const CNode& node) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
480481
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override
481-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex);
482+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex);
482483
bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing)
483-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex);
484+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex);
484485

485486
/** Implement PeerManager */
486487
void StartScheduledTasks(CScheduler& scheduler) override;
@@ -494,7 +495,7 @@ class PeerManagerImpl final : public PeerManager
494495
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
495496
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
496497
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override
497-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex);
498+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex);
498499
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) override;
499500

500501
private:
@@ -758,7 +759,8 @@ class PeerManagerImpl final : public PeerManager
758759
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
759760
CTransactionRef FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main);
760761

761-
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main);
762+
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
763+
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main);
762764

763765
/** Process a new block. Perform any post-processing housekeeping */
764766
void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing);
@@ -809,7 +811,8 @@ class PeerManagerImpl final : public PeerManager
809811
*/
810812
bool BlockRequestAllowed(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
811813
bool AlreadyHaveBlock(const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
812-
void ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& inv);
814+
void ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& inv)
815+
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
813816

814817
/**
815818
* Validation logic for compact filters request handling.

0 commit comments

Comments
 (0)