Skip to content

Commit 6ff8406

Browse files
committed
remove obsoleted TxOrphanage::m_mutex
The TxOrphanage is now guarded externally by m_tx_download_mutex.
1 parent 61745c7 commit 6ff8406

File tree

3 files changed

+20
-48
lines changed

3 files changed

+20
-48
lines changed

src/test/orphanage_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
2121
class TxOrphanageTest : public TxOrphanage
2222
{
2323
public:
24-
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
24+
inline size_t CountOrphans() const
2525
{
26-
LOCK(m_mutex);
2726
return m_orphans.size();
2827
}
2928

30-
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
29+
CTransactionRef RandomOrphan()
3130
{
32-
LOCK(m_mutex);
3331
std::map<Wtxid, OrphanTx>::iterator it;
3432
it = m_orphans.lower_bound(Wtxid::FromUint256(InsecureRand256()));
3533
if (it == m_orphans.end())

src/txorphanage.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ static constexpr auto ORPHAN_TX_EXPIRE_INTERVAL{5min};
2020

2121
bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
2222
{
23-
LOCK(m_mutex);
24-
2523
const Txid& hash = tx->GetHash();
2624
const Wtxid& wtxid = tx->GetWitnessHash();
2725
if (m_orphans.count(wtxid))
@@ -55,13 +53,11 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
5553

5654
int TxOrphanage::EraseTx(const Wtxid& wtxid)
5755
{
58-
LOCK(m_mutex);
5956
return EraseTxNoLock(wtxid);
6057
}
6158

6259
int TxOrphanage::EraseTxNoLock(const Wtxid& wtxid)
6360
{
64-
AssertLockHeld(m_mutex);
6561
std::map<Wtxid, OrphanTx>::iterator it = m_orphans.find(wtxid);
6662
if (it == m_orphans.end())
6763
return 0;
@@ -97,8 +93,6 @@ int TxOrphanage::EraseTxNoLock(const Wtxid& wtxid)
9793

9894
void TxOrphanage::EraseForPeer(NodeId peer)
9995
{
100-
LOCK(m_mutex);
101-
10296
m_peer_work_set.erase(peer);
10397

10498
int nErased = 0;
@@ -116,8 +110,6 @@ void TxOrphanage::EraseForPeer(NodeId peer)
116110

117111
void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
118112
{
119-
LOCK(m_mutex);
120-
121113
unsigned int nEvicted = 0;
122114
auto nNow{Now<NodeSeconds>()};
123115
if (m_next_sweep <= nNow) {
@@ -150,9 +142,6 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
150142

151143
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
152144
{
153-
LOCK(m_mutex);
154-
155-
156145
for (unsigned int i = 0; i < tx.vout.size(); i++) {
157146
const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
158147
if (it_by_prev != m_outpoint_to_orphan_it.end()) {
@@ -171,14 +160,11 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
171160

172161
bool TxOrphanage::HaveTx(const Wtxid& wtxid) const
173162
{
174-
LOCK(m_mutex);
175163
return m_orphans.count(wtxid);
176164
}
177165

178166
CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
179167
{
180-
LOCK(m_mutex);
181-
182168
auto work_set_it = m_peer_work_set.find(peer);
183169
if (work_set_it != m_peer_work_set.end()) {
184170
auto& work_set = work_set_it->second;
@@ -197,8 +183,6 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
197183

198184
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
199185
{
200-
LOCK(m_mutex);
201-
202186
auto work_set_it = m_peer_work_set.find(peer);
203187
if (work_set_it != m_peer_work_set.end()) {
204188
auto& work_set = work_set_it->second;
@@ -209,8 +193,6 @@ bool TxOrphanage::HaveTxToReconsider(NodeId peer)
209193

210194
void TxOrphanage::EraseForBlock(const CBlock& block)
211195
{
212-
LOCK(m_mutex);
213-
214196
std::vector<Wtxid> vOrphanErase;
215197

216198
for (const CTransactionRef& ptx : block.vtx) {
@@ -239,8 +221,6 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
239221

240222
std::vector<CTransactionRef> TxOrphanage::GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const
241223
{
242-
LOCK(m_mutex);
243-
244224
// First construct a vector of iterators to ensure we do not return duplicates of the same tx
245225
// and so we can sort by nTimeExpire.
246226
std::vector<OrphanMap::iterator> iters;
@@ -281,8 +261,6 @@ std::vector<CTransactionRef> TxOrphanage::GetChildrenFromSamePeer(const CTransac
281261

282262
std::vector<std::pair<CTransactionRef, NodeId>> TxOrphanage::GetChildrenFromDifferentPeer(const CTransactionRef& parent, NodeId nodeid) const
283263
{
284-
LOCK(m_mutex);
285-
286264
// First construct vector of iterators to ensure we do not return duplicates of the same tx.
287265
std::vector<OrphanMap::iterator> iters;
288266

src/txorphanage.h

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,51 @@
2222
class TxOrphanage {
2323
public:
2424
/** Add a new orphan transaction */
25-
bool AddTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
25+
bool AddTx(const CTransactionRef& tx, NodeId peer);
2626

2727
/** Check if we already have an orphan transaction (by wtxid only) */
28-
bool HaveTx(const Wtxid& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
28+
bool HaveTx(const Wtxid& wtxid) const;
2929

3030
/** Extract a transaction from a peer's work set
3131
* Returns nullptr if there are no transactions to work on.
3232
* Otherwise returns the transaction reference, and removes
3333
* it from the work set.
3434
*/
35-
CTransactionRef GetTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
35+
CTransactionRef GetTxToReconsider(NodeId peer);
3636

3737
/** Erase an orphan by wtxid */
38-
int EraseTx(const Wtxid& wtxid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
38+
int EraseTx(const Wtxid& wtxid);
3939

4040
/** Erase all orphans announced by a peer (eg, after that peer disconnects) */
41-
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
41+
void EraseForPeer(NodeId peer);
4242

4343
/** Erase all orphans included in or invalidated by a new block */
44-
void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
44+
void EraseForBlock(const CBlock& block);
4545

4646
/** Limit the orphanage to the given maximum */
47-
void LimitOrphans(unsigned int max_orphans, FastRandomContext& rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
47+
void LimitOrphans(unsigned int max_orphans, FastRandomContext& rng);
4848

4949
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
50-
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
50+
void AddChildrenToWorkSet(const CTransaction& tx);
5151

5252
/** Does this peer have any work to do? */
53-
bool HaveTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
53+
bool HaveTxToReconsider(NodeId peer);
5454

5555
/** Get all children that spend from this tx and were received from nodeid. Sorted from most
5656
* recent to least recent. */
57-
std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
57+
std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const;
5858

5959
/** Get all children that spend from this tx but were not received from nodeid. Also return
6060
* which peer provided each tx. */
61-
std::vector<std::pair<CTransactionRef, NodeId>> GetChildrenFromDifferentPeer(const CTransactionRef& parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
61+
std::vector<std::pair<CTransactionRef, NodeId>> GetChildrenFromDifferentPeer(const CTransactionRef& parent, NodeId nodeid) const;
6262

6363
/** Return how many entries exist in the orphange */
64-
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
64+
size_t Size()
6565
{
66-
LOCK(m_mutex);
6766
return m_orphans.size();
6867
}
6968

7069
protected:
71-
/** Guards orphan transactions */
72-
mutable Mutex m_mutex;
73-
7470
struct OrphanTx {
7571
CTransactionRef tx;
7672
NodeId fromPeer;
@@ -80,10 +76,10 @@ class TxOrphanage {
8076

8177
/** Map from wtxid to orphan transaction record. Limited by
8278
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
83-
std::map<Wtxid, OrphanTx> m_orphans GUARDED_BY(m_mutex);
79+
std::map<Wtxid, OrphanTx> m_orphans;
8480

8581
/** Which peer provided the orphans that need to be reconsidered */
86-
std::map<NodeId, std::set<Wtxid>> m_peer_work_set GUARDED_BY(m_mutex);
82+
std::map<NodeId, std::set<Wtxid>> m_peer_work_set;
8783

8884
using OrphanMap = decltype(m_orphans);
8985

@@ -98,16 +94,16 @@ class TxOrphanage {
9894

9995
/** Index from the parents' COutPoint into the m_orphans. Used
10096
* to remove orphan transactions from the m_orphans */
101-
std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY(m_mutex);
97+
std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it;
10298

10399
/** Orphan transactions in vector for quick random eviction */
104-
std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY(m_mutex);
100+
std::vector<OrphanMap::iterator> m_orphan_list;
105101

106102
/** Erase an orphan by wtxid */
107-
int EraseTxNoLock(const Wtxid& wtxid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
103+
int EraseTxNoLock(const Wtxid& wtxid);
108104

109105
/** Timestamp for the next scheduled sweep of expired orphans */
110-
NodeSeconds m_next_sweep GUARDED_BY(m_mutex){0s};
106+
NodeSeconds m_next_sweep{0s};
111107
};
112108

113109
#endif // BITCOIN_TXORPHANAGE_H

0 commit comments

Comments
 (0)