Skip to content

Commit

Permalink
Merge bitcoin#15201: net: Add missing locking annotation for vNodes. …
Browse files Browse the repository at this point in the history
…vNodes is guarded by cs_vNodes.

eea02be Add locking annotation for vNodes. vNodes is guarded by cs_vNodes. (practicalswift)

Pull request description:

  Add locking annotation for `vNodes`. `vNodes` is guarded by `cs_vNodes`.

Tree-SHA512: b1e18be22ba5b9dd153536380321b09b30a75a20575f975af9af94164f51982b32267ba0994e77c801513b59da05d923a974a9d2dfebdac48024c4bda98b53af
  • Loading branch information
MarcoFalke authored and gades committed May 18, 2022
1 parent 92f44f7 commit 7f17a76
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/net.h
Expand Up @@ -218,7 +218,18 @@ friend class CNode;
CConnman(uint64_t seed0, uint64_t seed1);
~CConnman();
bool Start(CScheduler& scheduler, const Options& options);
void Stop();

// TODO: Remove NO_THREAD_SAFETY_ANALYSIS. Lock cs_vNodes before reading the variable vNodes.
//
// When removing NO_THREAD_SAFETY_ANALYSIS be aware of the following lock order requirements:
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
// which locks cs_vNodes.
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
// locks cs_vNodes.
//
// Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
void Stop() NO_THREAD_SAFETY_ANALYSIS;

void Interrupt();
bool GetNetworkActive() const { return fNetworkActive; };
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
Expand Down Expand Up @@ -572,7 +583,7 @@ friend class CNode;
std::map<std::pair<Consensus::LLMQType, uint256>, std::set<uint256>> masternodeQuorumRelayMembers; // protected by cs_vPendingMasternodes
std::set<uint256> masternodePendingProbes;
mutable CCriticalSection cs_vPendingMasternodes;
std::vector<CNode*> vNodes;
std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
std::list<CNode*> vNodesDisconnected;
std::unordered_map<SOCKET, CNode*> mapSocketToNode;
mutable CCriticalSection cs_vNodes;
Expand Down

0 comments on commit 7f17a76

Please sign in to comment.