21
21
class TxOrphanage {
22
22
public:
23
23
/* * 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 );
25
25
26
26
/* * 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 );
28
28
29
29
/* * Extract a transaction from a peer's work set
30
30
* Returns nullptr and sets more to false if there are no transactions
@@ -33,33 +33,33 @@ class TxOrphanage {
33
33
* the originating peer, and whether there are more orphans for this peer
34
34
* to work on after this tx.
35
35
*/
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 );
37
37
38
38
/* * 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 );
40
40
41
41
/* * 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 );
43
43
44
44
/* * 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 );
46
46
47
47
/* * 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 );
49
49
50
50
/* * 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 );
52
52
53
53
/* * 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 )
55
55
{
56
- LOCK (g_cs_orphans );
56
+ LOCK (m_mutex );
57
57
return m_orphans.size ();
58
58
}
59
59
60
60
protected:
61
61
/* * Guards orphan transactions */
62
- static RecursiveMutex g_cs_orphans ;
62
+ mutable Mutex m_mutex ;
63
63
64
64
struct OrphanTx {
65
65
CTransactionRef tx;
@@ -70,10 +70,10 @@ class TxOrphanage {
70
70
71
71
/* * Map from txid to orphan transaction record. Limited by
72
72
* -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 );
74
74
75
75
/* * 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 );
77
77
78
78
using OrphanMap = decltype (m_orphans);
79
79
@@ -88,17 +88,17 @@ class TxOrphanage {
88
88
89
89
/* * Index from the parents' COutPoint into the m_orphans. Used
90
90
* 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 );
92
92
93
93
/* * 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 );
95
95
96
96
/* * Index from wtxid into the m_orphans to lookup orphan
97
97
* 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 );
99
99
100
100
/* * 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 );
102
102
};
103
103
104
104
#endif // BITCOIN_TXORPHANAGE_H
0 commit comments