Skip to content

Commit 85c78d5

Browse files
committed
Add wtxid-index to orphan map
1 parent 08b3995 commit 85c78d5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct COrphanTx {
151151
};
152152
RecursiveMutex g_cs_orphans;
153153
std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
154+
std::map<uint256, std::map<uint256, COrphanTx>::iterator> g_orphans_by_wtxid GUARDED_BY(g_cs_orphans);
154155

155156
void EraseOrphansFor(NodeId peer);
156157

@@ -936,6 +937,8 @@ bool AddOrphanTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRE
936937
auto ret = mapOrphanTransactions.emplace(hash, COrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, g_orphan_list.size()});
937938
assert(ret.second);
938939
g_orphan_list.push_back(ret.first);
940+
// Allow for lookups in the orphan pool by wtxid, as well as txid
941+
g_orphans_by_wtxid.emplace(tx->GetWitnessHash(), ret.first);
939942
for (const CTxIn& txin : tx->vin) {
940943
mapOrphanTransactionsByPrev[txin.prevout].insert(ret.first);
941944
}
@@ -972,6 +975,7 @@ int static EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
972975
it_last->second.list_pos = old_pos;
973976
}
974977
g_orphan_list.pop_back();
978+
g_orphans_by_wtxid.erase(it->second.tx->GetWitnessHash());
975979

976980
mapOrphanTransactions.erase(it);
977981
return 1;
@@ -4464,6 +4468,7 @@ class CNetProcessingCleanup
44644468
// orphan transactions
44654469
mapOrphanTransactions.clear();
44664470
mapOrphanTransactionsByPrev.clear();
4471+
g_orphans_by_wtxid.clear();
44674472
}
44684473
};
44694474
static CNetProcessingCleanup instance_of_cnetprocessingcleanup;

0 commit comments

Comments
 (0)