| 54 | } |
| 55 | |
| 56 | int TxOrphanage::EraseTx(const uint256& txid) |
| 57 | { |
| 58 | AssertLockHeld(g_cs_orphans); |
| 59 | std::map<uint256, OrphanTx>::iterator it = m_orphans.find(txid); |
| 60 | if (it == m_orphans.end()) |
| 61 | return 0; |
| 62 | for (const CTxIn& txin : it->second.tx->vin) |
| 63 | { |
| 64 | auto itPrev = m_outpoint_to_orphan_it.find(txin.prevout); |
| 65 | if (itPrev == m_outpoint_to_orphan_it.end()) |
| 66 | continue; |
| 67 | itPrev->second.erase(it); |
| 68 | if (itPrev->second.empty()) |
| 69 | m_outpoint_to_orphan_it.erase(itPrev); |
| 70 | } |
| 71 | |
| 72 | size_t old_pos = it->second.list_pos; |
| 73 | assert(m_orphan_list[old_pos] == it); |
| 74 | if (old_pos + 1 != m_orphan_list.size()) { |
| 75 | // Unless we're deleting the last entry in m_orphan_list, move the last |
| 76 | // entry to the position we're deleting. |
| 77 | auto it_last = m_orphan_list.back(); |
| 78 | m_orphan_list[old_pos] = it_last; |
| 79 | it_last->second.list_pos = old_pos; |
| 80 | } |
| 81 | m_orphan_list.pop_back(); |
| 82 | m_wtxid_to_orphan_it.erase(it->second.tx->GetWitnessHash()); |
| 83 | |
| 84 | m_orphans.erase(it); |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | void TxOrphanage::EraseForPeer(NodeId peer) |
| 89 | { |