diff --git a/src/node/txorphanage.cpp b/src/node/txorphanage.cpp index 6093be46ce4..ce087d17ffb 100644 --- a/src/node/txorphanage.cpp +++ b/src/node/txorphanage.cpp @@ -567,6 +567,8 @@ bool TxOrphanageImpl::HaveTxToReconsider(NodeId peer) } void TxOrphanageImpl::EraseForBlock(const CBlock& block) { + if (m_orphans.empty()) return; + std::set wtxids_to_erase; for (const CTransactionRef& ptx : block.vtx) { const CTransaction& block_tx = *ptx; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index d65005fc645..7a66751db5a 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -661,26 +661,25 @@ void CTxMemPool::removeConflicts(const CTransaction &tx) } } -/** - * Called when a block is connected. Removes from mempool. - */ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight) { + // Remove confirmed txs and conflicts when a new block is connected, updating the fee logic AssertLockHeld(cs); Assume(!m_have_changeset); std::vector txs_removed_for_block; - txs_removed_for_block.reserve(vtx.size()); - 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, true, MemPoolRemovalReason::BLOCK); + if (mapTx.size() || mapNextTx.size() || mapDeltas.size()) { + txs_removed_for_block.reserve(vtx.size()); + 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, true, MemPoolRemovalReason::BLOCK); + } + removeConflicts(*tx); + ClearPrioritisation(tx->GetHash()); } - removeConflicts(*tx); - ClearPrioritisation(tx->GetHash()); } if (m_opts.signals) { m_opts.signals->MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);