Bitcoin ABC  0.26.3
P2P Digital Currency
txorphanage.h
Go to the documentation of this file.
1 // Copyright (c) 2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_TXORPHANAGE_H
6 #define BITCOIN_TXORPHANAGE_H
7 
8 #include <net.h>
9 #include <primitives/block.h>
10 #include <primitives/transaction.h>
11 #include <sync.h>
12 
15 
22 class TxOrphanage {
23 public:
25  bool AddTx(const CTransactionRef &tx, NodeId peer)
27 
29  bool HaveTx(const TxId &txid) const LOCKS_EXCLUDED(g_cs_orphans);
30 
35  std::pair<CTransactionRef, NodeId> GetTx(const TxId &txid) const
37 
40 
45 
47  void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(g_cs_orphans);
48 
50  unsigned int LimitOrphans(unsigned int max_orphans)
52 
58  void AddChildrenToWorkSet(const CTransaction &tx,
59  std::set<TxId> &orphan_work_set) const
61 
62 protected:
63  struct OrphanTx {
66  int64_t nTimeExpire;
67  size_t list_pos;
68  };
69 
74  std::map<TxId, OrphanTx> m_orphans GUARDED_BY(g_cs_orphans);
75 
76  using OrphanMap = decltype(m_orphans);
77 
79  template <typename I> bool operator()(const I &a, const I &b) const {
80  return &(*a) < &(*b);
81  }
82  };
83 
88  std::map<COutPoint, std::set<OrphanMap ::iterator, IteratorComparator>>
89  m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans);
90 
92  std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY(g_cs_orphans);
93 };
94 
95 #endif // BITCOIN_TXORPHANAGE_H
Definition: block.h:55
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition: txorphanage.h:22
decltype(m_orphans) OrphanMap
Definition: txorphanage.h:76
bool HaveTx(const TxId &txid) const LOCKS_EXCLUDED(g_cs_orphans)
Check if we already have an orphan transaction.
std::pair< CTransactionRef, NodeId > GetTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Get an orphan transaction and its originating peer (Transaction ref will be nullptr if not found)
void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(g_cs_orphans)
Erase all orphans included in or invalidated by a new block.
std::map< TxId, OrphanTx > m_orphans GUARDED_BY(g_cs_orphans)
Map from txid to orphan transaction record.
std::map< COutPoint, std::set< OrphanMap ::iterator, IteratorComparator > > m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans)
Index from the parents' COutPoint into the m_orphans.
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans announced by a peer (eg, after that peer disconnects)
Definition: txorphanage.cpp:88
std::vector< OrphanMap::iterator > m_orphan_list GUARDED_BY(g_cs_orphans)
Orphan transactions in vector for quick random eviction.
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add a new orphan transaction.
Definition: txorphanage.cpp:20
unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Limit the orphanage to the given maximum.
void AddChildrenToWorkSet(const CTransaction &tx, std::set< TxId > &orphan_work_set) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add any orphans that list a particular tx as a parent into a peer's work set (ie orphans that may hav...
int EraseTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase an orphan by txid.
Definition: txorphanage.cpp:56
int64_t NodeId
Definition: nodeid.h:10
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
A TxId is the identifier of a transaction.
Definition: txid.h:14
bool operator()(const I &a, const I &b) const
Definition: txorphanage.h:79
CTransactionRef tx
Definition: txorphanage.h:64
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
Definition: txorphanage.cpp:18