77#include < consensus/validation.h>
88#include < logging.h>
99#include < policy/policy.h>
10+ #include < primitives/transaction.h>
1011
1112#include < cassert>
1213
@@ -20,8 +21,8 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
2021{
2122 LOCK (m_mutex);
2223
23- const uint256 & hash = tx->GetHash ();
24- const uint256 & wtxid = tx->GetWitnessHash ();
24+ const Txid & hash = tx->GetHash ();
25+ const Wtxid & wtxid = tx->GetWitnessHash ();
2526 if (m_orphans.count (hash))
2627 return false ;
2728
@@ -53,16 +54,16 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
5354 return true ;
5455}
5556
56- int TxOrphanage::EraseTx (const uint256 & txid)
57+ int TxOrphanage::EraseTx (const Txid & txid)
5758{
5859 LOCK (m_mutex);
5960 return EraseTxNoLock (txid);
6061}
6162
62- int TxOrphanage::EraseTxNoLock (const uint256 & txid)
63+ int TxOrphanage::EraseTxNoLock (const Txid & txid)
6364{
6465 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);
6667 if (it == m_orphans.end ())
6768 return 0 ;
6869 for (const CTxIn& txin : it->second .tx ->vin )
@@ -100,10 +101,10 @@ void TxOrphanage::EraseForPeer(NodeId peer)
100101 m_peer_work_set.erase (peer);
101102
102103 int nErased = 0 ;
103- std::map<uint256 , OrphanTx>::iterator iter = m_orphans.begin ();
104+ std::map<Txid , OrphanTx>::iterator iter = m_orphans.begin ();
104105 while (iter != m_orphans.end ())
105106 {
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
107108 if (maybeErase->second .fromPeer == peer)
108109 {
109110 nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
@@ -123,10 +124,10 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
123124 // Sweep out expired orphan pool entries:
124125 int nErased = 0 ;
125126 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 ();
127128 while (iter != m_orphans.end ())
128129 {
129- std::map<uint256 , OrphanTx>::iterator maybeErase = iter++;
130+ std::map<Txid , OrphanTx>::iterator maybeErase = iter++;
130131 if (maybeErase->second .nTimeExpire <= nNow) {
131132 nErased += EraseTxNoLock (maybeErase->second .tx ->GetHash ());
132133 } else {
@@ -159,7 +160,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
159160 for (const auto & elem : it_by_prev->second ) {
160161 // Get this source peer's work set, emplacing an empty set if it didn't exist
161162 // (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 ;
163164 // Add this tx to the work set
164165 orphan_work_set.insert (elem->first );
165166 LogPrint (BCLog::TXPACKAGES, " added %s (wtxid=%s) to peer %d workset\n " ,
@@ -173,9 +174,9 @@ bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
173174{
174175 LOCK (m_mutex);
175176 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 () ));
177178 } else {
178- return m_orphans.count (gtxid.GetHash ());
179+ return m_orphans.count (Txid::FromUint256 ( gtxid.GetHash () ));
179180 }
180181}
181182
@@ -187,7 +188,7 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
187188 if (work_set_it != m_peer_work_set.end ()) {
188189 auto & work_set = work_set_it->second ;
189190 while (!work_set.empty ()) {
190- uint256 txid = *work_set.begin ();
191+ Txid txid = *work_set.begin ();
191192 work_set.erase (work_set.begin ());
192193
193194 const auto orphan_it = m_orphans.find (txid);
@@ -215,7 +216,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
215216{
216217 LOCK (m_mutex);
217218
218- std::vector<uint256 > vOrphanErase;
219+ std::vector<Txid > vOrphanErase;
219220
220221 for (const CTransactionRef& ptx : block.vtx ) {
221222 const CTransaction& tx = *ptx;
@@ -226,7 +227,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
226227 if (itByPrev == m_outpoint_to_orphan_it.end ()) continue ;
227228 for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
228229 const CTransaction& orphanTx = *(*mi)->second .tx ;
229- const uint256 & orphanHash = orphanTx.GetHash ();
230+ const auto & orphanHash = orphanTx.GetHash ();
230231 vOrphanErase.push_back (orphanHash);
231232 }
232233 }
@@ -235,7 +236,7 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
235236 // Erase orphan transactions included or precluded by this block
236237 if (vOrphanErase.size ()) {
237238 int nErased = 0 ;
238- for (const uint256 & orphanHash : vOrphanErase) {
239+ for (const auto & orphanHash : vOrphanErase) {
239240 nErased += EraseTxNoLock (orphanHash);
240241 }
241242 LogPrint (BCLog::TXPACKAGES, " Erased %d orphan tx included or conflicted by block\n " , nErased);
0 commit comments