diff options
author | Anthony Towns <aj@erisian.com.au> | 2022-10-07 14:25:47 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2022-10-11 23:35:32 +1000 |
commit | 733d85f79cde353d8c9b54370f296b1031fa33d9 (patch) | |
tree | d82f4afe95a9e61ff84eeac104d118013c44a372 /src/txorphanage.h | |
parent | a936f41a5d5f7bb97425f82ec64dfae62e840a56 (diff) |
Move all g_cs_orphans locking to txorphanage
Diffstat (limited to 'src/txorphanage.h')
-rw-r--r-- | src/txorphanage.h | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/txorphanage.h b/src/txorphanage.h index 5af1f2f0e0..91cfb7786d 100644 --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -13,9 +13,6 @@ #include <map> #include <set> -/** Guards orphan transactions */ -extern RecursiveMutex g_cs_orphans; - /** A class to track orphan transactions (failed on TX_MISSING_INPUTS) * Since we cannot distinguish orphans from bad transactions with * non-existent inputs, we heavily limit the number of orphans @@ -24,10 +21,10 @@ extern RecursiveMutex g_cs_orphans; class TxOrphanage { public: /** Add a new orphan transaction */ - bool AddTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + bool AddTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Check if we already have an orphan transaction (by txid or wtxid) */ - bool HaveTx(const GenTxid& gtxid) const LOCKS_EXCLUDED(::g_cs_orphans); + bool HaveTx(const GenTxid& gtxid) const EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Extract a transaction from a peer's work set * Returns nullptr and sets more to false if there are no transactions @@ -36,31 +33,34 @@ public: * the originating peer, and whether there are more orphans for this peer * to work on after this tx. */ - CTransactionRef GetTxToReconsider(NodeId peer, NodeId& originator, bool& more) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + CTransactionRef GetTxToReconsider(NodeId peer, NodeId& originator, bool& more) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Erase an orphan by txid */ - int EraseTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + int EraseTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Erase all orphans announced by a peer (eg, after that peer disconnects) */ - void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Erase all orphans included in or invalidated by a new block */ - void EraseForBlock(const CBlock& block) LOCKS_EXCLUDED(::g_cs_orphans); + void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Limit the orphanage to the given maximum */ - void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Add any orphans that list a particular tx as a parent into a peer's work set */ - void AddChildrenToWorkSet(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); + void AddChildrenToWorkSet(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Return how many entries exist in the orphange */ - size_t Size() LOCKS_EXCLUDED(::g_cs_orphans) + size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans) { - LOCK(::g_cs_orphans); + LOCK(g_cs_orphans); return m_orphans.size(); } protected: + /** Guards orphan transactions */ + static RecursiveMutex g_cs_orphans; + struct OrphanTx { CTransactionRef tx; NodeId fromPeer; @@ -96,6 +96,9 @@ protected: /** Index from wtxid into the m_orphans to lookup orphan * transactions using their witness ids. */ std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY(g_cs_orphans); + + /** Erase an orphan by txid */ + int _EraseTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); }; #endif // BITCOIN_TXORPHANAGE_H |