Skip to content

Commit 03254c2

Browse files
committed
Merge bitcoin/bitcoin#19909: refactor: Remove unused CTxMemPool::clear() helper
fa818e1 txmempool: Remove unused clear() member function (MarcoFalke) Pull request description: Seems odd to have code in Bitcoin Core that is unused. Moreover the function was broken (see bitcoin/bitcoin#24145) and is brittle, as there is nothing that prevents similar bugs from re-appearing. Fix both issues by replacing it with C++11 member initializers. ACKs for top commit: glozow: ACK fa818e1 Tree-SHA512: e79e44cac7d5a84d9ecc8e3f3b0b9a50e1e3ebec358b20ba5dac175ef07d1fbe338a20f83ee80f746f7c726c79e77f8be49e14bca57a41063da8a5302123c3a9
2 parents 3f8591d + fa818e1 commit 03254c2

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

src/test/txvalidationcache_tests.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
7777
LOCK(cs_main);
7878
BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() != block.GetHash());
7979
}
80-
m_node.mempool->clear();
80+
BOOST_CHECK_EQUAL(m_node.mempool->size(), 1U);
81+
WITH_LOCK(m_node.mempool->cs, m_node.mempool->removeRecursive(CTransaction{spends[0]}, MemPoolRemovalReason::CONFLICT));
82+
BOOST_CHECK_EQUAL(m_node.mempool->size(), 0U);
8183

8284
// Test 3: ... and should be rejected if spend2 is in the memory pool
8385
BOOST_CHECK(ToMemPool(spends[1]));
@@ -86,7 +88,9 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
8688
LOCK(cs_main);
8789
BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() != block.GetHash());
8890
}
89-
m_node.mempool->clear();
91+
BOOST_CHECK_EQUAL(m_node.mempool->size(), 1U);
92+
WITH_LOCK(m_node.mempool->cs, m_node.mempool->removeRecursive(CTransaction{spends[1]}, MemPoolRemovalReason::CONFLICT));
93+
BOOST_CHECK_EQUAL(m_node.mempool->size(), 0U);
9094

9195
// Final sanity test: first spend in *m_node.mempool, second in block, that's OK:
9296
std::vector<CMutableTransaction> oneSpend;

src/txmempool.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ CTxMemPool::CTxMemPool(const Options& opts)
396396
m_full_rbf{opts.full_rbf},
397397
m_limits{opts.limits}
398398
{
399-
_clear(); //lock free clear
400399
}
401400

402401
bool CTxMemPool::isSpent(const COutPoint& outpoint) const
@@ -634,26 +633,6 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
634633
blockSinceLastRollingFeeBump = true;
635634
}
636635

637-
void CTxMemPool::_clear()
638-
{
639-
vTxHashes.clear();
640-
mapTx.clear();
641-
mapNextTx.clear();
642-
totalTxSize = 0;
643-
m_total_fee = 0;
644-
cachedInnerUsage = 0;
645-
lastRollingFeeUpdate = GetTime();
646-
blockSinceLastRollingFeeBump = false;
647-
rollingMinimumFeeRate = 0;
648-
++nTransactionsUpdated;
649-
}
650-
651-
void CTxMemPool::clear()
652-
{
653-
LOCK(cs);
654-
_clear();
655-
}
656-
657636
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
658637
{
659638
if (m_check_ratio == 0) return;

src/txmempool.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ class CTxMemPool
319319
std::atomic<unsigned int> nTransactionsUpdated{0}; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
320320
CBlockPolicyEstimator* const minerPolicyEstimator;
321321

322-
uint64_t totalTxSize GUARDED_BY(cs); //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
323-
CAmount m_total_fee GUARDED_BY(cs); //!< sum of all mempool tx's fees (NOT modified fee)
324-
uint64_t cachedInnerUsage GUARDED_BY(cs); //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
322+
uint64_t totalTxSize GUARDED_BY(cs){0}; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
323+
CAmount m_total_fee GUARDED_BY(cs){0}; //!< sum of all mempool tx's fees (NOT modified fee)
324+
uint64_t cachedInnerUsage GUARDED_BY(cs){0}; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
325325

326-
mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs);
327-
mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs);
328-
mutable double rollingMinimumFeeRate GUARDED_BY(cs); //!< minimum fee to get into the pool, decreases exponentially
329-
mutable Epoch m_epoch GUARDED_BY(cs);
326+
mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs){GetTime()};
327+
mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs){false};
328+
mutable double rollingMinimumFeeRate GUARDED_BY(cs){0}; //!< minimum fee to get into the pool, decreases exponentially
329+
mutable Epoch m_epoch GUARDED_BY(cs){};
330330

331331
// In-memory counter for external mempool tracking purposes.
332332
// This number is incremented once every time a transaction
@@ -500,8 +500,6 @@ class CTxMemPool
500500
void removeConflicts(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
501501
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
502502

503-
void clear();
504-
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free
505503
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid=false);
506504
void queryHashes(std::vector<uint256>& vtxid) const;
507505
bool isSpent(const COutPoint& outpoint) const;

0 commit comments

Comments
 (0)