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... | |
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< CTransactionRef > | GetChildrenFromSamePeer (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< OrphanTxBase > | GetOrphanTransactions () const |
Protected Types | |
using | OrphanMap = decltype(m_orphans) |
Protected Attributes | |
std::map< Wtxid, OrphanTx > | m_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... | |
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.
|
protected |
Definition at line 96 of file txorphanage.h.
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.
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 183 of file txorphanage.cpp.
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.
int TxOrphanage::EraseTx | ( | const Wtxid & | wtxid | ) |
Erase an orphan by wtxid.
Definition at line 48 of file txorphanage.cpp.
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.
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.
std::vector< TxOrphanage::OrphanTxBase > TxOrphanage::GetOrphanTransactions | ( | ) | 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 155 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 150 of file txorphanage.cpp.
bool TxOrphanage::HaveTxToReconsider | ( | NodeId | peer | ) |
Does this peer have any work to do?
Definition at line 173 of file txorphanage.cpp.
void TxOrphanage::LimitOrphans | ( | unsigned int | max_orphans, |
FastRandomContext & | rng | ||
) |
Limit the orphanage to the given maximum.
Definition at line 100 of file txorphanage.cpp.
|
inline |
Return how many entries exist in the orphange.
Definition at line 70 of file txorphanage.h.
|
protected |
Timestamp for the next scheduled sweep of expired orphans.
Definition at line 115 of file txorphanage.h.
|
protected |
Orphan transactions in vector for quick random eviction.
Definition at line 112 of file txorphanage.h.
Map from wtxid to orphan transaction record.
Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS
Definition at line 91 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 109 of file txorphanage.h.
Which peer provided the orphans that need to be reconsidered.
Definition at line 94 of file txorphanage.h.