Skip to content

Commit f024578

Browse files
committed
miner: Absorb SkipMapTxEntry into addPackageTxs
SkipMapTxEntry is a short helper function that's only used in addPackageTxs, we can just inline it, keep the comments, and avoid the unnecessary interface and lock annotations.
1 parent 345457b commit f024578

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/node/miner.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,6 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
262262
return nDescendantsUpdated;
263263
}
264264

265-
// Skip entries in mapTx that are already in a block or are present
266-
// in mapModifiedTx (which implies that the mapTx ancestor state is
267-
// stale due to ancestor inclusion in the block)
268-
// Also skip transactions that we've already failed to add. This can happen if
269-
// we consider a transaction in mapModifiedTx and it fails: we can then
270-
// potentially consider it again while walking mapTx. It's currently
271-
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
272-
// failedTx and avoid re-evaluation, since the re-evaluation would be using
273-
// cached size/sigops/fee values that are not actually correct.
274-
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
275-
{
276-
AssertLockHeld(m_mempool.cs);
277-
278-
assert(it != m_mempool.mapTx.end());
279-
return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
280-
}
281-
282265
void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries)
283266
{
284267
// Sort package by ancestor count
@@ -321,10 +304,25 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
321304

322305
while (mi != m_mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) {
323306
// First try to find a new transaction in mapTx to evaluate.
324-
if (mi != m_mempool.mapTx.get<ancestor_score>().end() &&
325-
SkipMapTxEntry(m_mempool.mapTx.project<0>(mi), mapModifiedTx, failedTx)) {
326-
++mi;
327-
continue;
307+
//
308+
// Skip entries in mapTx that are already in a block or are present
309+
// in mapModifiedTx (which implies that the mapTx ancestor state is
310+
// stale due to ancestor inclusion in the block)
311+
// Also skip transactions that we've already failed to add. This can happen if
312+
// we consider a transaction in mapModifiedTx and it fails: we can then
313+
// potentially consider it again while walking mapTx. It's currently
314+
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
315+
// failedTx and avoid re-evaluation, since the re-evaluation would be using
316+
// cached size/sigops/fee values that are not actually correct.
317+
/** Return true if given transaction from mapTx has already been evaluated,
318+
* or if the transaction's cached data in mapTx is incorrect. */
319+
if (mi != m_mempool.mapTx.get<ancestor_score>().end()) {
320+
auto it = m_mempool.mapTx.project<0>(mi);
321+
assert(it != m_mempool.mapTx.end());
322+
if (mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it)) {
323+
++mi;
324+
continue;
325+
}
328326
}
329327

330328
// Now that mi is not stale, determine which transaction to evaluate:

src/node/miner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ class BlockAssembler
189189
* These checks should always succeed, and they're here
190190
* only as an extra check in case of suboptimal node configuration */
191191
bool TestPackageTransactions(const CTxMemPool::setEntries& package) const;
192-
/** Return true if given transaction from mapTx has already been evaluated,
193-
* or if the transaction's cached data in mapTx is incorrect. */
194-
bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
195192
/** Sort the package in an order that is valid to appear in a block */
196193
void SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries);
197194
/** Add descendants of given transactions to mapModifiedTx with ancestor

0 commit comments

Comments
 (0)