diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1968,43 +1968,9 @@ */ void PeerManagerImpl::BlockConnected( const std::shared_ptr &pblock, const CBlockIndex *pindex) { - { - LOCK(g_cs_orphans); - - std::vector vOrphanErase; - - for (const CTransactionRef &ptx : pblock->vtx) { - const CTransaction &tx = *ptx; - - // Which orphan pool entries must we evict? - for (const auto &txin : tx.vin) { - auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout); - if (itByPrev == mapOrphanTransactionsByPrev.end()) { - continue; - } - - for (auto mi = itByPrev->second.begin(); - mi != itByPrev->second.end(); ++mi) { - const CTransaction &orphanTx = *(*mi)->second.tx; - const TxId &orphanId = orphanTx.GetId(); - vOrphanErase.push_back(orphanId); - } - } - } + EraseOrphansForBlock(*pblock); + m_last_tip_update = GetTime(); - // Erase orphan transactions included or precluded by this block - if (vOrphanErase.size()) { - int nErased = 0; - for (const auto &orphanId : vOrphanErase) { - nErased += EraseOrphanTx(orphanId); - } - LogPrint(BCLog::MEMPOOL, - "Erased %d orphan tx included or conflicted by block\n", - nErased); - } - - m_last_tip_update = GetTime(); - } { LOCK(m_recent_confirmed_transactions_mutex); for (const CTransactionRef &ptx : pblock->vtx) { diff --git a/src/txorphanage.h b/src/txorphanage.h --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -6,6 +6,7 @@ #define BITCOIN_TXORPHANAGE_H #include +#include #include #include @@ -22,6 +23,7 @@ int EraseOrphanTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); +void EraseOrphansForBlock(const CBlock &block) LOCKS_EXCLUDED(g_cs_orphans); unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); void AddChildrenToWorkSet(const CTransaction &tx, diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -180,3 +180,39 @@ } return {it->second.tx, it->second.fromPeer}; } + +void EraseOrphansForBlock(const CBlock &block) { + LOCK(g_cs_orphans); + + std::vector vOrphanErase; + + for (const CTransactionRef &ptx : block.vtx) { + const CTransaction &tx = *ptx; + + // Which orphan pool entries must we evict? + for (const auto &txin : tx.vin) { + auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout); + if (itByPrev == mapOrphanTransactionsByPrev.end()) { + continue; + } + + for (auto mi = itByPrev->second.begin(); + mi != itByPrev->second.end(); ++mi) { + const CTransaction &orphanTx = *(*mi)->second.tx; + const TxId &orphanId = orphanTx.GetId(); + vOrphanErase.push_back(orphanId); + } + } + } + + // Erase orphan transactions included or precluded by this block + if (vOrphanErase.size()) { + int nErased = 0; + for (const auto &orphanId : vOrphanErase) { + nErased += EraseOrphanTx(orphanId); + } + LogPrint(BCLog::MEMPOOL, + "Erased %d orphan tx included or conflicted by block\n", + nErased); + } +}