From 79f73ad713a8d62a6172fbad228cbca848f9ff57 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 17 Sep 2025 13:26:45 -0400 Subject: [PATCH] Add check that GetSortedScoreWithTopology() agrees with CompareMiningScoreWithTopology() We use CompareMiningScoreWithTopology() for sorting transaction announcements during tx relay, and we use GetSortedScoreWithTopology() in CTxMemPool::check(). --- src/txmempool.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 5197fb012df..592f6194523 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -425,11 +425,20 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei CCoinsViewCache mempoolDuplicate(const_cast(&active_coins_tip)); + std::optional last_wtxid = std::nullopt; + for (const auto& it : GetSortedScoreWithTopology()) { checkTotal += it->GetTxSize(); check_total_fee += it->GetFee(); innerUsage += it->DynamicMemoryUsage(); const CTransaction& tx = it->GetTx(); + + // CompareMiningScoreWithTopology should agree with GetSortedScoreWithTopology() + if (last_wtxid) { + assert(CompareMiningScoreWithTopology(*last_wtxid, tx.GetWitnessHash())); + } + last_wtxid = tx.GetWitnessHash(); + std::set setParentCheck; std::set setParentsStored; for (const CTxIn &txin : tx.vin) {