fuzz: send blocktxn messages in cmpctblock harness

Sometimes, blindly take an existing block and choose random
transactions to request in a blocktxn message.
This commit is contained in:
Eugene Siegel
2026-02-04 10:10:00 -05:00
parent d0333bfe99
commit c8d688f41c

View File

@@ -379,6 +379,29 @@ FUZZ_TARGET(cmpctblock, .init = initialize_cmpctblock)
CBlockHeaderAndShortTxIDs base_cmpctblock = cmpctblock;
net_msg = NetMsg::Make(NetMsgType::CMPCTBLOCK, base_cmpctblock);
},
[&]() {
// Send a blocktxn message for an existing block (if one exists).
size_t num_blocks = info.size();
if (num_blocks == 0) {
sent_net_msg = false;
return;
}
// Fetch an existing block and randomly choose transactions to send over.
size_t index = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, num_blocks - 1);
const BlockInfo& block_info = info[index];
BlockTransactions block_txn;
block_txn.blockhash = block_info.hash;
std::shared_ptr<CBlock> cblock = block_info.block;
for (size_t i = 0; i < cblock->vtx.size(); i++) {
if (fuzzed_data_provider.ConsumeBool()) continue;
block_txn.txn.push_back(cblock->vtx[i]);
}
net_msg = NetMsg::Make(NetMsgType::BLOCKTXN, block_txn);
},
[&]() {
// Send a headers message for an existing block (if one exists).
size_t num_blocks = info.size();