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 | 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) |
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 |
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 102 of file txorphanage.h.
Add an additional announcer to an orphan if it exists.
Otherwise, do nothing.
Definition at line 51 of file txorphanage.cpp.
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 155 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 222 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 100 of file txorphanage.cpp.
int TxOrphanage::EraseTx | ( | const Wtxid & | wtxid | ) |
Erase an orphan by wtxid.
Definition at line 65 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 250 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 194 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 177 of file txorphanage.cpp.
Check if a {tx, peer} exists in the orphanage.
Definition at line 188 of file txorphanage.cpp.
bool TxOrphanage::HaveTxToReconsider | ( | NodeId | peer | ) |
Does this peer have any work to do?
Definition at line 212 of file txorphanage.cpp.
void TxOrphanage::LimitOrphans | ( | unsigned int | max_orphans, |
FastRandomContext & | rng | ||
) |
Limit the orphanage to the given maximum.
Definition at line 123 of file txorphanage.cpp.
|
inline |
Return how many entries exist in the orphange.
Definition at line 75 of file txorphanage.h.
|
protected |
Timestamp for the next scheduled sweep of expired orphans.
Definition at line 121 of file txorphanage.h.
|
protected |
Orphan transactions in vector for quick random eviction.
Definition at line 118 of file txorphanage.h.
Map from wtxid to orphan transaction record.
Limited by -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS
Definition at line 97 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 115 of file txorphanage.h.
Which peer provided the orphans that need to be reconsidered.
Definition at line 100 of file txorphanage.h.