mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-12 06:53:11 +02:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user