Invoke removeUnchecked() directly in removeForBlock()
What changed, and why it matters
This commit simplifies how Bitcoin Core removes transactions from the memory pool when they are included in a newly mined block. It replaces a small two-step staging process with a direct call to the underlying removal function. The change appears to be a straightforward code cleanup with no obvious security impact, though it removes a thin abstraction layer that previously ensured removal events were recorded consistently.
No immediate action required. Treat as routine refactoring. If reviewing for defense in depth, verify that RemoveStaged's usage accounting and logging are not relied upon by monitoring or fee-estimation code, and that removeUnchecked's internal invariants remain satisfied when called directly from removeForBlock().
Security signals we found
Refactoring of mempool removal path
Removal of intermediate RemoveStaged wrapper call
No change to validation, consensus, or network logic
No bounds, input, or cryptographic changes
Evidence from the diff
In CTxMemPool::removeForBlock(), the code previously created a setEntries container, inserted a single transaction iterator, and called RemoveStaged(stage, MemPoolRemovalReason::BLOCK). The patch calls removeUnchecked(it, MemPoolRemovalReason::BLOCK) directly. RemoveStaged() is a wrapper that iterates over staged entries and calls removeUnchecked() while updating mempool usage statistics and logging. removeUnchecked() performs the actual map erase and descendant tracking. The direct call bypasses the staging wrapper but preserves the same removal reason. The surrounding logic (removeConflicts, ClearPrioritisation) is unchanged.
Changed components
src/txmempool.cppCTxMemPool::removeForBlock()CTxMemPool::removeUnchecked()CTxMemPool::RemoveStaged()Inspect captured patch +1 / −3
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 1162634b..ee4ced3b 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -398,10 +398,8 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
for (const auto& tx : vtx) {
txiter it = mapTx.find(tx->GetHash());
if (it != mapTx.end()) {
- setEntries stage;
- stage.insert(it);
txs_removed_for_block.emplace_back(*it);
- RemoveStaged(stage, MemPoolRemovalReason::BLOCK);
+ removeUnchecked(it, MemPoolRemovalReason::BLOCK);
}
removeConflicts(*tx);
ClearPrioritisation(tx->GetHash());
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.