Bitcoin ABC  0.26.3
P2P Digital Currency
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
TxOrphanage Class Reference

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 we keep and the duration we keep them for. More...

#include <txorphanage.h>

Collaboration diagram for TxOrphanage:
[legend]

Classes

struct  IteratorComparator
 
struct  OrphanTx
 

Public Member Functions

bool AddTx (const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add a new orphan transaction. More...
 
bool HaveTx (const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Check if we already have an orphan transaction. More...
 
CTransactionRef GetTxToReconsider (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Extract a transaction from a peer's work set. More...
 
int EraseTx (const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase an orphan by txid. More...
 
void EraseForPeer (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase all orphans announced by a peer (eg, after that peer disconnects) More...
 
void EraseForBlock (const CBlock &block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase all orphans included in or invalidated by a new block. More...
 
unsigned int LimitOrphans (unsigned int max_orphans, FastRandomContext &rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Limit the orphanage to the given maximum. More...
 
void AddChildrenToWorkSet (const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add any orphans that list a particular tx as a parent into the from peer's work set. More...
 
bool HaveTxToReconsider (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Does this peer have any work to do? More...
 
std::vector< CTransactionRefGetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get all children that spend from this tx and were received from nodeid. More...
 
std::vector< std::pair< CTransactionRef, NodeId > > GetChildrenFromDifferentPeer (const CTransactionRef &parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get all children that spend from this tx but were not received from nodeid. More...
 
size_t Size () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Return how many entries exist in the orphange. More...
 

Protected Types

using OrphanMap = decltype(m_orphans)
 

Protected Member Functions

std::map< TxId, OrphanTx > m_orphans GUARDED_BY (m_mutex)
 Map from txid to orphan transaction record. More...
 
std::map< NodeId, std::set< TxId > > m_peer_work_set GUARDED_BY (m_mutex)
 Which peer provided the orphans that need to be reconsidered. More...
 
std::map< COutPoint, std::set< OrphanMap ::iterator, IteratorComparator > > m_outpoint_to_orphan_it GUARDED_BY (m_mutex)
 Index from the parents' COutPoint into the m_orphans. More...
 
std::vector< OrphanMap::iterator > m_orphan_list GUARDED_BY (m_mutex)
 Orphan transactions in vector for quick random eviction. More...
 
int EraseTxNoLock (const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
 Erase an orphan by txid. More...
 
NodeSeconds m_next_sweep GUARDED_BY (m_mutex)
 Timestamp for the next scheduled sweep of expired orphans. More...
 

Protected Attributes

Mutex m_mutex
 Guards orphan transactions. More...
 

Detailed Description

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 we keep and the duration we keep them for.

Definition at line 23 of file txorphanage.h.

Member Typedef Documentation

◆ OrphanMap

using TxOrphanage::OrphanMap = decltype(m_orphans)
protected

Definition at line 110 of file txorphanage.h.

Member Function Documentation

◆ AddChildrenToWorkSet()

void TxOrphanage::AddChildrenToWorkSet ( const CTransaction tx)

Add any orphans that list a particular tx as a parent into the from peer's work set.

Definition at line 161 of file txorphanage.cpp.

Here is the call graph for this function:

◆ AddTx()

bool TxOrphanage::AddTx ( const CTransactionRef tx,
NodeId  peer 
)

Add a new orphan transaction.

Definition at line 19 of file txorphanage.cpp.

Here is the call graph for this function:

◆ EraseForBlock()

void TxOrphanage::EraseForBlock ( const CBlock block)

Erase all orphans included in or invalidated by a new block.

Definition at line 218 of file txorphanage.cpp.

Here is the call graph for this function:

◆ EraseForPeer()

void TxOrphanage::EraseForPeer ( NodeId  peer)

Erase all orphans announced by a peer (eg, after that peer disconnects)

Definition at line 102 of file txorphanage.cpp.

Here is the call graph for this function:

◆ EraseTx()

int TxOrphanage::EraseTx ( const TxId txid)

Erase an orphan by txid.

Definition at line 57 of file txorphanage.cpp.

Here is the call graph for this function:

◆ EraseTxNoLock()

int TxOrphanage::EraseTxNoLock ( const TxId txid)
protected

Erase an orphan by txid.

Definition at line 62 of file txorphanage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChildrenFromDifferentPeer()

std::vector< std::pair< CTransactionRef, NodeId > > TxOrphanage::GetChildrenFromDifferentPeer ( const CTransactionRef parent,
NodeId  nodeid 
) const

Get all children that spend from this tx but were not received from nodeid.

Also return which peer provided each tx.

Definition at line 301 of file txorphanage.cpp.

◆ GetChildrenFromSamePeer()

std::vector< CTransactionRef > TxOrphanage::GetChildrenFromSamePeer ( const CTransactionRef parent,
NodeId  nodeid 
) const

Get all children that spend from this tx and were received from nodeid.

Sorted from most recent to least recent.

Definition at line 256 of file txorphanage.cpp.

◆ GetTxToReconsider()

CTransactionRef TxOrphanage::GetTxToReconsider ( NodeId  peer)

Extract a transaction from a peer's work set.

Returns nullptr if there are no transactions to work on. Otherwise returns the transaction reference, and removes it from the work set.

Definition at line 188 of file txorphanage.cpp.

Here is the call graph for this function:

◆ GUARDED_BY() [1/5]

std::map<TxId, OrphanTx> m_orphans TxOrphanage::GUARDED_BY ( m_mutex  )
protected

Map from txid to orphan transaction record.

Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS

◆ GUARDED_BY() [2/5]

std::map<NodeId, std::set<TxId> > m_peer_work_set TxOrphanage::GUARDED_BY ( m_mutex  )
protected

Which peer provided the orphans that need to be reconsidered.

◆ GUARDED_BY() [3/5]

std::map<COutPoint, std::set<OrphanMap ::iterator, IteratorComparator> > m_outpoint_to_orphan_it TxOrphanage::GUARDED_BY ( m_mutex  )
protected

Index from the parents' COutPoint into the m_orphans.

Used to remove orphan transactions from the m_orphans

◆ GUARDED_BY() [4/5]

std::vector<OrphanMap::iterator> m_orphan_list TxOrphanage::GUARDED_BY ( m_mutex  )
protected

Orphan transactions in vector for quick random eviction.

◆ GUARDED_BY() [5/5]

NodeSeconds m_next_sweep TxOrphanage::GUARDED_BY ( m_mutex  )
inlineprotected

Timestamp for the next scheduled sweep of expired orphans.

Definition at line 132 of file txorphanage.h.

◆ HaveTx()

bool TxOrphanage::HaveTx ( const TxId txid) const

Check if we already have an orphan transaction.

Definition at line 183 of file txorphanage.cpp.

◆ HaveTxToReconsider()

bool TxOrphanage::HaveTxToReconsider ( NodeId  peer)

Does this peer have any work to do?

Definition at line 207 of file txorphanage.cpp.

◆ LimitOrphans()

unsigned int TxOrphanage::LimitOrphans ( unsigned int  max_orphans,
FastRandomContext rng 
)

Limit the orphanage to the given maximum.

Definition at line 123 of file txorphanage.cpp.

Here is the call graph for this function:

◆ Size()

size_t TxOrphanage::Size ( )
inline

Return how many entries exist in the orphange.

Definition at line 85 of file txorphanage.h.

Member Data Documentation

◆ m_mutex

Mutex TxOrphanage::m_mutex
mutableprotected

Guards orphan transactions.

Definition at line 92 of file txorphanage.h.


The documentation for this class was generated from the following files: