Repository: bitcoin
Issue: Replace all of the RecursiveMutex instances with the Mutex ones
Labels: Brainstorming,Refactoring

**UPD 2023-04-18**. See a shortlist [here](https://github.com/bitcoin/bitcoin/issues/19303#issuecomment-1513337566).

---

This is a tracking issue for the long-term goal to replace all of the `RecursiveMutex` instances with the `Mutex` ones throughout the code base.

Anthony Williams (_C++ Concurrency in Action_, 2019, 3.3.3 Recursive locking):
> Most of the time, if you think you want a recursive mutex, you probably need to change your design instead.

Anthony Towns, https://github.com/bitcoin/bitcoin/issues/19303#issuecomment-646956780:
> ... the actual goal is "make locking logic easier to follow" rather than "remove RecurviseMutex"

Should be noted, to insure that mutex locking policy has not been changed by accident in non-trivial cases, all of the related code branches must be covered by appropriate lock assertions: `AssertLockHeld()` or `AssertLockNotHeld()`.

Also Clang Thread Safety Analysis annotations with [Negative Capabilities](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative) are very useful (see #19249) but are not a panacea, of course :)

---

- [x] `RecursiveMutex cs_Shutdown` (#19180)
- [x] `RecursiveMutex cs_nTimeOffset` (#19189)
- [x] `RecursiveMutex cs_proxyInfos` (#19190)
- ~`RecursiveMutex csPathCached` (#19213)~
- [x] `RecursiveMutex cs_warnings` (#19220)
- [x] `RecursiveMutex CAddrMan::cs` (#19238)
- [x] `RecursiveMutex BanMan::m_cs_banned` (#24092, #24097)
- [x] `RecursiveMutex cs_mapLocalHost` (#24099)
- [x] `RecursiveMutex CConnman::cs_totalBytesRecv` (#22829)
- [x] `RecursiveMutex CConnman::cs_totalBytesSent` (#24157)
- [x] `RecursiveMutex CConnman::m_addr_fetches_mutex` (#22829)
- [x] `RecursiveMutex CConnman::cs_vAddedNodes` (#22829)
- [ ] `RecursiveMutex CConnman::m_nodes_mutex`
- [x] `RecursiveMutex CNode::cs_vSend` (#19915)
- [x] `RecursiveMutex CNode::cs_hSocket` (#19915)
- [x] `RecursiveMutex CNode::cs_vRecv` (#19915)
- ~`RecursiveMutex CNode::cs_vProcessMsg` (#24122)~
- ~`RecursiveMutex CNode::cs_sendProcessing` (#25597)~
- [x] `RecursiveMutex CNode::cs_SubVer` (#24079)
- [x] `RecursiveMutex CNode::cs_inventory` (#19347)
- [x] `RecursiveMutex CNode::cs_addrName` (removed in #22782)
- [x] `RecursiveMutex CNode::cs_addrLocal` #24108
- [ ] `RecursiveMutex Peer::TxRelay::m_bloom_filter_mutex`
- [ ] `RecursiveMutex Peer::TxRelay::m_tx_inventory_mutex` (#24125)
- [x] `RecursiveMutex CNode::TxRelay::cs_feeFilter` (#18819)
- ~`RecursiveMutex g_cs_orphans`~
- [x] `RecursiveMutex g_cs_recent_confirmed_transactions` (#19378)
- [x] `RecursiveMutex cs_most_recent_block` (#24062)
- [x] `RecursiveMutex CBlockPolicyEstimator::m_cs_fee_estimator` (#22014)
- [x] `RecursiveMutex cs_rpcWarmup` (#19399)
- [x] `RecursiveMutex SingleThreadedSchedulerClient::m_cs_callbacks_pending` (#24069)
- [ ] `RecursiveMutex BlockManager::cs_LastBlockFile`
- [ ] `RecursiveMutex FillableSigningProvider::cs_KeyStore`
- [ ] `RecursiveMutex ArgsManager::cs_args`
- [x] `RecursiveMutex CChainState::cs_nBlockSequenceId` (#22824)
- [x] `RecursiveMutex CChainState::m_cs_chainstate` (#24103)
- [ ] `RecursiveMutex cs_db`
- [ ] `RecursiveMutex DescriptorScriptPubKeyMan::cs_desc_man`
- [x] `RecursiveMutex cs_wallets` (#19101)
- [ ] `RecursiveMutex CWallet::cs_wallet` (#19773,  #19833)

and

- `RecursiveMutex CTxMemPool::cs` (#19306, ~#19647~, #19652, #19854, #19872, #19901, #19909, #19917)
- `RecursiveMutex cs_main`