Bitcoin Core 29.99.0
P2P Digital Currency
Classes | Public Types | Public Member Functions | List of all members
node::TxOrphanage Class Referenceabstract

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 amount of announcements (unique (NodeId, wtxid) pairs), the number of inputs, and size of the orphans stored (both individual and summed). More...

#include <txorphanage.h>

Inheritance diagram for node::TxOrphanage:
[legend]

Classes

struct  OrphanInfo
 Allows providing orphan information externally. More...
 

Public Types

using Usage = int64_t
 
using Count = unsigned int
 

Public Member Functions

virtual ~TxOrphanage ()=default
 
virtual bool AddTx (const CTransactionRef &tx, NodeId peer)=0
 Add a new orphan transaction. More...
 
virtual bool AddAnnouncer (const Wtxid &wtxid, NodeId peer)=0
 Add an additional announcer to an orphan if it exists. More...
 
virtual CTransactionRef GetTx (const Wtxid &wtxid) const =0
 Get a transaction by its witness txid. More...
 
virtual bool HaveTx (const Wtxid &wtxid) const =0
 Check if we already have an orphan transaction (by wtxid only) More...
 
virtual bool HaveTxFromPeer (const Wtxid &wtxid, NodeId peer) const =0
 Check if a {tx, peer} exists in the orphanage. More...
 
virtual CTransactionRef GetTxToReconsider (NodeId peer)=0
 Extract a transaction from a peer's work set, and flip it back to non-reconsiderable. More...
 
virtual bool EraseTx (const Wtxid &wtxid)=0
 Erase an orphan by wtxid, including all announcements if there are multiple. More...
 
virtual void EraseForPeer (NodeId peer)=0
 Maybe erase all orphans announced by a peer (eg, after that peer disconnects). More...
 
virtual void EraseForBlock (const CBlock &block)=0
 Erase all orphans included in or invalidated by a new block. More...
 
virtual std::vector< std::pair< Wtxid, NodeId > > AddChildrenToWorkSet (const CTransaction &tx, FastRandomContext &rng)=0
 Add any orphans that list a particular tx as a parent into the from peer's work set. More...
 
virtual bool HaveTxToReconsider (NodeId peer)=0
 Does this peer have any work to do? More...
 
virtual std::vector< CTransactionRefGetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const =0
 Get all children that spend from this tx and were received from nodeid. More...
 
virtual std::vector< OrphanInfoGetOrphanTransactions () const =0
 Get all orphan transactions. More...
 
virtual Usage TotalOrphanUsage () const =0
 Get the total usage (weight) of all orphans. More...
 
virtual Usage UsageByPeer (NodeId peer) const =0
 Total usage (weight) of orphans for which this peer is an announcer. More...
 
virtual void SanityCheck () const =0
 Check consistency between PeerOrphanInfo and m_orphans. More...
 
virtual Count CountAnnouncements () const =0
 Number of announcements, i.e. More...
 
virtual Count CountUniqueOrphans () const =0
 Number of unique orphans (by wtxid). More...
 
virtual Count AnnouncementsFromPeer (NodeId peer) const =0
 Number of orphans stored from this peer. More...
 
virtual Count LatencyScoreFromPeer (NodeId peer) const =0
 Latency score of transactions announced by this peer. More...
 
virtual Count MaxGlobalLatencyScore () const =0
 Get the maximum global latency score allowed. More...
 
virtual Count TotalLatencyScore () const =0
 Get the total latency score of all orphans. More...
 
virtual Usage ReservedPeerUsage () const =0
 Get the reserved usage per peer. More...
 
virtual Count MaxPeerLatencyScore () const =0
 Get the maximum latency score allowed per peer. More...
 
virtual Usage MaxGlobalUsage () const =0
 Get the maximum global usage allowed. 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 amount of announcements (unique (NodeId, wtxid) pairs), the number of inputs, and size of the orphans stored (both individual and summed).

We also try to prevent adversaries from churning this data structure: once global limits are reached, we continuously evict the oldest announcement (sorting non-reconsiderable orphans before reconsiderable ones) from the most resource-intensive peer until we are back within limits.

Definition at line 38 of file txorphanage.h.

Member Typedef Documentation

◆ Count

using node::TxOrphanage::Count = unsigned int

Definition at line 41 of file txorphanage.h.

◆ Usage

using node::TxOrphanage::Usage = int64_t

Definition at line 40 of file txorphanage.h.

Constructor & Destructor Documentation

◆ ~TxOrphanage()

virtual node::TxOrphanage::~TxOrphanage ( )
virtualdefault

Member Function Documentation

◆ AddAnnouncer()

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

Add an additional announcer to an orphan if it exists.

Otherwise, do nothing.

Implemented in node::TxOrphanageImpl.

◆ AddChildrenToWorkSet()

virtual std::vector< std::pair< Wtxid, NodeId > > node::TxOrphanage::AddChildrenToWorkSet ( const CTransaction tx,
FastRandomContext rng 
)
pure virtual

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

Implemented in node::TxOrphanageImpl.

◆ AddTx()

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

Add a new orphan transaction.

