From ff3b398d124b9efa49b612dbbb715bbe5d53e727 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 4 Oct 2023 09:28:05 -0400 Subject: [PATCH] mempool: eliminate accessors to mempool entry ancestor/descendant cached state --- src/kernel/mempool_entry.h | 9 --------- src/txmempool.cpp | 25 +------------------------ 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/kernel/mempool_entry.h b/src/kernel/mempool_entry.h index 28c2290cb5d..2e61f1023c4 100644 --- a/src/kernel/mempool_entry.h +++ b/src/kernel/mempool_entry.h @@ -166,17 +166,8 @@ public: lockPoints = lp; } - uint64_t GetCountWithDescendants() const { return m_count_with_descendants; } - int64_t GetSizeWithDescendants() const { return nSizeWithDescendants; } - CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; } - bool GetSpendsCoinbase() const { return spendsCoinbase; } - uint64_t GetCountWithAncestors() const { return m_count_with_ancestors; } - int64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } - CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } - int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; } - const Parents& GetMemPoolParentsConst() const { return m_parents; } const Children& GetMemPoolChildrenConst() const { return m_children; } Parents& GetMemPoolParents() const { return m_parents; } diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 7c3be6e1d85..28a6418b944 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -720,40 +720,17 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei }; assert(setParentCheck.size() == it->GetMemPoolParentsConst().size()); assert(std::equal(setParentCheck.begin(), setParentCheck.end(), it->GetMemPoolParentsConst().begin(), comp)); - // Verify ancestor state is correct. - auto ancestors{AssumeCalculateMemPoolAncestors(__func__, *it, Limits::NoLimits())}; - uint64_t nCountCheck = ancestors.size() + 1; - int32_t nSizeCheck = it->GetTxSize(); - CAmount nFeesCheck = it->GetModifiedFee(); - int64_t nSigOpCheck = it->GetSigOpCost(); - - for (txiter ancestorIt : ancestors) { - nSizeCheck += ancestorIt->GetTxSize(); - nFeesCheck += ancestorIt->GetModifiedFee(); - nSigOpCheck += ancestorIt->GetSigOpCost(); - } - - assert(it->GetCountWithAncestors() == nCountCheck); - assert(it->GetSizeWithAncestors() == nSizeCheck); - assert(it->GetSigOpCostWithAncestors() == nSigOpCheck); - assert(it->GetModFeesWithAncestors() == nFeesCheck); // Check children against mapNextTx CTxMemPoolEntry::Children setChildrenCheck; auto iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0)); - int32_t child_sizes{0}; for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) { txiter childit = iter->second; assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions - if (setChildrenCheck.insert(*childit).second) { - child_sizes += childit->GetTxSize(); - } + setChildrenCheck.insert(*childit); } assert(setChildrenCheck.size() == it->GetMemPoolChildrenConst().size()); assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(), it->GetMemPoolChildrenConst().begin(), comp)); - // Also check to make sure size is greater than sum with immediate children. - // just a sanity check, not definitive that this calc is correct... - assert(it->GetSizeWithDescendants() >= child_sizes + it->GetTxSize()); TxValidationState dummy_state; // Not used. CheckTxInputs() should always pass CAmount txfee = 0;