Skip to content

Commit 5ee5b69

Browse files
committed
refactor: Add non-thread-safe CBlockPolicyEstimator::_removeTx helper
This changes removes recursion in the m_cs_fee_estimator locks.
1 parent 5c3033d commit 5ee5b69

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/policy/fees.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe
473473
bool CBlockPolicyEstimator::removeTx(uint256 hash, bool inBlock)
474474
{
475475
LOCK(m_cs_fee_estimator);
476+
return _removeTx(hash, inBlock);
477+
}
478+
479+
bool CBlockPolicyEstimator::_removeTx(const uint256& hash, bool inBlock)
480+
{
481+
AssertLockHeld(m_cs_fee_estimator);
476482
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
477483
if (pos != mapMemPoolTxs.end()) {
478484
feeStats->removeTx(pos->second.blockHeight, nBestSeenHeight, pos->second.bucketIndex, inBlock);
@@ -556,7 +562,8 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
556562

557563
bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
558564
{
559-
if (!removeTx(entry->GetTx().GetHash(), true)) {
565+
AssertLockHeld(m_cs_fee_estimator);
566+
if (!_removeTx(entry->GetTx().GetHash(), true)) {
560567
// This transaction wasn't being tracked for fee estimation
561568
return false;
562569
}
@@ -965,7 +972,7 @@ void CBlockPolicyEstimator::FlushUnconfirmed() {
965972
// Remove every entry in mapMemPoolTxs
966973
while (!mapMemPoolTxs.empty()) {
967974
auto mi = mapMemPoolTxs.begin();
968-
removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs
975+
_removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs
969976
}
970977
int64_t endclear = GetTimeMicros();
971978
LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001);

src/policy/fees.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ class CBlockPolicyEstimator
194194
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
195195

196196
/** Remove a transaction from the mempool tracking stats*/
197-
bool removeTx(uint256 hash, bool inBlock);
197+
bool removeTx(uint256 hash, bool inBlock)
198+
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
198199

199200
/** DEPRECATED. Return a feerate estimate */
200201
CFeeRate estimateFee(int confTarget) const
@@ -278,6 +279,10 @@ class CBlockPolicyEstimator
278279
unsigned int HistoricalBlockSpan() const EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
279280
/** Calculation of highest target that reasonable estimate can be provided for */
280281
unsigned int MaxUsableEstimate() const EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
282+
283+
/** A non-thread-safe helper for the removeTx function */
284+
bool _removeTx(const uint256& hash, bool inBlock)
285+
EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
281286
};
282287

283288
class FeeFilterRounder

0 commit comments

Comments
 (0)