Implemented in node::TxOrphanageImpl.

◆ AnnouncementsFromPeer()

virtual Count node::TxOrphanage::AnnouncementsFromPeer ( NodeId  peer) const
pure virtual

Number of orphans stored from this peer.

Implemented in node::TxOrphanageImpl.

◆ CountAnnouncements()

virtual Count node::TxOrphanage::CountAnnouncements ( ) const
pure virtual

Number of announcements, i.e.

total size of m_orphans. Ones for the same wtxid are not de-duplicated. Not the same as TotalLatencyScore().

Implemented in node::TxOrphanageImpl.

◆ CountUniqueOrphans()

virtual Count node::TxOrphanage::CountUniqueOrphans ( ) const
pure virtual

Number of unique orphans (by wtxid).

Implemented in node::TxOrphanageImpl.

◆ EraseForBlock()

virtual void node::TxOrphanage::EraseForBlock ( const CBlock block)
pure virtual

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

Implemented in node::TxOrphanageImpl.

◆ EraseForPeer()

virtual void node::TxOrphanage::EraseForPeer ( NodeId  peer)
pure virtual

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.

Implemented in node::TxOrphanageImpl.

◆ EraseTx()

virtual bool node::TxOrphanage::EraseTx ( const Wtxid wtxid)
pure virtual

Erase an orphan by wtxid, including all announcements if there are multiple.

Returns true if an orphan was erased, false if no tx with this wtxid exists.

Implemented in node::TxOrphanageImpl.

◆ GetChildrenFromSamePeer()

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

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

Sorted reconsiderable before non-reconsiderable, then from most recent to least recent.

Implemented in node::TxOrphanageImpl.

◆ GetOrphanTransactions()

virtual std::vector< OrphanInfo > node::TxOrphanage::GetOrphanTransactions ( ) const
pure virtual

Get all orphan transactions.

Implemented in node::TxOrphanageImpl.

◆ GetTx()

virtual CTransactionRef node::TxOrphanage::GetTx ( const Wtxid wtxid) const
pure virtual

Get a transaction by its witness txid.

Implemented in node::TxOrphanageImpl.

◆ GetTxToReconsider()

virtual CTransactionRef node::TxOrphanage::GetTxToReconsider ( NodeId  peer)
pure virtual

Extract a transaction from a peer's work set, and flip it back to non-reconsiderable.

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

Implemented in node::TxOrphanageImpl.

◆ HaveTx()

virtual bool node::TxOrphanage::HaveTx ( const Wtxid wtxid) const
pure virtual

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

Implemented in node::TxOrphanageImpl.

◆ HaveTxFromPeer()

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

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

Implemented in node::TxOrphanageImpl.

◆ HaveTxToReconsider()

virtual bool node::TxOrphanage::HaveTxToReconsider ( NodeId  peer)
pure virtual

Does this peer have any work to do?

Implemented in node::TxOrphanageImpl.

◆ LatencyScoreFromPeer()

virtual Count node::TxOrphanage::LatencyScoreFromPeer ( NodeId  peer) const
pure virtual

Latency score of transactions announced by this peer.

Implemented in node::TxOrphanageImpl.

◆ MaxGlobalLatencyScore()

virtual Count node::TxOrphanage::MaxGlobalLatencyScore ( ) const
pure virtual

Get the maximum global latency score allowed.

Implemented in node::TxOrphanageImpl.

◆ MaxGlobalUsage()

virtual Usage node::TxOrphanage::MaxGlobalUsage ( ) const
pure virtual

Get the maximum global usage allowed.

Implemented in node::TxOrphanageImpl.

◆ MaxPeerLatencyScore()

virtual Count node::TxOrphanage::MaxPeerLatencyScore ( ) const
pure virtual

Get the maximum latency score allowed per peer.

Implemented in node::TxOrphanageImpl.

◆ ReservedPeerUsage()

virtual Usage node::TxOrphanage::ReservedPeerUsage ( ) const
pure virtual

Get the reserved usage per peer.

Implemented in node::TxOrphanageImpl.

◆ SanityCheck()

virtual void node::TxOrphanage::SanityCheck ( ) const
pure virtual

Check consistency between PeerOrphanInfo and m_orphans.

Recalculate counters and ensure they match what is cached.

Implemented in node::TxOrphanageImpl.

◆ TotalLatencyScore()

virtual Count node::TxOrphanage::TotalLatencyScore ( ) const
pure virtual

Get the total latency score of all orphans.

Implemented in node::TxOrphanageImpl.

◆ TotalOrphanUsage()

virtual Usage node::TxOrphanage::TotalOrphanUsage ( ) const
pure virtual

Get the total usage (weight) of all orphans.

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

Implemented in node::TxOrphanageImpl.

◆ UsageByPeer()

virtual Usage node::TxOrphanage::UsageByPeer ( NodeId  peer) const
pure virtual

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 TotalOrphanUsage(). Similarly, UsageByPeer() may be far higher than ReservedPeerUsage(), particularly if many peers have provided the same orphans.

Implemented in node::TxOrphanageImpl.


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