5 #ifndef BITCOIN_TXORPHANAGE_H 6 #define BITCOIN_TXORPHANAGE_H 151 return a->first < b->first;
166 #endif // BITCOIN_TXORPHANAGE_H std::shared_ptr< const CTransaction > CTransactionRef
CTransactionRef GetTxToReconsider(NodeId peer)
Extract a transaction from a peer's work set Returns nullptr if there are no transactions to work on...
int EraseTx(const Wtxid &wtxid)
Erase an orphan by wtxid.
bool AddAnnouncer(const Wtxid &wtxid, NodeId peer)
Add an additional announcer to an orphan if it exists.
unsigned int TotalOrphanUsage() const
Get the total usage (weight) of all orphans.
unsigned int GetUsage() const
Get the weight of this transaction, an approximation of its memory usage.
static constexpr auto ORPHAN_TX_EXPIRE_TIME
Expiration time for orphan transactions.
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
std::vector< CTransactionRef > GetChildrenFromSamePeer(const CTransactionRef &parent, NodeId nodeid) const
Get all children that spend from this tx and were received from nodeid.
std::set< Wtxid > m_work_set
List of transactions that should be reconsidered: added to in AddChildrenToWorkSet, removed from one-by-one with each call to GetTxToReconsider.
std::set< NodeId > announcers
Peers added with AddTx or AddAnnouncer.
void AddChildrenToWorkSet(const CTransaction &tx, FastRandomContext &rng)
Add any orphans that list a particular tx as a parent into the from peer's work set.
static int32_t GetTransactionWeight(const CTransaction &tx)
std::map< Wtxid, OrphanTx > m_orphans
Map from wtxid to orphan transaction record.
unsigned int m_total_orphan_usage
Total usage (weight) of all entries in m_orphans.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
CTransactionRef GetTx(const Wtxid &wtxid) const
unsigned int UsageByPeer(NodeId peer) const
Total usage (weight) of orphans for which this peer is an announcer.
void SanityCheck() const
Check consistency between PeerOrphanInfo and m_orphans.
void LimitOrphans(unsigned int max_orphans, FastRandomContext &rng)
Limit the orphanage to the given maximum.
void EraseForPeer(NodeId peer)
Maybe erase all orphans announced by a peer (eg, after that peer disconnects).
bool HaveTxFromPeer(const Wtxid &wtxid, NodeId peer) const
Check if a {tx, peer} exists in the orphanage.
bool HaveTxToReconsider(NodeId peer)
Does this peer have any work to do?
bool AddTx(const CTransactionRef &tx, NodeId peer)
Add a new orphan transaction.
NodeSeconds m_next_sweep
Timestamp for the next scheduled sweep of expired orphans.
std::vector< OrphanTxBase > GetOrphanTransactions() const
decltype(m_orphans) OrphanMap
static constexpr auto ORPHAN_TX_EXPIRE_INTERVAL
Minimum time between orphan transactions expire time checks.
std::map< COutPoint, std::set< OrphanMap::iterator, IteratorComparator > > m_outpoint_to_orphan_it
Index from the parents' COutPoint into the m_orphans.
unsigned int m_total_usage
Total weight of orphans for which this peer is an announcer.
std::vector< OrphanMap::iterator > m_orphan_list
Orphan transactions in vector for quick random eviction.
size_t Size() const
Return how many entries exist in the orphange.
The basic transaction that is broadcasted on the network and contained in blocks. ...
bool operator()(const I &a, const I &b) const
std::map< NodeId, PeerOrphanInfo > m_peer_orphanage_info
Allows providing orphan information externally.
void EraseForBlock(const CBlock &block)
Erase all orphans included in or invalidated by a new block.
bool HaveTx(const Wtxid &wtxid) const
Check if we already have an orphan transaction (by wtxid only)
unsigned int m_total_announcements
Total number of <peer, tx> pairs.
transaction_identifier represents the two canonical transaction identifier types (txid, wtxid).