mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-08 14:34:53 -05:00
Merge bitcoin/bitcoin#29031: fuzz: Improve fuzzing stability for txorphan harness
15f5a0d0c8
fuzz: Improve fuzzing stability for txorphan harness (dergoegge) Pull request description: The `txorphan` harness has low stability as eviction of orphan txs is entirely random at the moment. Fix this by passing the rng to `LimitOrphans`, which can be deterministic in tests. Also see #29018. ACKs for top commit: maflcko: lgtm ACK15f5a0d0c8
brunoerg: utACK15f5a0d0c8
Tree-SHA512: 854ec34b3a0f16f26db6dc419096c6e7a380e8400119534aa278d6b1d54c253b572aa2fad13c383c796c431d8ff4263956e6f60326e99f8bf6abd16d9a280e97
This commit is contained in:
commit
40bc501bf4
5 changed files with 9 additions and 8 deletions
|
@ -4298,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
||||||
|
|
||||||
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
||||||
m_orphanage.LimitOrphans(m_opts.max_orphan_txs);
|
m_orphanage.LimitOrphans(m_opts.max_orphan_txs, m_rng);
|
||||||
} else {
|
} else {
|
||||||
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s (wtxid=%s)\n",
|
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s (wtxid=%s)\n",
|
||||||
tx.GetHash().ToString(),
|
tx.GetHash().ToString(),
|
||||||
|
|
|
@ -33,6 +33,7 @@ void initialize_orphanage()
|
||||||
FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
FastRandomContext limit_orphans_rng{/*fDeterministic=*/true};
|
||||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||||
|
|
||||||
TxOrphanage orphanage;
|
TxOrphanage orphanage;
|
||||||
|
@ -132,7 +133,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
||||||
// test mocktime and expiry
|
// test mocktime and expiry
|
||||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||||
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||||
orphanage.LimitOrphans(limit);
|
orphanage.LimitOrphans(limit, limit_orphans_rng);
|
||||||
Assert(orphanage.Size() <= limit);
|
Assert(orphanage.Size() <= limit);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,11 +129,12 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test LimitOrphanTxSize() function:
|
// Test LimitOrphanTxSize() function:
|
||||||
orphanage.LimitOrphans(40);
|
FastRandomContext rng{/*fDeterministic=*/true};
|
||||||
|
orphanage.LimitOrphans(40, rng);
|
||||||
BOOST_CHECK(orphanage.CountOrphans() <= 40);
|
BOOST_CHECK(orphanage.CountOrphans() <= 40);
|
||||||
orphanage.LimitOrphans(10);
|
orphanage.LimitOrphans(10, rng);
|
||||||
BOOST_CHECK(orphanage.CountOrphans() <= 10);
|
BOOST_CHECK(orphanage.CountOrphans() <= 10);
|
||||||
orphanage.LimitOrphans(0);
|
orphanage.LimitOrphans(0, rng);
|
||||||
BOOST_CHECK(orphanage.CountOrphans() == 0);
|
BOOST_CHECK(orphanage.CountOrphans() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
|
||||||
if (nErased > 0) LogPrint(BCLog::TXPACKAGES, "Erased %d orphan tx from peer=%d\n", nErased, peer);
|
if (nErased > 0) LogPrint(BCLog::TXPACKAGES, "Erased %d orphan tx from peer=%d\n", nErased, peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
|
||||||
{
|
{
|
||||||
LOCK(m_mutex);
|
LOCK(m_mutex);
|
||||||
|
|
||||||
|
@ -138,7 +138,6 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
||||||
nNextSweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
|
nNextSweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
|
||||||
if (nErased > 0) LogPrint(BCLog::TXPACKAGES, "Erased %d orphan tx due to expiration\n", nErased);
|
if (nErased > 0) LogPrint(BCLog::TXPACKAGES, "Erased %d orphan tx due to expiration\n", nErased);
|
||||||
}
|
}
|
||||||
FastRandomContext rng;
|
|
||||||
while (m_orphans.size() > max_orphans)
|
while (m_orphans.size() > max_orphans)
|
||||||
{
|
{
|
||||||
// Evict a random orphan:
|
// Evict a random orphan:
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
||||||
|
|
||||||
/** Limit the orphanage to the given maximum */
|
/** Limit the orphanage to the given maximum */
|
||||||
void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
void LimitOrphans(unsigned int max_orphans, FastRandomContext& rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
||||||
|
|
||||||
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
||||||
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
||||||
|
|
Loading…
Add table
Reference in a new issue