@@ -54,16 +54,19 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
54
54
return true ;
55
55
}
56
56
57
- int TxOrphanage::EraseTx (const Txid& txid )
57
+ int TxOrphanage::EraseTx (const Wtxid& wtxid )
58
58
{
59
59
LOCK (m_mutex);
60
- return EraseTxNoLock (txid );
60
+ return EraseTxNoLock (wtxid );
61
61
}
62
62
63
- int TxOrphanage::EraseTxNoLock (const Txid& txid )
63
+ int TxOrphanage::EraseTxNoLock (const Wtxid& wtxid )
64
64
{
65
65
AssertLockHeld (m_mutex);
66
- std::map<Txid, OrphanTx>::iterator it = m_orphans.find (txid);
66
+ auto it_by_wtxid = m_wtxid_to_orphan_it.find (wtxid);
67
+ if (it_by_wtxid == m_wtxid_to_orphan_it.end ()) return 0 ;
68
+
69
+ std::map<Txid, OrphanTx>::iterator it = it_by_wtxid->second ;
67
70
if (it == m_orphans.end ())
68
71
return 0 ;
69
72
for (const CTxIn& txin : it->second .tx ->vin )
@@ -85,10 +88,10 @@ int TxOrphanage::EraseTxNoLock(const Txid& txid)
85
88
m_orphan_list[old_pos] = it_last;
86
89
it_last->second .list_pos = old_pos;
87
90
}
88
- const auto & wtxid = it->second .tx ->GetWitnessHash ();
91
+ const auto & txid = it->second .tx ->GetHash ();
89
92
LogPrint (BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s)\n " , txid.ToString (), wtxid.ToString ());
90
93
m_orphan_list.pop_back ();
91
- m_wtxid_to_orphan_it.erase (it-> second . tx -> GetWitnessHash () );
94
+ m_wtxid_to_orphan_it.erase (wtxid );
92
95
93
96
m_orphans.erase (it);
94
97
return 1 ;
@@ -107,7 +110,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
107
110
std::map<Txid, OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
108
111
if (maybeErase->second .fromPeer == peer)
109
112
{
110
- nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
113
+ nErased += EraseTxNoLock (maybeErase->second .tx ->GetWitnessHash ());
111
114
}
112
115
}
113
116
if (nErased > 0 ) LogPrint (BCLog::TXPACKAGES, " Erased %d orphan tx from peer=%d\n " , nErased, peer);
@@ -129,7 +132,7 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
129
132
{
130
133
std::map<Txid, OrphanTx>::iterator maybeErase = iter++;
131
134
if (maybeErase->second .nTimeExpire <= nNow) {
132
- nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
135
+ nErased += EraseTxNoLock (maybeErase->second .tx ->GetWitnessHash ());
133
136
} else {
134
137
nMinExpTime = std::min (maybeErase->second .nTimeExpire , nMinExpTime);
135
138
}
@@ -142,7 +145,7 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
142
145
{
143
146
// Evict a random orphan:
144
147
size_t randompos = rng.randrange (m_orphan_list.size ());
145
- EraseTxNoLock (m_orphan_list[randompos]->first );
148
+ EraseTxNoLock (m_orphan_list[randompos]->second . tx -> GetWitnessHash () );
146
149
++nEvicted;
147
150
}
148
151
if (nEvicted > 0 ) LogPrint (BCLog::TXPACKAGES, " orphanage overflow, removed %u tx\n " , nEvicted);
@@ -211,7 +214,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
211
214
{
212
215
LOCK (m_mutex);
213
216
214
- std::vector<Txid > vOrphanErase;
217
+ std::vector<Wtxid > vOrphanErase;
215
218
216
219
for (const CTransactionRef& ptx : block.vtx ) {
217
220
const CTransaction& tx = *ptx;
@@ -222,8 +225,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
222
225
if (itByPrev == m_outpoint_to_orphan_it.end ()) continue ;
223
226
for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
224
227
const CTransaction& orphanTx = *(*mi)->second .tx ;
225
- const auto & orphanHash = orphanTx.GetHash ();
226
- vOrphanErase.push_back (orphanHash);
228
+ vOrphanErase.push_back (orphanTx.GetWitnessHash ());
227
229
}
228
230
}
229
231
}
0 commit comments