@@ -91,6 +91,7 @@ struct COrphanTx {
9191};
9292RecursiveMutex g_cs_orphans;
9393std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY (g_cs_orphans);
94+ std::map<uint256, std::map<uint256, COrphanTx>::iterator> g_orphans_by_wtxid GUARDED_BY (g_cs_orphans);
9495
9596void EraseOrphansFor (NodeId peer);
9697
@@ -868,6 +869,8 @@ bool AddOrphanTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRE
868869 auto ret = mapOrphanTransactions.emplace (hash, COrphanTx{tx, peer, GetTime () + ORPHAN_TX_EXPIRE_TIME, g_orphan_list.size ()});
869870 assert (ret.second );
870871 g_orphan_list.push_back (ret.first );
872+ // Allow for lookups in the orphan pool by wtxid, as well as txid
873+ g_orphans_by_wtxid.emplace (tx->GetWitnessHash (), ret.first );
871874 for (const CTxIn& txin : tx->vin ) {
872875 mapOrphanTransactionsByPrev[txin.prevout ].insert (ret.first );
873876 }
@@ -904,6 +907,7 @@ int static EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
904907 it_last->second .list_pos = old_pos;
905908 }
906909 g_orphan_list.pop_back ();
910+ g_orphans_by_wtxid.erase (it->second .tx ->GetWitnessHash ());
907911
908912 mapOrphanTransactions.erase (it);
909913 return 1 ;
@@ -4139,6 +4143,7 @@ class CNetProcessingCleanup
41394143 // orphan transactions
41404144 mapOrphanTransactions.clear ();
41414145 mapOrphanTransactionsByPrev.clear ();
4146+ g_orphans_by_wtxid.clear ();
41424147 }
41434148};
41444149static CNetProcessingCleanup instance_of_cnetprocessingcleanup;
0 commit comments