@@ -23,7 +23,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
23
23
24
24
const Txid& hash = tx->GetHash ();
25
25
const Wtxid& wtxid = tx->GetWitnessHash ();
26
- if (m_orphans.count (hash ))
26
+ if (m_orphans.count (wtxid ))
27
27
return false ;
28
28
29
29
// Ignore big transactions, to avoid a
@@ -40,11 +40,9 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
40
40
return false ;
41
41
}
42
42
43
- auto ret = m_orphans.emplace (hash , OrphanTx{tx, peer, GetTime () + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size ()});
43
+ auto ret = m_orphans.emplace (wtxid , OrphanTx{tx, peer, GetTime () + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size ()});
44
44
assert (ret.second );
45
45
m_orphan_list.push_back (ret.first );
46
- // Allow for lookups in the orphan pool by wtxid, as well as txid
47
- m_wtxid_to_orphan_it.emplace (tx->GetWitnessHash (), ret.first );
48
46
for (const CTxIn& txin : tx->vin ) {
49
47
m_outpoint_to_orphan_it[txin.prevout ].insert (ret.first );
50
48
}
@@ -63,10 +61,7 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
63
61
int TxOrphanage::EraseTxNoLock (const Wtxid& wtxid)
64
62
{
65
63
AssertLockHeld (m_mutex);
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 ;
64
+ std::map<Wtxid, OrphanTx>::iterator it = m_orphans.find (wtxid);
70
65
if (it == m_orphans.end ())
71
66
return 0 ;
72
67
for (const CTxIn& txin : it->second .tx ->vin )
@@ -91,7 +86,6 @@ int TxOrphanage::EraseTxNoLock(const Wtxid& wtxid)
91
86
const auto & txid = it->second .tx ->GetHash ();
92
87
LogPrint (BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s)\n " , txid.ToString (), wtxid.ToString ());
93
88
m_orphan_list.pop_back ();
94
- m_wtxid_to_orphan_it.erase (wtxid);
95
89
96
90
m_orphans.erase (it);
97
91
return 1 ;
@@ -104,13 +98,13 @@ void TxOrphanage::EraseForPeer(NodeId peer)
104
98
m_peer_work_set.erase (peer);
105
99
106
100
int nErased = 0 ;
107
- std::map<Txid , OrphanTx>::iterator iter = m_orphans.begin ();
101
+ std::map<Wtxid , OrphanTx>::iterator iter = m_orphans.begin ();
108
102
while (iter != m_orphans.end ())
109
103
{
110
- std::map<Txid, OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
111
- if (maybeErase-> second . fromPeer == peer)
112
- {
113
- nErased += EraseTxNoLock (maybeErase-> second . tx -> GetWitnessHash () );
104
+ // increment to avoid iterator becoming invalid after erasure
105
+ const auto & [wtxid, orphan] = *iter++;
106
+ if (orphan. fromPeer == peer) {
107
+ nErased += EraseTxNoLock (wtxid );
114
108
}
115
109
}
116
110
if (nErased > 0 ) LogPrint (BCLog::TXPACKAGES, " Erased %d orphan tx from peer=%d\n " , nErased, peer);
@@ -127,10 +121,10 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
127
121
// Sweep out expired orphan pool entries:
128
122
int nErased = 0 ;
129
123
int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
130
- std::map<Txid , OrphanTx>::iterator iter = m_orphans.begin ();
124
+ std::map<Wtxid , OrphanTx>::iterator iter = m_orphans.begin ();
131
125
while (iter != m_orphans.end ())
132
126
{
133
- std::map<Txid , OrphanTx>::iterator maybeErase = iter++;
127
+ std::map<Wtxid , OrphanTx>::iterator maybeErase = iter++;
134
128
if (maybeErase->second .nTimeExpire <= nNow) {
135
129
nErased += EraseTxNoLock (maybeErase->second .tx ->GetWitnessHash ());
136
130
} else {
@@ -162,7 +156,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
162
156
for (const auto & elem : it_by_prev->second ) {
163
157
// Get this source peer's work set, emplacing an empty set if it didn't exist
164
158
// (note: if this peer wasn't still connected, we would have removed the orphan tx already)
165
- std::set<Txid >& orphan_work_set = m_peer_work_set.try_emplace (elem->second .fromPeer ).first ->second ;
159
+ std::set<Wtxid >& orphan_work_set = m_peer_work_set.try_emplace (elem->second .fromPeer ).first ->second ;
166
160
// Add this tx to the work set
167
161
orphan_work_set.insert (elem->first );
168
162
LogPrint (BCLog::TXPACKAGES, " added %s (wtxid=%s) to peer %d workset\n " ,
@@ -175,7 +169,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
175
169
bool TxOrphanage::HaveTx (const Wtxid& wtxid) const
176
170
{
177
171
LOCK (m_mutex);
178
- return m_wtxid_to_orphan_it .count (wtxid);
172
+ return m_orphans .count (wtxid);
179
173
}
180
174
181
175
CTransactionRef TxOrphanage::GetTxToReconsider (NodeId peer)
@@ -186,10 +180,10 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
186
180
if (work_set_it != m_peer_work_set.end ()) {
187
181
auto & work_set = work_set_it->second ;
188
182
while (!work_set.empty ()) {
189
- Txid txid = *work_set.begin ();
183
+ Wtxid wtxid = *work_set.begin ();
190
184
work_set.erase (work_set.begin ());
191
185
192
- const auto orphan_it = m_orphans.find (txid );
186
+ const auto orphan_it = m_orphans.find (wtxid );
193
187
if (orphan_it != m_orphans.end ()) {
194
188
return orphan_it->second .tx ;
195
189
}
0 commit comments