![]() |
Bitcoin Core 28.99.0
P2P Digital Currency
|
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>
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< CTransactionRef > | GetChildrenFromSamePeer (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< OrphanTxBase > | GetOrphanTransactions () 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, OrphanTx > | m_orphans |
Map from wtxid to orphan transaction record. More... | |
std::map< NodeId, PeerOrphanInfo > | m_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... | |
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.
|
protected |
Definition at line 144 of file txorphanage.h.
Add an additional announcer to an orphan if it exists.
Otherwise, do nothing.
Definition at line 55 of file txorphanage.cpp.
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.
bool TxOrphanage::AddTx | ( | const CTransactionRef & | tx, |
NodeId | peer | ||
) |
Add a new orphan transaction.
Definition at line 15 of file txorphanage.cpp.
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.
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.
int TxOrphanage::EraseTx | ( | const Wtxid & | wtxid | ) |
Erase an orphan by wtxid.
Definition at line 72 of file txorphanage.cpp.
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.
std::vector< TxOrphanage::OrphanTxBase > TxOrphanage::GetOrphanTransactions | ( | ) | const |
CTransactionRef TxOrphanage::GetTx | ( | const Wtxid & | wtxid | ) | const |
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.
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.
Check if a {tx, peer} exists in the orphanage.
Definition at line 214 of file txorphanage.cpp.
bool TxOrphanage::HaveTxToReconsider | ( | NodeId | peer | ) |
Does this peer have any work to do?
Definition at line 238 of file txorphanage.cpp.
void TxOrphanage::LimitOrphans | ( | unsigned int | max_orphans, |
FastRandomContext & | rng | ||
) |
Limit the orphanage to the given maximum.
Definition at line 143 of file txorphanage.cpp.
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.
|
inline |
Return how many entries exist in the orphange.
Definition at line 76 of file txorphanage.h.
|
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.
|
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.
|
protected |
Timestamp for the next scheduled sweep of expired orphans.
Definition at line 163 of file txorphanage.h.
|
protected |
Orphan transactions in vector for quick random eviction.
Definition at line 160 of file txorphanage.h.
Map from wtxid to orphan transaction record.
Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS
Definition at line 126 of file txorphanage.h.
|
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.
|
protected |
Definition at line 142 of file txorphanage.h.
|
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.
|
protected |
Total usage (weight) of all entries in m_orphans.
Definition at line 118 of file txorphanage.h.