Skip to content

Commit e486597

Browse files
committed
Merge bitcoin#31918: fuzz: add basic TxOrphanage::EraseForBlock cov
8400b74 fuzz: add basic TxOrphanage::EraseForBlock cov (Greg Sanders) Pull request description: Currently uncovered ACKs for top commit: dergoegge: utACK 8400b74 marcofleon: ACK 8400b74 Tree-SHA512: 8c032ffa15ccce73ee1e0b2425d9c303acd4ec87c43f05de0cb96f4d831faeb5651175a32a7fc3ed81bf9400ee4416ca826999777326c29d06e3bd67cb06068c
2 parents 279ab20 + 8400b74 commit e486597

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/fuzz/txorphan.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
4747

4848
CTransactionRef ptx_potential_parent = nullptr;
4949

50+
std::vector<CTransactionRef> tx_history;
51+
5052
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
5153
{
5254
// construct transaction
@@ -75,6 +77,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
7577
return new_tx;
7678
}();
7779

80+
tx_history.push_back(tx);
81+
7882
const auto wtxid{tx->GetWitnessHash()};
7983

8084
// 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)
195199
Assert(!orphanage.HaveTxFromPeer(tx->GetWitnessHash(), peer_id));
196200
Assert(orphanage.UsageByPeer(peer_id) == 0);
197201
},
202+
[&] {
203+
// Make a block out of txs and then EraseForBlock
204+
CBlock block;
205+
int num_txs = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1000);
206+
for (int i{0}; i < num_txs; ++i) {
207+
auto& tx_to_remove = PickValue(fuzzed_data_provider, tx_history);
208+
block.vtx.push_back(tx_to_remove);
209+
}
210+
orphanage.EraseForBlock(block);
211+
for (const auto& tx_removed : block.vtx) {
212+
Assert(!orphanage.HaveTx(tx_removed->GetWitnessHash()));
213+
Assert(!orphanage.HaveTxFromPeer(tx_removed->GetWitnessHash(), peer_id));
214+
}
215+
},
198216
[&] {
199217
// test mocktime and expiry
200218
SetMockTime(ConsumeTime(fuzzed_data_provider));

0 commit comments

Comments
 (0)