7
7
#include < consensus/validation.h>
8
8
#include < logging.h>
9
9
#include < policy/policy.h>
10
+ #include < primitives/transaction.h>
10
11
11
12
#include < cassert>
12
13
@@ -20,8 +21,8 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
20
21
{
21
22
LOCK (m_mutex);
22
23
23
- const uint256 & hash = tx->GetHash ();
24
- const uint256 & wtxid = tx->GetWitnessHash ();
24
+ const Txid & hash = tx->GetHash ();
25
+ const Wtxid & wtxid = tx->GetWitnessHash ();
25
26
if (m_orphans.count (hash))
26
27
return false ;
27
28
@@ -53,16 +54,16 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
53
54
return true ;
54
55
}
55
56
56
- int TxOrphanage::EraseTx (const uint256 & txid)
57
+ int TxOrphanage::EraseTx (const Txid & txid)
57
58
{
58
59
LOCK (m_mutex);
59
60
return EraseTxNoLock (txid);
60
61
}
61
62
62
- int TxOrphanage::EraseTxNoLock (const uint256 & txid)
63
+ int TxOrphanage::EraseTxNoLock (const Txid & txid)
63
64
{
64
65
AssertLockHeld (m_mutex);
65
- std::map<uint256 , OrphanTx>::iterator it = m_orphans.find (txid);
66
+ std::map<Txid , OrphanTx>::iterator it = m_orphans.find (txid);
66
67
if (it == m_orphans.end ())
67
68
return 0 ;
68
69
for (const CTxIn& txin : it->second .tx ->vin )
@@ -100,10 +101,10 @@ void TxOrphanage::EraseForPeer(NodeId peer)
100
101
m_peer_work_set.erase (peer);
101
102
102
103
int nErased = 0 ;
103
- std::map<uint256 , OrphanTx>::iterator iter = m_orphans.begin ();
104
+ std::map<Txid , OrphanTx>::iterator iter = m_orphans.begin ();
104
105
while (iter != m_orphans.end ())
105
106
{
106
- std::map<uint256 , OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
107
+ std::map<Txid , OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
107
108
if (maybeErase->second .fromPeer == peer)
108
109
{
109
110
nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
@@ -123,10 +124,10 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
123
124
// Sweep out expired orphan pool entries:
124
125
int nErased = 0 ;
125
126
int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
126
- std::map<uint256 , OrphanTx>::iterator iter = m_orphans.begin ();
127
+ std::map<Txid , OrphanTx>::iterator iter = m_orphans.begin ();
127
128
while (iter != m_orphans.end ())
128
129
{
129
- std::map<uint256 , OrphanTx>::iterator maybeErase = iter++;
130
+ std::map<Txid , OrphanTx>::iterator maybeErase = iter++;
130
131
if (maybeErase->second .nTimeExpire <= nNow) {
131
132
nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
132
133
} else {
@@ -159,7 +160,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
159
160
for (const auto & elem : it_by_prev->second ) {
160
161
// Get this source peer's work set, emplacing an empty set if it didn't exist
161
162
// (note: if this peer wasn't still connected, we would have removed the orphan tx already)
162
- std::set<uint256 >& orphan_work_set = m_peer_work_set.try_emplace (elem->second .fromPeer ).first ->second ;
163
+ std::set<Txid >& orphan_work_set = m_peer_work_set.try_emplace (elem->second .fromPeer ).first ->second ;
163
164
// Add this tx to the work set
164
165
orphan_work_set.insert (elem->first );
165
166
LogPrint (BCLog::TXPACKAGES, " added %s (wtxid=%s) to peer %d workset\n " ,
@@ -173,9 +174,9 @@ bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
173
174
{
174
175
LOCK (m_mutex);
175
176
if (gtxid.IsWtxid ()) {
176
- return m_wtxid_to_orphan_it.count (gtxid.GetHash ());
177
+ return m_wtxid_to_orphan_it.count (Wtxid::FromUint256 ( gtxid.GetHash () ));
177
178
} else {
178
- return m_orphans.count (gtxid.GetHash ());
179
+ return m_orphans.count (Txid::FromUint256 ( gtxid.GetHash () ));
179
180
}
180
181
}
181
182
@@ -187,7 +188,7 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
187
188
if (work_set_it != m_peer_work_set.end ()) {
188
189
auto & work_set = work_set_it->second ;
189
190
while (!work_set.empty ()) {
190
- uint256 txid = *work_set.begin ();
191
+ Txid txid = *work_set.begin ();
191
192
work_set.erase (work_set.begin ());
192
193
193
194
const auto orphan_it = m_orphans.find (txid);
@@ -215,7 +216,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
215
216
{
216
217
LOCK (m_mutex);
217
218
218
- std::vector<uint256 > vOrphanErase;
219
+ std::vector<Txid > vOrphanErase;
219
220
220
221
for (const CTransactionRef& ptx : block.vtx ) {
221
222
const CTransaction& tx = *ptx;
@@ -226,7 +227,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
226
227
if (itByPrev == m_outpoint_to_orphan_it.end ()) continue ;
227
228
for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
228
229
const CTransaction& orphanTx = *(*mi)->second .tx ;
229
- const uint256 & orphanHash = orphanTx.GetHash ();
230
+ const auto & orphanHash = orphanTx.GetHash ();
230
231
vOrphanErase.push_back (orphanHash);
231
232
}
232
233
}
@@ -235,7 +236,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
235
236
// Erase orphan transactions included or precluded by this block
236
237
if (vOrphanErase.size ()) {
237
238
int nErased = 0 ;
238
- for (const uint256 & orphanHash : vOrphanErase) {
239
+ for (const auto & orphanHash : vOrphanErase) {
239
240
nErased += EraseTxNoLock (orphanHash);
240
241
}
241
242
LogPrint (BCLog::TXPACKAGES, " Erased %d orphan tx included or conflicted by block\n " , nErased);
0 commit comments