Merge bitcoin/bitcoin#31918: fuzz: add basic TxOrphanage::EraseForBlock cov

8400b742fa fuzz: add basic TxOrphanage::EraseForBlock cov (Greg Sanders)

Pull request description:

  Currently uncovered

ACKs for top commit:
  dergoegge:
    utACK 8400b742fa
  marcofleon:
    ACK 8400b742fa

Tree-SHA512: 8c032ffa15ccce73ee1e0b2425d9c303acd4ec87c43f05de0cb96f4d831faeb5651175a32a7fc3ed81bf9400ee4416ca826999777326c29d06e3bd67cb06068c
This commit is contained in:
merge-script 2025-02-21 11:05:17 -05:00
commit e486597f9a
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -47,6 +47,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
CTransactionRef ptx_potential_parent = nullptr;
std::vector<CTransactionRef> tx_history;
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
{
// construct transaction
@ -75,6 +77,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
return new_tx;
}();
tx_history.push_back(tx);
const auto wtxid{tx->GetWitnessHash()};
// Trigger orphanage functions that are called using parents. ptx_potential_parent is a tx we constructed in a
@ -195,6 +199,20 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
Assert(!orphanage.HaveTxFromPeer(tx->GetWitnessHash(), peer_id));
Assert(orphanage.UsageByPeer(peer_id) == 0);
},
[&] {
// Make a block out of txs and then EraseForBlock
CBlock block;
int num_txs = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1000);
for (int i{0}; i < num_txs; ++i) {
auto& tx_to_remove = PickValue(fuzzed_data_provider, tx_history);
block.vtx.push_back(tx_to_remove);
}
orphanage.EraseForBlock(block);
for (const auto& tx_removed : block.vtx) {
Assert(!orphanage.HaveTx(tx_removed->GetWitnessHash()));
Assert(!orphanage.HaveTxFromPeer(tx_removed->GetWitnessHash(), peer_id));
}
},
[&] {
// test mocktime and expiry
SetMockTime(ConsumeTime(fuzzed_data_provider));