Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Member Functions | Protected Types | 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>

Inheritance diagram for TxOrphanage:
[legend]

Classes

struct  IteratorComparator
 
struct  OrphanTx
 
struct  OrphanTxBase
 Allows providing orphan information externally. More...
 

Public Member Functions

bool AddTx (const CTransactionRef &tx, NodeId peer)
 Add a new orphan transaction. More...
 
bool HaveTx (const Wtxid &wtxid) const
 Check if we already have an orphan transaction (by wtxid only) More...
 
CTransactionRef GetTxToReconsider (NodeId peer)
 Extract a transaction from a peer's work set Returns nullptr if there are no transactions to work on. More...
 
int EraseTx (const Wtxid &wtxid)
 Erase an orphan by wtxid. More...
 
void EraseForPeer (NodeId peer)
 Erase all orphans announced by a peer (eg, after that peer disconnects) More...
 
void EraseForBlock (const CBlock &block)
 Erase all orphans included in or invalidated by a new block. More...
 
void LimitOrphans (unsigned int max_orphans, FastRandomContext &rng)
 Limit the orphanage to the given maximum. More...
 
void AddChildrenToWorkSet (const CTransaction &tx)
 Add any orphans that list a particular tx as a parent into the from peer's work set. More...
 
bool HaveTxToReconsider (NodeId peer)
 Does this peer have any work to do? More...
 
std::vector< CTransactionRefGetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const
 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
 Get all children that spend from this tx but were not received from nodeid. More...
 
size_t Size () const
 Return how many entries exist in the orphange. More...
 
std::vector< OrphanTxBaseGetOrphanTransactions () const
 

Protected Types

using OrphanMap = decltype(m_orphans)
 

Protected Attributes

std::map< Wtxid, OrphanTxm_orphans
 Map from wtxid to orphan transaction record. More...
 
std::map< NodeId, std::set< Wtxid > > m_peer_work_set
 Which peer provided the orphans that need to be reconsidered. More...
 
std::map< COutPoint, std::set< OrphanMap::iterator, IteratorComparator > > m_outpoint_to_orphan_it
 Index from the parents' COutPoint into the m_orphans. More...
 
std::vector< OrphanMap::iterator > m_orphan_list
 Orphan transactions in vector for quick random eviction. More...
 
NodeSeconds m_next_sweep {0s}
 Timestamp for the next scheduled sweep of expired orphans. 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.

Not thread-safe. Requires external synchronization.

Definition at line 28 of file txorphanage.h.

Member Typedef Documentation

◆ OrphanMap

using TxOrphanage::OrphanMap = decltype(m_orphans)
protected

Definition at line 96 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 132 of file txorphanage.cpp.

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

◆ AddTx()

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

Add a new orphan transaction.

Definition at line 15 of file txorphanage.cpp.

Here is the call graph for this function:
Here is the caller 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 183 of file txorphanage.cpp.

Here is the call graph for this function:
Here is the caller 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 83 of file txorphanage.cpp.

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

◆ EraseTx()

int TxOrphanage::EraseTx ( const Wtxid wtxid)

Erase an orphan by wtxid.

Definition at line 48 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 251 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ 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 211 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ GetOrphanTransactions()

std::vector< TxOrphanage::OrphanTxBase > TxOrphanage::GetOrphanTransactions ( ) const

Definition at line 281 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ 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 155 of file txorphanage.cpp.

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

◆ HaveTx()

bool TxOrphanage::HaveTx ( const Wtxid wtxid) const

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

Definition at line 150 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ HaveTxToReconsider()

bool TxOrphanage::HaveTxToReconsider ( NodeId  peer)

Does this peer have any work to do?

Definition at line 173 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ LimitOrphans()

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

Limit the orphanage to the given maximum.

Definition at line 100 of file txorphanage.cpp.

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

◆ Size()

size_t TxOrphanage::Size ( ) const
inline

Return how many entries exist in the orphange.

Definition at line 70 of file txorphanage.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_next_sweep

NodeSeconds TxOrphanage::m_next_sweep {0s}
protected

Timestamp for the next scheduled sweep of expired orphans.

Definition at line 115 of file txorphanage.h.

◆ m_orphan_list

std::vector<OrphanMap::iterator> TxOrphanage::m_orphan_list
protected

Orphan transactions in vector for quick random eviction.

Definition at line 112 of file txorphanage.h.

◆ m_orphans

std::map<Wtxid, OrphanTx> TxOrphanage::m_orphans
protected

Map from wtxid to orphan transaction record.

Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS

Definition at line 91 of file txorphanage.h.

◆ m_outpoint_to_orphan_it

std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator> > TxOrphanage::m_outpoint_to_orphan_it
protected

Index from the parents' COutPoint into the m_orphans.

Used to remove orphan transactions from the m_orphans

Definition at line 109 of file txorphanage.h.

◆ m_peer_work_set

std::map<NodeId, std::set<Wtxid> > TxOrphanage::m_peer_work_set
protected

Which peer provided the orphans that need to be reconsidered.

Definition at line 94 of file txorphanage.h.


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