Merge bitcoin/bitcoin#35289: fuzz: Fix timeout in txorphan

004a7e3cfb fuzz: Fix txorphan timeout by limiting block weight (marcofleon)

Pull request description:

  The `EraseForBlock` branch in the `txorphan` harness could produce a block with 1000 transactions in it, each with potentially up to 200,000 inputs, resulting in way too many [map lookups](3cab711d69/src/node/txorphanage.cpp (L625)). This was producing inputs that were taking 2 seconds or longer per iteration, which is too long.

  Fix by only adding transactions to the block up to the block weight limit. This matches production behavior, as `EraseForBlock` is only called on a newly [connected block](3cab711d69/src/net_processing.cpp (L2090)).

ACKs for top commit:
  maflcko:
    lgtm ACK 004a7e3cfb
  instagibbs:
    ACK 004a7e3cfb
  sedited:
    ACK 004a7e3cfb

Tree-SHA512: 465504402358e1bed629104b21e05301139f1590884de21e77d566a45e422eef6d4380c5714692f33f5398e4e299b8c9f84b82f58c56a98e410c5c841184aee5
This commit is contained in:
merge-script
2026-05-14 17:25:50 +02:00

View File

@@ -197,9 +197,13 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
[&] {
// Make a block out of txs and then EraseForBlock
CBlock block;
int64_t block_weight{0};
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);
const auto tx_weight = GetTransactionWeight(*tx_to_remove);
if (block_weight + tx_weight > MAX_BLOCK_WEIGHT) break;
block_weight += tx_weight;
block.vtx.push_back(tx_to_remove);
}
orphanage->EraseForBlock(block);