aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2021-01-31 23:37:41 +1000
committerAnthony Towns <aj@erisian.com.au>2021-02-27 00:31:09 +1000
commit03257b832debcb1470420d8657d30ba30f4be770 (patch)
tree37d9ea35a839832c1629523ef8345139e0bd55c7 /src/net_processing.cpp
parent3c4c3c2fdda3a361e3802e97bc3566f815b75de1 (diff)
downloadbitcoin-03257b832debcb1470420d8657d30ba30f4be770.tar.xz
txorphanage: Extract EraseOrphansForBlock
Extract code that erases orphans when a new block is found into EraseOrphansForBlock.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 67a0c0e3d2..f1b5c6f38d 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1261,37 +1261,9 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
*/
void PeerManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
{
- {
- LOCK(g_cs_orphans);
-
- std::vector<uint256> vOrphanErase;
-
- for (const CTransactionRef& ptx : pblock->vtx) {
- const CTransaction& tx = *ptx;
+ EraseOrphansForBlock(*pblock);
+ m_last_tip_update = GetTime();
- // 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 uint256& orphanHash = orphanTx.GetHash();
- vOrphanErase.push_back(orphanHash);
- }
- }
- }
-
- // Erase orphan transactions included or precluded by this block
- if (vOrphanErase.size()) {
- int nErased = 0;
- for (const uint256& orphanHash : vOrphanErase) {
- nErased += EraseOrphanTx(orphanHash);
- }
- 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 auto& ptx : pblock->vtx) {