![]() |
Bitcoin Core 29.99.0
P2P Digital Currency
|
Classes | |
struct | Announcement |
One orphan announcement. More... | |
struct | ByPeer |
struct | ByPeerViewExtractor |
struct | ByWtxid |
struct | OrphanIndices |
struct | PeerDoSInfo |
struct | WtxidExtractor |
Public Member Functions | |
TxOrphanageImpl ()=default | |
TxOrphanageImpl (Count max_global_latency_score, Usage reserved_peer_usage) | |
~TxOrphanageImpl () noexcept override=default | |
TxOrphanage::Count | CountAnnouncements () const override |
Number of announcements, i.e. More... | |
TxOrphanage::Count | CountUniqueOrphans () const override |
Number of unique orphans (by wtxid). More... | |
TxOrphanage::Count | AnnouncementsFromPeer (NodeId peer) const override |
Number of orphans stored from this peer. More... | |
TxOrphanage::Count | LatencyScoreFromPeer (NodeId peer) const override |
Latency score of transactions announced by this peer. More... | |
TxOrphanage::Usage | UsageByPeer (NodeId peer) const override |
Total usage (weight) of orphans for which this peer is an announcer. More... | |
TxOrphanage::Count | MaxGlobalLatencyScore () const override |
Get the maximum global latency score allowed. More... | |
TxOrphanage::Count | TotalLatencyScore () const override |
Get the total latency score of all orphans. More... | |
TxOrphanage::Usage | ReservedPeerUsage () const override |
Get the reserved usage per peer. More... | |
TxOrphanage::Count | MaxPeerLatencyScore () const override |
Maximum allowed (deduplicated) latency score for all transactions (see Announcement::GetLatencyScore()). More... | |
TxOrphanage::Usage | MaxGlobalUsage () const override |
Maximum allowed (deduplicated) memory usage for all transactions (see Announcement::GetMemUsage()). More... | |
bool | AddTx (const CTransactionRef &tx, NodeId peer) override |
Add a new orphan transaction. More... | |
bool | AddAnnouncer (const Wtxid &wtxid, NodeId peer) override |
Add an additional announcer to an orphan if it exists. More... | |
CTransactionRef | GetTx (const Wtxid &wtxid) const override |
Get a transaction by its witness txid. More... | |
bool | HaveTx (const Wtxid &wtxid) const override |
Check if we already have an orphan transaction (by wtxid only) More... | |
bool | HaveTxFromPeer (const Wtxid &wtxid, NodeId peer) const override |
Check if a {tx, peer} exists in the orphanage. More... | |
CTransactionRef | GetTxToReconsider (NodeId peer) override |
If there is a tx that can be reconsidered, return it and set it back to non-reconsiderable. More... | |
bool | EraseTx (const Wtxid &wtxid) override |
Erase an orphan by wtxid, including all announcements if there are multiple. More... | |
void | EraseForPeer (NodeId peer) override |
Erase all entries by this peer. More... | |
void | EraseForBlock (const CBlock &block) override |
Erase all orphans included in or invalidated by a new block. More... | |
std::vector< std::pair< Wtxid, NodeId > > | AddChildrenToWorkSet (const CTransaction &tx, FastRandomContext &rng) override |
Add any orphans that list a particular tx as a parent into the from peer's work set. More... | |
bool | HaveTxToReconsider (NodeId peer) override |
Return whether there is a tx that can be reconsidered. More... | |
std::vector< CTransactionRef > | GetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const override |
Get all children that spend from this tx and were received from nodeid. More... | |
std::vector< OrphanInfo > | GetOrphanTransactions () const override |
Get all orphan transactions. More... | |
TxOrphanage::Usage | TotalOrphanUsage () const override |
Get the total usage (weight) of all orphans. More... | |
void | SanityCheck () const override |
Check consistency between PeerOrphanInfo and m_orphans. More... | |
![]() | |
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< CTransactionRef > | GetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const =0 |
Get all children that spend from this tx and were received from nodeid. More... | |
virtual std::vector< OrphanInfo > | GetOrphanTransactions () 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... | |
Private Types | |
using | SequenceNumber = uint64_t |
using | ByWtxidView = std::tuple< Wtxid, NodeId > |
using | ByPeerView = std::tuple< NodeId, bool, SequenceNumber > |
using | AnnouncementMap = boost::multi_index::multi_index_container< Announcement, OrphanIndices > |
template<typename Tag > | |
using | Iter = typename AnnouncementMap::index< Tag >::type::iterator |
Private Member Functions | |
template<typename Tag > | |
void | Erase (Iter< Tag > it) |
Erase from m_orphans and update m_peer_orphanage_info. More... | |
bool | EraseTxInternal (const Wtxid &wtxid) |
Erase by wtxid. More... | |
bool | IsUnique (Iter< ByWtxid > it) const |
Check if there is exactly one announcement with the same wtxid as it. More... | |
bool | NeedsTrim () const |
Check if the orphanage needs trimming. More... | |
void | LimitOrphans () |
Limit the orphanage to MaxGlobalLatencyScore and MaxGlobalUsage. More... | |
Private Attributes | |
SequenceNumber | m_current_sequence {0} |
Global sequence number, increment each time an announcement is added. More... | |
AnnouncementMap | m_orphans |
const TxOrphanage::Count | m_max_global_latency_score {DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE} |
const TxOrphanage::Usage | m_reserved_usage_per_peer {DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER} |
TxOrphanage::Count | m_unique_orphans {0} |
Number of unique orphans by wtxid. More... | |
TxOrphanage::Usage | m_unique_orphan_usage {0} |
Memory used by orphans (see Announcement::GetMemUsage()), deduplicated by wtxid. More... | |
TxOrphanage::Count | m_unique_rounded_input_scores {0} |
The sum of each unique transaction's latency scores including the inputs only (see Announcement::GetLatencyScore but subtract 1 for the announcements themselves). More... | |
std::unordered_map< COutPoint, std::set< Wtxid >, SaltedOutpointHasher > | m_outpoint_to_orphan_wtxids |
Index from the parents' outputs to wtxids that exist in m_orphans. More... | |
std::set< Wtxid > | m_reconsiderable_wtxids |
Set of Wtxids for which (exactly) one announcement with m_reconsider=true exists. More... | |
std::unordered_map< NodeId, PeerDoSInfo > | m_peer_orphanage_info |
Store per-peer statistics. More... | |
Additional Inherited Members | |
![]() | |
using | Usage = int64_t |
using | Count = unsigned int |
Definition at line 29 of file txorphanage.cpp.
|
private |
Definition at line 99 of file txorphanage.cpp.
|
private |
Definition at line 85 of file txorphanage.cpp.
|
private |
Definition at line 73 of file txorphanage.cpp.
|
private |
Definition at line 101 of file txorphanage.cpp.
|
private |
Definition at line 31 of file txorphanage.cpp.
|
default |
|
inline |
Definition at line 192 of file txorphanage.cpp.
|
overridedefaultnoexcept |
Add an additional announcer to an orphan if it exists.
Otherwise, do nothing.
Implements node::TxOrphanage.
Definition at line 354 of file txorphanage.cpp.
|
overridevirtual |
Add any orphans that list a particular tx as a parent into the from peer's work set.
Implements node::TxOrphanage.
Definition at line 527 of file txorphanage.cpp.
|
overridevirtual |
Add a new orphan transaction.
Implements node::TxOrphanage.
Definition at line 306 of file txorphanage.cpp.
|
overridevirtual |
Number of orphans stored from this peer.
Implements node::TxOrphanage.
Definition at line 296 of file txorphanage.cpp.
|
overridevirtual |
Number of announcements, i.e.
total size of m_orphans. Ones for the same wtxid are not de-duplicated. Not the same as TotalLatencyScore().
Implements node::TxOrphanage.
Definition at line 290 of file txorphanage.cpp.
|
overridevirtual |
Number of unique orphans (by wtxid).
Implements node::TxOrphanage.
Definition at line 294 of file txorphanage.cpp.
|
private |
Erase from m_orphans and update m_peer_orphanage_info.
Definition at line 238 of file txorphanage.cpp.
|
overridevirtual |
Erase all orphans included in or invalidated by a new block.
Implements node::TxOrphanage.
Definition at line 610 of file txorphanage.cpp.
|
overridevirtual |
Erase all entries by this peer.
Implements node::TxOrphanage.
Definition at line 416 of file txorphanage.cpp.
|
overridevirtual |
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.
Implements node::TxOrphanage.
Definition at line 405 of file txorphanage.cpp.
|
private |
Erase by wtxid.
Definition at line 385 of file txorphanage.cpp.
|
overridevirtual |
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.
Implements node::TxOrphanage.
Definition at line 645 of file txorphanage.cpp.
|
overridevirtual |
Get all orphan transactions.
Implements node::TxOrphanage.
Definition at line 672 of file txorphanage.cpp.
|
overridevirtual |
Get a transaction by its witness txid.
Implements node::TxOrphanage.
Definition at line 573 of file txorphanage.cpp.
|
overridevirtual |
If there is a tx that can be reconsidered, return it and set it back to non-reconsiderable.
Otherwise, return a nullptr.
Implements node::TxOrphanage.
Definition at line 587 of file txorphanage.cpp.
|
overridevirtual |
Check if we already have an orphan transaction (by wtxid only)
Implements node::TxOrphanage.
Definition at line 567 of file txorphanage.cpp.
|
overridevirtual |
Check if a {tx, peer} exists in the orphanage.
Implements node::TxOrphanage.
Definition at line 580 of file txorphanage.cpp.
|
overridevirtual |
Return whether there is a tx that can be reconsidered.
Implements node::TxOrphanage.
Definition at line 604 of file txorphanage.cpp.
Check if there is exactly one announcement with the same wtxid as it.
Definition at line 274 of file txorphanage.cpp.
|
overridevirtual |
Latency score of transactions announced by this peer.
Implements node::TxOrphanage.
Definition at line 301 of file txorphanage.cpp.
|
private |
Limit the orphanage to MaxGlobalLatencyScore and MaxGlobalUsage.
If the data structure needs trimming, evicts announcements by selecting the DoSiest peer and evicting its oldest announcement (sorting non-reconsiderable orphans first, to give reconsiderable orphans a greater chance of being processed).
Does nothing if no global limits are exceeded. This eviction strategy effectively "reserves" an amount of announcements and space for each peer. The reserved amount is protected from eviction even if there are peers spamming the orphanage.
Definition at line 442 of file txorphanage.cpp.
|
overridevirtual |
Get the maximum global latency score allowed.
Implements node::TxOrphanage.
Definition at line 765 of file txorphanage.cpp.
|
overridevirtual |
Maximum allowed (deduplicated) memory usage for all transactions (see Announcement::GetMemUsage()).
Dynamic based on number of peers. More peers means more allowed memory usage. The number of peers times ReservedPeerUsage() adds up to MaxGlobalUsage(). As long as every peer's m_total_usage / ReservedPeerUsage() < 1, MaxGlobalUsage() is not exceeded.
Implements node::TxOrphanage.
Definition at line 769 of file txorphanage.cpp.
|
overridevirtual |
Maximum allowed (deduplicated) latency score for all transactions (see Announcement::GetLatencyScore()).
Dynamic based on number of peers. Each peer has an equal amount, but the global maximum latency score stays constant. The number of peers times MaxPeerLatencyScore() (rounded) adds up to MaxGlobalLatencyScore(). As long as every peer's m_total_latency_score / MaxPeerLatencyScore() < 1, MaxGlobalLatencyScore() is not exceeded.
Implements node::TxOrphanage.
Definition at line 768 of file txorphanage.cpp.
|
private |
Check if the orphanage needs trimming.
Definition at line 771 of file txorphanage.cpp.
|
overridevirtual |
Get the reserved usage per peer.
Implements node::TxOrphanage.
Definition at line 767 of file txorphanage.cpp.
|
overridevirtual |
Check consistency between PeerOrphanInfo and m_orphans.
Recalculate counters and ensure they match what is cached.
Implements node::TxOrphanage.
Definition at line 695 of file txorphanage.cpp.
|
overridevirtual |
Get the total latency score of all orphans.
Implements node::TxOrphanage.
Definition at line 766 of file txorphanage.cpp.
|
overridevirtual |
Get the total usage (weight) of all orphans.
If an orphan has multiple announcers, its usage is only counted once within this total.
Implements node::TxOrphanage.
Definition at line 292 of file txorphanage.cpp.
|
overridevirtual |
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.
Implements node::TxOrphanage.
Definition at line 284 of file txorphanage.cpp.
|
private |
Global sequence number, increment each time an announcement is added.
Definition at line 33 of file txorphanage.cpp.
|
private |
Definition at line 104 of file txorphanage.cpp.
|
private |
Definition at line 102 of file txorphanage.cpp.
|
private |
Index from the parents' outputs to wtxids that exist in m_orphans.
Used to find children of a transaction that can be reconsidered and to remove entries that conflict with a block.
Definition at line 120 of file txorphanage.cpp.
|
private |
Store per-peer statistics.
Used to determine each peer's DoS score. The size of this map is used to determine the number of peers and thus global {latency score, memory} limits.
Definition at line 172 of file txorphanage.cpp.
|
private |
Set of Wtxids for which (exactly) one announcement with m_reconsider=true exists.
Definition at line 123 of file txorphanage.cpp.
|
private |
Definition at line 105 of file txorphanage.cpp.
|
private |
Memory used by orphans (see Announcement::GetMemUsage()), deduplicated by wtxid.
Definition at line 111 of file txorphanage.cpp.
|
private |
Number of unique orphans by wtxid.
Less than or equal to the number of entries in m_orphans.
Definition at line 108 of file txorphanage.cpp.
|
private |
The sum of each unique transaction's latency scores including the inputs only (see Announcement::GetLatencyScore but subtract 1 for the announcements themselves).
The total orphanage's latency score is given by this value + the number of entries in m_orphans.
Definition at line 116 of file txorphanage.cpp.