Skip to content

Commit ddb94fd

Browse files
committed
Merge bitcoin#35289: fuzz: Fix timeout in txorphan
004a7e3 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](https://github.com/bitcoin/bitcoin/blob/3cab711d69572431af78b0071fb721496f0241d7/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](https://github.com/bitcoin/bitcoin/blob/3cab711d69572431af78b0071fb721496f0241d7/src/net_processing.cpp#L2090). ACKs for top commit: maflcko: lgtm ACK 004a7e3 instagibbs: ACK 004a7e3 sedited: ACK 004a7e3 Tree-SHA512: 465504402358e1bed629104b21e05301139f1590884de21e77d566a45e422eef6d4380c5714692f33f5398e4e299b8c9f84b82f58c56a98e410c5c841184aee5
2 parents 3cab711 + 004a7e3 commit ddb94fd

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/test/fuzz/txorphan.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,13 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
197197
[&] {
198198
// Make a block out of txs and then EraseForBlock
199199
CBlock block;
200+
int64_t block_weight{0};
200201
int num_txs = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1000);
201202
for (int i{0}; i < num_txs; ++i) {
202203
auto& tx_to_remove = PickValue(fuzzed_data_provider, tx_history);
204+
const auto tx_weight = GetTransactionWeight(*tx_to_remove);
205+
if (block_weight + tx_weight > MAX_BLOCK_WEIGHT) break;
206+
block_weight += tx_weight;
203207
block.vtx.push_back(tx_to_remove);
204208
}
205209
orphanage->EraseForBlock(block);

0 commit comments

Comments
 (0)