Bitcoin Core  21.99.0
P2P Digital Currency
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | 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(g_cs_orphans)
 Add a new orphan transaction. More...
 
int EraseTx (const uint256 &txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
 Erase an orphan by txid. More...
 
void EraseForPeer (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
 Erase all orphans announced by a peer (eg, after that peer disconnects) More...
 
void AddChildrenToWorkSet (const CTransaction &tx, std::set< uint256 > &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 have found their final missing parent, and so should be reconsidered for the mempool) More...
 

Public Attributes

bool HaveTx(const GenTxid &gtxid) const LOCKS_EXCLUDED(std::pair< CTransactionRef, NodeIdGetTx (const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
 Check if we already have an orphan transaction (by txid or wtxid) More...
 
void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(unsigned int LimitOrphans (unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
 Erase all orphans included in or invalidated by a new block. More...
 

Protected Types

using OrphanMap = decltype(m_orphans)
 

Protected Member Functions

std::map< uint256, OrphanTx > m_orphans GUARDED_BY (g_cs_orphans)
 Map from txid to orphan transaction record. More...
 
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. More...
 
std::vector< OrphanMap::iterator > m_orphan_list GUARDED_BY (g_cs_orphans)
 Orphan transactions in vector for quick random eviction. More...
 
std::map< uint256, OrphanMap::iterator > m_wtxid_to_orphan_it GUARDED_BY (g_cs_orphans)
 Index from wtxid into the m_orphans to lookup orphan transactions using their witness ids. 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 21 of file txorphanage.h.

Member Typedef Documentation

◆ OrphanMap

using TxOrphanage::OrphanMap = decltype(m_orphans)
protected

Definition at line 62 of file txorphanage.h.

Member Function Documentation

◆ AddChildrenToWorkSet()

void TxOrphanage::AddChildrenToWorkSet ( const CTransaction tx,
std::set< uint256 > &  orphan_work_set 
) const

Add any orphans that list a particular tx as a parent into a peer's work set (ie orphans that may have found their final missing parent, and so should be reconsidered for the mempool)

Definition at line 141 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 20 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 88 of file txorphanage.cpp.

Here is the call graph for this function:

◆ EraseTx()

int TxOrphanage::EraseTx ( const uint256 txid)

Erase an orphan by txid.

Definition at line 56 of file txorphanage.cpp.

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

◆ GUARDED_BY() [1/4]

std::map<uint256, OrphanTx> m_orphans TxOrphanage::GUARDED_BY ( g_cs_orphans  )
protected

Map from txid to orphan transaction record.

Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS

◆ GUARDED_BY() [2/4]

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

Index from the parents' COutPoint into the m_orphans.

Used to remove orphan transactions from the m_orphans

◆ GUARDED_BY() [3/4]

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

Orphan transactions in vector for quick random eviction.

◆ GUARDED_BY() [4/4]

std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it TxOrphanage::GUARDED_BY ( g_cs_orphans  )
protected

Index from wtxid into the m_orphans to lookup orphan transactions using their witness ids.

Member Data Documentation

◆ GetTx

std::pair< CTransactionRef, NodeId > TxOrphanage::GetTx

Check if we already have an orphan transaction (by txid or wtxid)

Get an orphan transaction and its originating peer (Transaction ref will be nullptr if not found)

Definition at line 32 of file txorphanage.h.

◆ LimitOrphans

unsigned int TxOrphanage::LimitOrphans

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

Limit the orphanage to the given maximum

Definition at line 44 of file txorphanage.h.


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