2121class TxOrphanage {
2222public:
2323 /* * Add a new orphan transaction */
24- bool AddTx (const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
24+ bool AddTx (const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
2525
2626 /* * Check if we already have an orphan transaction (by txid or wtxid) */
27- bool HaveTx (const GenTxid& gtxid) const EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
27+ bool HaveTx (const GenTxid& gtxid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
2828
2929 /* * Extract a transaction from a peer's work set
3030 * Returns nullptr and sets more to false if there are no transactions
@@ -33,33 +33,33 @@ class TxOrphanage {
3333 * the originating peer, and whether there are more orphans for this peer
3434 * to work on after this tx.
3535 */
36- CTransactionRef GetTxToReconsider (NodeId peer, NodeId& originator, bool & more) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
36+ CTransactionRef GetTxToReconsider (NodeId peer, NodeId& originator, bool & more) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
3737
3838 /* * Erase an orphan by txid */
39- int EraseTx (const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
39+ int EraseTx (const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
4040
4141 /* * Erase all orphans announced by a peer (eg, after that peer disconnects) */
42- void EraseForPeer (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
42+ void EraseForPeer (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
4343
4444 /* * Erase all orphans included in or invalidated by a new block */
45- void EraseForBlock (const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
45+ void EraseForBlock (const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
4646
4747 /* * Limit the orphanage to the given maximum */
48- void LimitOrphans (unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
48+ void LimitOrphans (unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
4949
5050 /* * Add any orphans that list a particular tx as a parent into a peer's work set */
51- void AddChildrenToWorkSet (const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans );
51+ void AddChildrenToWorkSet (const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex );
5252
5353 /* * Return how many entries exist in the orphange */
54- size_t Size () EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans )
54+ size_t Size () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex )
5555 {
56- LOCK (g_cs_orphans );
56+ LOCK (m_mutex );
5757 return m_orphans.size ();
5858 }
5959
6060protected:
6161 /* * Guards orphan transactions */
62- static RecursiveMutex g_cs_orphans ;
62+ mutable Mutex m_mutex ;
6363
6464 struct OrphanTx {
6565 CTransactionRef tx;
@@ -70,10 +70,10 @@ class TxOrphanage {
7070
7171 /* * Map from txid to orphan transaction record. Limited by
7272 * -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
73- std::map<uint256, OrphanTx> m_orphans GUARDED_BY (g_cs_orphans );
73+ std::map<uint256, OrphanTx> m_orphans GUARDED_BY (m_mutex );
7474
7575 /* * Which peer provided a parent tx of orphans that need to be reconsidered */
76- std::map<NodeId, std::set<uint256>> m_peer_work_set GUARDED_BY (g_cs_orphans );
76+ std::map<NodeId, std::set<uint256>> m_peer_work_set GUARDED_BY (m_mutex );
7777
7878 using OrphanMap = decltype (m_orphans);
7979
@@ -88,17 +88,17 @@ class TxOrphanage {
8888
8989 /* * Index from the parents' COutPoint into the m_orphans. Used
9090 * to remove orphan transactions from the m_orphans */
91- std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY (g_cs_orphans );
91+ std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY (m_mutex );
9292
9393 /* * Orphan transactions in vector for quick random eviction */
94- std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY (g_cs_orphans );
94+ std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY (m_mutex );
9595
9696 /* * Index from wtxid into the m_orphans to lookup orphan
9797 * transactions using their witness ids. */
98- std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY (g_cs_orphans );
98+ std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY (m_mutex );
9999
100100 /* * Erase an orphan by txid */
101- int _EraseTx (const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans );
101+ int _EraseTx (const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex );
102102};
103103
104104#endif // BITCOIN_TXORPHANAGE_H
0 commit comments