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...
 
struct  PeerOrphanInfo
 

Public Member Functions

bool AddTx (const CTransactionRef &tx, NodeId peer)
 Add a new orphan transaction. More...
 
bool AddAnnouncer (const Wtxid &wtxid, NodeId peer)
 Add an additional announcer to an orphan if it exists. More...
 
CTransactionRef GetTx (const Wtxid &wtxid) const
 
bool HaveTx (const Wtxid &wtxid) const
 Check if we already have an orphan transaction (by wtxid only) More...
 
bool HaveTxFromPeer (const Wtxid &wtxid, NodeId peer) const
 Check if a {tx, peer} exists in the orphanage. 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)
 Maybe 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, FastRandomContext &rng)
 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...
 
size_t Size () const
 Return how many entries exist in the orphange. More...
 
std::vector< OrphanTxBaseGetOrphanTransactions () const
 
unsigned int TotalOrphanUsage () const
 Get the total usage (weight) of all orphans. More...
 
unsigned int UsageByPeer (NodeId peer) const
 Total usage (weight) of orphans for which this peer is an announcer. More...
 
void SanityCheck () const
 Check consistency between PeerOrphanInfo and m_orphans. More...
 

Protected Types

using OrphanMap = decltype(m_orphans)
 

Protected Attributes

unsigned int m_total_orphan_usage {0}
 Total usage (weight) of all entries in m_orphans. More...
 
unsigned int m_total_announcements {0}
 Total number of <peer, tx> pairs. More...
 
std::map< Wtxid, OrphanTxm_orphans
 Map from wtxid to orphan transaction record. More...
 
std::map< NodeId, PeerOrphanInfom_peer_orphanage_info
 
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 29 of file txorphanage.h.

Member Typedef Documentation

◆ OrphanMap

using TxOrphanage::OrphanMap = decltype(m_orphans)
protected

Definition at line 144 of file txorphanage.h.

Member Function Documentation

◆ AddAnnouncer()

bool TxOrphanage::AddAnnouncer ( const Wtxid wtxid,
NodeId  peer 
)

Add an additional announcer to an orphan if it exists.

Otherwise, do nothing.

Definition at line 55 of file txorphanage.cpp.

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

◆ AddChildrenToWorkSet()

void TxOrphanage::AddChildrenToWorkSet ( const CTransaction tx,
FastRandomContext rng 
)

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

Definition at line 175 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 247 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)

Maybe erase all orphans announced by a peer (eg, after that peer disconnects).

If an orphan has been announced by another peer, don't erase, just remove this peer from the list of announcers.

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

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

Here is the caller graph for this function:

◆ GetOrphanTransactions()

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

Definition at line 315 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ GetTx()

CTransactionRef TxOrphanage::GetTx ( const Wtxid wtxid) const

Definition at line 208 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 220 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 203 of file txorphanage.cpp.

Here is the caller graph for this function:

◆ HaveTxFromPeer()

bool TxOrphanage::HaveTxFromPeer ( const Wtxid wtxid,
NodeId  peer 
) const

Check if a {tx, peer} exists in the orphanage.

Definition at line 214 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 238 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 143 of file txorphanage.cpp.

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

◆ SanityCheck()

void TxOrphanage::SanityCheck ( ) const

Check consistency between PeerOrphanInfo and m_orphans.

Recalculate counters and ensure they match what is cached.

Definition at line 325 of file txorphanage.cpp.

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 76 of file txorphanage.h.

Here is the caller graph for this function:

◆ TotalOrphanUsage()

unsigned int TxOrphanage::TotalOrphanUsage ( ) const
inline

Get the total usage (weight) of all orphans.

If an orphan has multiple announcers, its usage is only counted once within this total.

Definition at line 98 of file txorphanage.h.

Here is the caller graph for this function:

◆ UsageByPeer()

unsigned int TxOrphanage::UsageByPeer ( NodeId  peer) const
inline

Total usage (weight) of orphans for which this peer is an announcer.

If an orphan has multiple announcers, its weight will be accounted for in each PeerOrphanInfo, so the total of all peers' UsageByPeer() may be larger than TotalOrphanBytes().

Definition at line 103 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 163 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 160 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 126 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 157 of file txorphanage.h.

◆ m_peer_orphanage_info

std::map<NodeId, PeerOrphanInfo> TxOrphanage::m_peer_orphanage_info
protected

Definition at line 142 of file txorphanage.h.

◆ m_total_announcements

unsigned int TxOrphanage::m_total_announcements {0}
protected

Total number of <peer, tx> pairs.

Can be larger than m_orphans.size() because multiple peers may have announced the same orphan.

Definition at line 122 of file txorphanage.h.

◆ m_total_orphan_usage

unsigned int TxOrphanage::m_total_orphan_usage {0}
protected

Total usage (weight) of all entries in m_orphans.

Definition at line 118 of file txorphanage.h.


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