From 1ca4f01090cfa968c789fafde42054da3263a0e2 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Sat, 8 Feb 2025 13:38:19 -0500 Subject: [PATCH] Fix miniminer_tests to work with cluster limits --- src/test/miniminer_tests.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/test/miniminer_tests.cpp b/src/test/miniminer_tests.cpp index 28f467a416e..45c932c1f03 100644 --- a/src/test/miniminer_tests.cpp +++ b/src/test/miniminer_tests.cpp @@ -598,17 +598,23 @@ BOOST_FIXTURE_TEST_CASE(calculate_cluster, TestChain100Setup) CTxMemPool& pool = *Assert(m_node.mempool); LOCK2(cs_main, pool.cs); - // Add chain of size 500 - TestMemPoolEntryHelper entry; + // Add 500 transactions in 10 clusters + std::vector last_txs; std::vector chain_txids; auto& lasttx = m_coinbase_txns[0]; - for (auto i{0}; i < 500; ++i) { - const auto tx = make_tx({COutPoint{lasttx->GetHash(), 0}}, /*num_outputs=*/1); - AddToMempool(pool, entry.Fee(CENT).FromTx(tx)); - chain_txids.push_back(tx->GetHash()); - lasttx = tx; + TestMemPoolEntryHelper entry; + for (int cluster_count=0; cluster_count < 10; ++cluster_count) { + // Add chain of size 50 + lasttx = m_coinbase_txns[cluster_count]; + for (auto i{0}; i < 50; ++i) { + const auto tx = make_tx({COutPoint{lasttx->GetHash(), 0}}, /*num_outputs=*/1); + AddToMempool(pool, entry.Fee(CENT).FromTx(tx)); + chain_txids.push_back(tx->GetHash()); + lasttx = tx; + } + last_txs.emplace_back(lasttx->GetHash()); } - const auto cluster_500tx = pool.GatherClusters({lasttx->GetHash()}); + const auto cluster_500tx = pool.GatherClusters(last_txs); CTxMemPool::setEntries cluster_500tx_set{cluster_500tx.begin(), cluster_500tx.end()}; BOOST_CHECK_EQUAL(cluster_500tx.size(), cluster_500tx_set.size()); const auto vec_iters_500 = pool.GetIterVec(chain_txids); @@ -617,29 +623,29 @@ BOOST_FIXTURE_TEST_CASE(calculate_cluster, TestChain100Setup) // GatherClusters stops at 500 transactions. const auto tx_501 = make_tx({COutPoint{lasttx->GetHash(), 0}}, /*num_outputs=*/1); AddToMempool(pool, entry.Fee(CENT).FromTx(tx_501)); - const auto cluster_501 = pool.GatherClusters({tx_501->GetHash()}); + const auto cluster_501 = pool.GatherClusters(last_txs); BOOST_CHECK_EQUAL(cluster_501.size(), 0); /* Zig Zag cluster: - * txp0 txp1 txp2 ... txp48 txp49 + * txp0 txp1 txp2 ... txp30 txp31 * \ / \ / \ \ / - * txc0 txc1 txc2 ... txc48 + * txc0 txc1 txc2 ... txc30 * Note that each transaction's ancestor size is 1 or 3, and each descendant size is 1, 2 or 3. * However, all of these transactions are in the same cluster. */ std::vector zigzag_txids; - for (auto p{0}; p < 50; ++p) { + for (auto p{0}; p < 32; ++p) { const auto txp = make_tx({COutPoint{Txid::FromUint256(GetRandHash()), 0}}, /*num_outputs=*/2); AddToMempool(pool, entry.Fee(CENT).FromTx(txp)); zigzag_txids.push_back(txp->GetHash()); } - for (auto c{0}; c < 49; ++c) { + for (auto c{0}; c < 31; ++c) { const auto txc = make_tx({COutPoint{zigzag_txids[c], 1}, COutPoint{zigzag_txids[c+1], 0}}, /*num_outputs=*/1); AddToMempool(pool, entry.Fee(CENT).FromTx(txc)); zigzag_txids.push_back(txc->GetHash()); } const auto vec_iters_zigzag = pool.GetIterVec(zigzag_txids); // It doesn't matter which tx we calculate cluster for, everybody is in it. - const std::vector indices{0, 22, 72, zigzag_txids.size() - 1}; + const std::vector indices{0, 22, 52, zigzag_txids.size() - 1}; for (const auto index : indices) { const auto cluster = pool.GatherClusters({zigzag_txids[index]}); BOOST_CHECK_EQUAL(cluster.size(), zigzag_txids.size());