Skip to content

Commit 606755b

Browse files
sdaftuarjnewbery
authored andcommitted
Add wtxid-index to orphan map
1 parent 3654937 commit 606755b

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
@@ -91,6 +91,7 @@ struct COrphanTx {
9191
};
9292
RecursiveMutex g_cs_orphans;
9393
std::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

9596
void 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
};
41444149
static CNetProcessingCleanup instance_of_cnetprocessingcleanup;

0 commit comments

Comments
 (0)