Skip to content

Commit 7082ce3

Browse files
committed
scripted-diff: rename and de-globalise g_cs_orphans
-BEGIN VERIFY SCRIPT- sed -i -e 's/static RecursiveMutex/mutable Mutex/' src/txorphanage.h sed -i -e '/RecursiveMutex/d' src/txorphanage.cpp sed -i -e 's/g_cs_orphans/m_mutex/g' $(git grep -l g_cs_orphans src/) -END VERIFY SCRIPT-
1 parent 733d85f commit 7082ce3

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

src/test/orphanage_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
2020
class TxOrphanageTest : public TxOrphanage
2121
{
2222
public:
23-
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans)
23+
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
2424
{
25-
LOCK(g_cs_orphans);
25+
LOCK(m_mutex);
2626
return m_orphans.size();
2727
}
2828

29-
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans)
29+
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
3030
{
31-
LOCK(g_cs_orphans);
31+
LOCK(m_mutex);
3232
std::map<uint256, OrphanTx>::iterator it;
3333
it = m_orphans.lower_bound(InsecureRand256());
3434
if (it == m_orphans.end())

src/txorphanage.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
1515
/** Minimum time between orphan transactions expire time checks in seconds */
1616
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
1717

18-
RecursiveMutex TxOrphanage::g_cs_orphans;
1918

2019
bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
2120
{
22-
LOCK(g_cs_orphans);
21+
LOCK(m_mutex);
2322

2423
const uint256& hash = tx->GetHash();
2524
if (m_orphans.count(hash))
@@ -55,13 +54,13 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
5554

5655
int TxOrphanage::EraseTx(const uint256& txid)
5756
{
58-
LOCK(g_cs_orphans);
57+
LOCK(m_mutex);
5958
return _EraseTx(txid);
6059
}
6160

6261
int TxOrphanage::_EraseTx(const uint256& txid)
6362
{
64-
AssertLockHeld(g_cs_orphans);
63+
AssertLockHeld(m_mutex);
6564
std::map<uint256, OrphanTx>::iterator it = m_orphans.find(txid);
6665
if (it == m_orphans.end())
6766
return 0;
@@ -93,7 +92,7 @@ int TxOrphanage::_EraseTx(const uint256& txid)
9392

9493
void TxOrphanage::EraseForPeer(NodeId peer)
9594
{
96-
LOCK(g_cs_orphans);
95+
LOCK(m_mutex);
9796

9897
m_peer_work_set.erase(peer);
9998

@@ -112,7 +111,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
112111

113112
void TxOrphanage::LimitOrphans(unsigned int max_orphans)
114113
{
115-
LOCK(g_cs_orphans);
114+
LOCK(m_mutex);
116115

117116
unsigned int nEvicted = 0;
118117
static int64_t nNextSweep;
@@ -148,7 +147,7 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
148147

149148
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, NodeId peer)
150149
{
151-
LOCK(g_cs_orphans);
150+
LOCK(m_mutex);
152151

153152
// Get this peer's work set, emplacing an empty set it didn't exist
154153
std::set<uint256>& orphan_work_set = m_peer_work_set.try_emplace(peer).first->second;
@@ -165,7 +164,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, NodeId peer)
165164

166165
bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
167166
{
168-
LOCK(g_cs_orphans);
167+
LOCK(m_mutex);
169168
if (gtxid.IsWtxid()) {
170169
return m_wtxid_to_orphan_it.count(gtxid.GetHash());
171170
} else {
@@ -175,7 +174,7 @@ bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
175174

176175
CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer, NodeId& originator, bool& more)
177176
{
178-
LOCK(g_cs_orphans);
177+
LOCK(m_mutex);
179178

180179
auto work_set_it = m_peer_work_set.find(peer);
181180
if (work_set_it != m_peer_work_set.end()) {
@@ -198,7 +197,7 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer, NodeId& originator,
198197

199198
void TxOrphanage::EraseForBlock(const CBlock& block)
200199
{
201-
LOCK(g_cs_orphans);
200+
LOCK(m_mutex);
202201

203202
std::vector<uint256> vOrphanErase;
204203

src/txorphanage.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
class TxOrphanage {
2222
public:
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

6060
protected:
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

Comments
 (0)