Skip to content

Commit e868b22

Browse files
committed
fee estimator: avoid sorting mempool on shutdown
1 parent 0975406 commit e868b22

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void Shutdown()
205205

206206
if (fFeeEstimatesInitialized)
207207
{
208-
::feeEstimator.FlushUnconfirmed(::mempool);
208+
::feeEstimator.FlushUnconfirmed();
209209
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
210210
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION);
211211
if (!est_fileout.IsNull())

src/policy/fees.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -981,16 +981,17 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
981981
return true;
982982
}
983983

984-
void CBlockPolicyEstimator::FlushUnconfirmed(CTxMemPool& pool) {
984+
void CBlockPolicyEstimator::FlushUnconfirmed() {
985985
int64_t startclear = GetTimeMicros();
986-
std::vector<uint256> txids;
987-
pool.queryHashes(txids);
988986
LOCK(cs_feeEstimator);
989-
for (auto& txid : txids) {
990-
removeTx(txid, false);
987+
size_t num_entries = mapMemPoolTxs.size();
988+
// Remove every entry in mapMemPoolTxs
989+
while (!mapMemPoolTxs.empty()) {
990+
auto mi = mapMemPoolTxs.begin();
991+
removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs
991992
}
992993
int64_t endclear = GetTimeMicros();
993-
LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n",txids.size(), (endclear - startclear)*0.000001);
994+
LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001);
994995
}
995996

996997
FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)

src/policy/fees.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class CBlockPolicyEstimator
223223
bool Read(CAutoFile& filein);
224224

225225
/** Empty mempool transactions on shutdown to record failure to confirm for txs still in mempool */
226-
void FlushUnconfirmed(CTxMemPool& pool);
226+
void FlushUnconfirmed();
227227

228228
/** Calculation of highest target that estimates are tracked for */
229229
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const;

0 commit comments

Comments
 (0)