Skip to content

Commit 83679ff

Browse files
committed
txorphanage: Extract HaveOrphanTx
Extract some common code into HaveOrphanTx function.
1 parent ee135c8 commit 83679ff

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,14 +1509,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
15091509

15101510
const uint256& hash = gtxid.GetHash();
15111511

1512-
{
1513-
LOCK(g_cs_orphans);
1514-
if (!gtxid.IsWtxid() && mapOrphanTransactions.count(hash)) {
1515-
return true;
1516-
} else if (gtxid.IsWtxid() && g_orphans_by_wtxid.count(hash)) {
1517-
return true;
1518-
}
1519-
}
1512+
if (HaveOrphanTx(gtxid)) return true;
15201513

15211514
{
15221515
LOCK(m_recent_confirmed_transactions_mutex);

src/txorphanage.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,13 @@ void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work
119119
}
120120
}
121121

122+
bool HaveOrphanTx(const GenTxid& gtxid)
123+
{
124+
LOCK(g_cs_orphans);
125+
if (gtxid.IsWtxid()) {
126+
return g_orphans_by_wtxid.count(gtxid.GetHash());
127+
} else {
128+
return mapOrphanTransactions.count(gtxid.GetHash());
129+
}
130+
}
131+

src/txorphanage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2727
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2828
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2929
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
30+
bool HaveOrphanTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans);
3031

3132
/** Map from txid to orphan transaction record. Limited by
3233
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */

0 commit comments

Comments
 (0)