From d2dcd37aac1e723a4103f2d6fefaa492141f5d42 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Mon, 10 Nov 2025 18:19:18 -0500 Subject: [PATCH] Avoid using mapTx.modify() to update modified fees Now that the mempool no longer keeps any feerate-based indices, we can modify feerates in mempool entries directly. --- src/kernel/mempool_entry.h | 4 ++-- src/txmempool.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kernel/mempool_entry.h b/src/kernel/mempool_entry.h index b274e1f7eee..3053a77c3e6 100644 --- a/src/kernel/mempool_entry.h +++ b/src/kernel/mempool_entry.h @@ -80,7 +80,7 @@ private: const unsigned int entryHeight; //!< Chain height when entering the mempool const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase const int64_t sigOpCost; //!< Total sigop cost - CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block + mutable CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block mutable LockPoints lockPoints; //!< Track the height and time at which tx was final public: @@ -124,7 +124,7 @@ public: const LockPoints& GetLockPoints() const { return lockPoints; } // Updates the modified fees with descendants/ancestors. - void UpdateModifiedFee(CAmount fee_diff) + void UpdateModifiedFee(CAmount fee_diff) const { m_modified_fee = SaturatingAdd(m_modified_fee, fee_diff); } diff --git a/src/txmempool.cpp b/src/txmempool.cpp index ee4ced3b0c8..de4a5572821 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -598,7 +598,7 @@ void CTxMemPool::PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelt if (it != mapTx.end()) { // PrioritiseTransaction calls stack on previous ones. Set the new // transaction fee to be current modified fee + feedelta. - mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); }); + it->UpdateModifiedFee(nFeeDelta); m_txgraph->SetTransactionFee(*it, it->GetModifiedFee()); ++nTransactionsUpdated; } @@ -975,7 +975,7 @@ CTxMemPool::ChangeSet::TxHandle CTxMemPool::ChangeSet::StageAddition(const CTran TxGraph::Ref ref(m_pool->m_txgraph->AddTransaction(FeePerWeight(fee, GetSigOpsAdjustedWeight(GetTransactionWeight(*tx), sigops_cost, ::nBytesPerSigOp)))); auto newit = m_to_add.emplace(std::move(ref), tx, fee, time, entry_height, entry_sequence, spends_coinbase, sigops_cost, lp).first; if (delta) { - m_to_add.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); }); + newit->UpdateModifiedFee(delta); m_pool->m_txgraph->SetTransactionFee(*newit, newit->GetModifiedFee()); }