mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
Merge bitcoin/bitcoin#25683: refactor: log nEvicted
message in LimitOrphans
then return void
b4b657ba57
refactor: log `nEvicted` message in `LimitOrphans` then return void (chinggg)
Pull request description:
Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49347
LimitOrphans() can log expired tx and it should log evicted tx as well instead of returning the `nEvicted` number for caller to print the message.
Since `LimitOrphans()` now returns void, the redundant assertion check in fuzz test is also removed.
Top commit has no ACKs.
Tree-SHA512: 18c41702321b0e59812590cd389f3163831d431f4ebdc3b3e1e0698496a6bdbac52288f28f779237a58813c6717da1a35e8933d509822978ff726c1b13cfc778
This commit is contained in:
commit
b1c8ea45c9
4 changed files with 5 additions and 10 deletions
|
@ -3631,10 +3631,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
||||
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
|
||||
unsigned int nEvicted = m_orphanage.LimitOrphans(nMaxOrphanTx);
|
||||
if (nEvicted > 0) {
|
||||
LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted);
|
||||
}
|
||||
m_orphanage.LimitOrphans(nMaxOrphanTx);
|
||||
} else {
|
||||
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
|
||||
// We will continue to reject this tx since it has rejected
|
||||
|
|
|
@ -138,10 +138,8 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
|
|||
[&] {
|
||||
// test mocktime and expiry
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
auto size_before = orphanage.Size();
|
||||
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
auto n_evicted = WITH_LOCK(g_cs_orphans, return orphanage.LimitOrphans(limit));
|
||||
Assert(size_before - n_evicted <= limit);
|
||||
WITH_LOCK(g_cs_orphans, orphanage.LimitOrphans(limit));
|
||||
Assert(orphanage.Size() <= limit);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
|
|||
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
|
||||
}
|
||||
|
||||
unsigned int TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
||||
void TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
||||
{
|
||||
AssertLockHeld(g_cs_orphans);
|
||||
|
||||
|
@ -135,7 +135,7 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
|||
EraseTx(m_orphan_list[randompos]->first);
|
||||
++nEvicted;
|
||||
}
|
||||
return nEvicted;
|
||||
if (nEvicted > 0) LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted);
|
||||
}
|
||||
|
||||
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) const
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
void EraseForBlock(const CBlock& block) LOCKS_EXCLUDED(::g_cs_orphans);
|
||||
|
||||
/** Limit the orphanage to the given maximum */
|
||||
unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||
void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||
|
||||
/** Add any orphans that list a particular tx as a parent into a peer's work set
|
||||
* (ie orphans that may have found their final missing parent, and so should be reconsidered for the mempool) */
|
||||
|
|
Loading…
Reference in a new issue