From 83679ffc600305ec0926fd195ee31c11de2ed613 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 31 Jan 2021 21:24:08 +1000 Subject: [PATCH] txorphanage: Extract HaveOrphanTx Extract some common code into HaveOrphanTx function. --- src/net_processing.cpp | 9 +-------- src/txorphanage.cpp | 10 ++++++++++ src/txorphanage.h | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 181e64c77e7..cda177dfe39 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1509,14 +1509,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid) const uint256& hash = gtxid.GetHash(); - { - LOCK(g_cs_orphans); - if (!gtxid.IsWtxid() && mapOrphanTransactions.count(hash)) { - return true; - } else if (gtxid.IsWtxid() && g_orphans_by_wtxid.count(hash)) { - return true; - } - } + if (HaveOrphanTx(gtxid)) return true; { LOCK(m_recent_confirmed_transactions_mutex); diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp index c1443115f0c..473abd50445 100644 --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -119,3 +119,13 @@ void AddChildrenToWorkSet(const CTransaction& tx, std::set& orphan_work } } +bool HaveOrphanTx(const GenTxid& gtxid) +{ + LOCK(g_cs_orphans); + if (gtxid.IsWtxid()) { + return g_orphans_by_wtxid.count(gtxid.GetHash()); + } else { + return mapOrphanTransactions.count(gtxid.GetHash()); + } +} + diff --git a/src/txorphanage.h b/src/txorphanage.h index c57249265e7..ab4960be693 100644 --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -27,6 +27,7 @@ int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); void AddChildrenToWorkSet(const CTransaction& tx, std::set& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); +bool HaveOrphanTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans); /** Map from txid to orphan transaction record. Limited by * -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */