Skip to content

Commit 1a64b05

Browse files
committed
scratch: multiple mempool txns, multiple new txns
1 parent 87c1e0d commit 1a64b05

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/test/fuzz/cmpctblock.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ FUZZ_TARGET(cmpctblock, .init=initialize_cmpctblock)
171171
// If the mempool is non-empty, choose a mempool outpoint. Otherwise, choose a coinbase.
172172
COutPoint outpoint;
173173
unsigned long mempool_size = setup->m_node.mempool->size();
174-
if (mempool_size != 0) {
174+
if (fuzzed_data_provider.ConsumeBool() && mempool_size != 0) {
175175
size_t random_idx = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, mempool_size - 1);
176176
LOCK(setup->m_node.mempool->cs);
177177
outpoint = COutPoint(setup->m_node.mempool->txns_randomized[random_idx].second->GetSharedTx()->GetHash(), 0);
@@ -239,20 +239,27 @@ FUZZ_TARGET(cmpctblock, .init=initialize_cmpctblock)
239239
coinbase_tx.vout[0].nValue = COIN;
240240
block->vtx.push_back(MakeTransactionRef(coinbase_tx));
241241

242-
// Add a tx from mempool. Since we do not include parents, it may be an invalid block.
243242
const auto mempool_size = setup->m_node.mempool->size();
244243
if (fuzzed_data_provider.ConsumeBool() && mempool_size != 0) {
245-
LOCK(setup->m_node.mempool->cs);
244+
// Add txns from the mempool. Since we do not include parents, it may be an invalid block.
245+
size_t num_txns = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, mempool_size);
246246
size_t random_idx = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, mempool_size - 1);
247-
CTransactionRef mempool_tx = setup->m_node.mempool->txns_randomized[random_idx].second->GetSharedTx();
248-
block->vtx.push_back(mempool_tx);
247+
248+
LOCK(setup->m_node.mempool->cs);
249+
for (int i = random_idx; i < random_idx + num_txns; ++i) {
250+
CTransactionRef mempool_tx = setup->m_node.mempool->txns_randomized[i % mempool_size].second->GetSharedTx();
251+
block->vtx.push_back(mempool_tx);
252+
}
249253
}
250254

251-
// Create and add a (possibly invalid) tx that is not in the mempool.
255+
// Create and add (possibly invalid) txns that are not in the mempool.
252256
if (fuzzed_data_provider.ConsumeBool()) {
253-
CTransactionRef non_mempool_tx = create_tx();
254-
if (non_mempool_tx != nullptr) {
255-
block->vtx.push_back(non_mempool_tx);
257+
size_t new_txns = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 10);
258+
for (int i = 0; i < new_txns; ++i) {
259+
CTransactionRef non_mempool_tx = create_tx();
260+
if (non_mempool_tx != nullptr) {
261+
block->vtx.push_back(non_mempool_tx);
262+
}
256263
}
257264
}
258265

0 commit comments

Comments
 (0)