mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
[prep/test] have TxOrphanage remember its own limits in LimitOrphans
Move towards a model where TxOrphanage is initialized with limits that it remembers throughout its lifetime. Remove the param. Limiting by number of unique orphans will be removed in a later commit. Now that -maxorphantx is gone, this does not change the node behavior. The parameter is only used in tests.
This commit is contained in:
@@ -41,8 +41,6 @@ struct TxDownloadOptions {
|
||||
const CTxMemPool& m_mempool;
|
||||
/** RNG provided by caller. */
|
||||
FastRandomContext& m_rng;
|
||||
/** Maximum number of transactions allowed in orphanage. */
|
||||
const uint32_t m_max_orphan_txs;
|
||||
/** Instantiate TxRequestTracker as deterministic (used for tests). */
|
||||
bool m_deterministic_txrequest{false};
|
||||
};
|
||||
|
||||
@@ -422,7 +422,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
|
||||
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
||||
// Note that, if the orphanage reaches capacity, it's possible that we immediately evict
|
||||
// the transaction we just added.
|
||||
m_orphanage.LimitOrphans(m_opts.m_max_orphan_txs, m_opts.m_rng);
|
||||
m_orphanage.LimitOrphans(m_opts.m_rng);
|
||||
} else {
|
||||
unique_parents.clear();
|
||||
LogDebug(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s (wtxid=%s)\n",
|
||||
|
||||
@@ -141,7 +141,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
|
||||
if (nErased > 0) LogDebug(BCLog::TXPACKAGES, "Erased %d orphan transaction(s) from peer=%d\n", nErased, peer);
|
||||
}
|
||||
|
||||
void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
|
||||
void TxOrphanage::LimitOrphans(FastRandomContext& rng)
|
||||
{
|
||||
unsigned int nEvicted = 0;
|
||||
auto nNow{Now<NodeSeconds>()};
|
||||
@@ -163,7 +163,7 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
|
||||
m_next_sweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
|
||||
if (nErased > 0) LogDebug(BCLog::TXPACKAGES, "Erased %d orphan tx due to expiration\n", nErased);
|
||||
}
|
||||
while (m_orphans.size() > max_orphans)
|
||||
while (m_orphans.size() > DEFAULT_MAX_ORPHAN_TRANSACTIONS)
|
||||
{
|
||||
// Evict a random orphan:
|
||||
size_t randompos = rng.randrange(m_orphan_list.size());
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
/** Erase all orphans included in or invalidated by a new block */
|
||||
void EraseForBlock(const CBlock& block);
|
||||
|
||||
/** Limit the orphanage to the given maximum */
|
||||
void LimitOrphans(unsigned int max_orphans, FastRandomContext& rng);
|
||||
/** Limit the orphanage to DEFAULT_MAX_ORPHAN_TRANSACTIONS. */
|
||||
void LimitOrphans(FastRandomContext& rng);
|
||||
|
||||
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
||||
void AddChildrenToWorkSet(const CTransaction& tx, FastRandomContext& rng);
|
||||
|
||||
Reference in New Issue
Block a user