24 const uint256& hash = tx->GetHash();
25 if (m_orphans.count(hash))
44 m_orphan_list.push_back(ret.first);
46 m_wtxid_to_orphan_it.emplace(tx->GetWitnessHash(), ret.first);
47 for (
const CTxIn& txin : tx->vin) {
48 m_outpoint_to_orphan_it[txin.
prevout].insert(ret.first);
52 m_orphans.size(), m_outpoint_to_orphan_it.size());
59 std::map<uint256, OrphanTx>::iterator it = m_orphans.find(txid);
60 if (it == m_orphans.end())
62 for (
const CTxIn& txin : it->second.tx->vin)
64 auto itPrev = m_outpoint_to_orphan_it.find(txin.
prevout);
65 if (itPrev == m_outpoint_to_orphan_it.end())
67 itPrev->second.erase(it);
68 if (itPrev->second.empty())
69 m_outpoint_to_orphan_it.erase(itPrev);
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()) {
77 auto it_last = m_orphan_list.back();
78 m_orphan_list[old_pos] = it_last;
79 it_last->second.list_pos = old_pos;
81 m_orphan_list.pop_back();
82 m_wtxid_to_orphan_it.erase(it->second.tx->GetWitnessHash());
93 std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
94 while (iter != m_orphans.end())
96 std::map<uint256, OrphanTx>::iterator maybeErase = iter++;
97 if (maybeErase->second.fromPeer == peer)
99 nErased +=
EraseTx(maybeErase->second.tx->GetHash());
109 unsigned int nEvicted = 0;
110 static int64_t nNextSweep;
112 if (nNextSweep <= nNow) {
116 std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
117 while (iter != m_orphans.end())
119 std::map<uint256, OrphanTx>::iterator maybeErase = iter++;
120 if (maybeErase->second.nTimeExpire <= nNow) {
121 nErased +=
EraseTx(maybeErase->second.tx->GetHash());
123 nMinExpTime = std::min(maybeErase->second.nTimeExpire, nMinExpTime);
131 while (m_orphans.size() > max_orphans)
134 size_t randompos = rng.
randrange(m_orphan_list.size());
135 EraseTx(m_orphan_list[randompos]->first);
144 for (
unsigned int i = 0; i < tx.
vout.size(); i++) {
145 const auto it_by_prev = m_outpoint_to_orphan_it.find(
COutPoint(tx.
GetHash(), i));
146 if (it_by_prev != m_outpoint_to_orphan_it.end()) {
147 for (
const auto& elem : it_by_prev->second) {
148 orphan_work_set.insert(elem->first);
154 bool TxOrphanage::HaveTx(
const GenTxid& gtxid)
const
158 return m_wtxid_to_orphan_it.count(gtxid.
GetHash());
160 return m_orphans.count(gtxid.
GetHash());
168 const auto it = m_orphans.find(txid);
169 if (it == m_orphans.end())
return {
nullptr, -1};
170 return {it->second.tx, it->second.fromPeer};
173 void TxOrphanage::EraseForBlock(
const CBlock& block)
177 std::vector<uint256> vOrphanErase;
183 for (
const auto& txin : tx.
vin) {
184 auto itByPrev = m_outpoint_to_orphan_it.find(txin.prevout);
185 if (itByPrev == m_outpoint_to_orphan_it.end())
continue;
186 for (
auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
189 vOrphanErase.push_back(orphanHash);
195 if (vOrphanErase.size()) {
197 for (
const uint256& orphanHash : vOrphanErase) {
198 nErased +=
EraseTx(orphanHash);