Fix miniminer_tests to work with cluster limits
What changed, and why it matters
This commit only changes a test file (miniminer_tests.cpp) so that existing unit tests still pass after a new mempool 'cluster limit' rule was introduced. It does not change any production code that runs on real Bitcoin nodes, so it cannot directly affect live network security or be exploited by attackers.
No security action required. Treat as a normal test-maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch updates src/test/miniminer_tests.cpp. It replaces a single 500-transaction chain with 10 separate 50-transaction chains, and reduces a zig-zag cluster from 50+49 transactions to 32+31 transactions. These adjustments keep the test cases within the new cluster-size limits while preserving the same test assertions (e.g., GatherClusters returns the expected set, and a 501st transaction causes an empty cluster). No consensus, mempool policy, P2P, wallet, or RPC code is modified.
Changed components
src/test/miniminer_tests.cppInspect captured patch +20 / −14
diff --git a/src/test/miniminer_tests.cpp b/src/test/miniminer_tests.cpp
index 28f467a4..45c932c1 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<Txid> last_txs;
std::vector<Txid> 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<Txid> 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<size_t> indices{0, 22, 72, zigzag_txids.size() - 1};
+ const std::vector<size_t> 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());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.