mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-29 08:19:21 +02:00
txorphanage: Move functions and data into class
Collects all the orphan handling globals into a single member var in net_processing, and ensures access is encapuslated into the interface functions. Also adds doxygen comments for methods.
This commit is contained in:
@@ -17,14 +17,7 @@ static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
|
||||
|
||||
RecursiveMutex g_cs_orphans;
|
||||
|
||||
std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
|
||||
std::map<uint256, std::map<uint256, COrphanTx>::iterator> g_orphans_by_wtxid GUARDED_BY(g_cs_orphans);
|
||||
|
||||
std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans);
|
||||
|
||||
std::vector<std::map<uint256, COrphanTx>::iterator> g_orphan_list GUARDED_BY(g_cs_orphans);
|
||||
|
||||
bool OrphanageAddTx(const CTransactionRef& tx, NodeId peer)
|
||||
bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
|
||||
@@ -60,8 +53,9 @@ bool OrphanageAddTx(const CTransactionRef& tx, NodeId peer)
|
||||
return true;
|
||||
}
|
||||
|
||||
int EraseOrphanTx(const uint256& txid)
|
||||
int TxOrphanage::EraseTx(const uint256& txid)
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
std::map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find(txid);
|
||||
if (it == mapOrphanTransactions.end())
|
||||
return 0;
|
||||
@@ -91,7 +85,7 @@ int EraseOrphanTx(const uint256& txid)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EraseOrphansFor(NodeId peer)
|
||||
void TxOrphanage::EraseForPeer(NodeId peer)
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
|
||||
@@ -102,13 +96,13 @@ void EraseOrphansFor(NodeId peer)
|
||||
std::map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
|
||||
if (maybeErase->second.fromPeer == peer)
|
||||
{
|
||||
nErased += EraseOrphanTx(maybeErase->second.tx->GetHash());
|
||||
nErased += EraseTx(maybeErase->second.tx->GetHash());
|
||||
}
|
||||
}
|
||||
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
|
||||
}
|
||||
|
||||
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
||||
unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
|
||||
@@ -124,7 +118,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
||||
{
|
||||
std::map<uint256, COrphanTx>::iterator maybeErase = iter++;
|
||||
if (maybeErase->second.nTimeExpire <= nNow) {
|
||||
nErased += EraseOrphanTx(maybeErase->second.tx->GetHash());
|
||||
nErased += EraseTx(maybeErase->second.tx->GetHash());
|
||||
} else {
|
||||
nMinExpTime = std::min(maybeErase->second.nTimeExpire, nMinExpTime);
|
||||
}
|
||||
@@ -138,13 +132,13 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
||||
{
|
||||
// Evict a random orphan:
|
||||
size_t randompos = rng.randrange(g_orphan_list.size());
|
||||
EraseOrphanTx(g_orphan_list[randompos]->first);
|
||||
EraseTx(g_orphan_list[randompos]->first);
|
||||
++nEvicted;
|
||||
}
|
||||
return nEvicted;
|
||||
}
|
||||
|
||||
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set)
|
||||
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) const
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||
@@ -157,7 +151,7 @@ void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work
|
||||
}
|
||||
}
|
||||
|
||||
bool HaveOrphanTx(const GenTxid& gtxid)
|
||||
bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
|
||||
{
|
||||
LOCK(g_cs_orphans);
|
||||
if (gtxid.IsWtxid()) {
|
||||
@@ -167,7 +161,7 @@ bool HaveOrphanTx(const GenTxid& gtxid)
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& txid)
|
||||
std::pair<CTransactionRef, NodeId> TxOrphanage::GetTx(const uint256& txid) const
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
|
||||
@@ -176,7 +170,7 @@ std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& txid)
|
||||
return {it->second.tx, it->second.fromPeer};
|
||||
}
|
||||
|
||||
void EraseOrphansForBlock(const CBlock& block)
|
||||
void TxOrphanage::EraseForBlock(const CBlock& block)
|
||||
{
|
||||
LOCK(g_cs_orphans);
|
||||
|
||||
@@ -201,7 +195,7 @@ void EraseOrphansForBlock(const CBlock& block)
|
||||
if (vOrphanErase.size()) {
|
||||
int nErased = 0;
|
||||
for (const uint256& orphanHash : vOrphanErase) {
|
||||
nErased += EraseOrphanTx(orphanHash);
|
||||
nErased += EraseTx(orphanHash);
|
||||
}
|
||||
LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx included or conflicted by block\n", nErased);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user