Skip to content

Commit 1a8f51e

Browse files
committed
Merge bitcoin/bitcoin#28843: [refactor] Cleanup BlockAssembler mempool usage
192dac1 [refactor] Cleanup BlockAssembler mempool usage (TheCharlatan) Pull request description: The `addPackageTxs` method of the `BlockAssembler` currently has access to two mempool variables, as an argument and as a member. Clean this up and clarify that they both are the same mempool instance by removing the argument and instead only using the member variable in the method. This was noticed in this PR review: bitcoin/bitcoin#25223 (comment). ACKs for top commit: achow101: ACK 192dac1 danielabrozzoni: re-ACK 192dac1 stickies-v: ACK 192dac1 Tree-SHA512: a5ae7d6d771fbb5b54f23624b4d3429acf07bbe38179a462a078c825d60c89a725ad4e13fe7067eebea7dfec63c56c8f39b5077b0d949d594f500affcc1272d1
2 parents 2d944e9 + 192dac1 commit 1a8f51e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/node/miner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
138138
int nPackagesSelected = 0;
139139
int nDescendantsUpdated = 0;
140140
if (m_mempool) {
141-
LOCK(m_mempool->cs);
142-
addPackageTxs(*m_mempool, nPackagesSelected, nDescendantsUpdated);
141+
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
143142
}
144143

145144
const auto time_1{SteadyClock::now()};
@@ -288,9 +287,10 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
288287
// Each time through the loop, we compare the best transaction in
289288
// mapModifiedTxs with the next transaction in the mempool to decide what
290289
// transaction package to work on next.
291-
void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSelected, int& nDescendantsUpdated)
290+
void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
292291
{
293-
AssertLockHeld(mempool.cs);
292+
const auto& mempool{*Assert(m_mempool)};
293+
LOCK(mempool.cs);
294294

295295
// mapModifiedTx will store sorted packages after they are modified
296296
// because some of their txs are already in the block

src/node/miner.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ class BlockAssembler
187187
// Methods for how to add transactions to a block.
188188
/** Add transactions based on feerate including unconfirmed ancestors
189189
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
190-
* statistics from the package selection (for logging statistics). */
191-
void addPackageTxs(const CTxMemPool& mempool, int& nPackagesSelected, int& nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
190+
* statistics from the package selection (for logging statistics).
191+
*
192+
* @pre BlockAssembler::m_mempool must not be nullptr
193+
*/
194+
void addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(!m_mempool->cs);
192195

193196
// helper functions for addPackageTxs()
194197
/** Remove confirmed (inBlock) entries from given set */

0 commit comments

Comments
 (0)