From 532491faf1aa90053af52cbedce403b9eccf0bc3 Mon Sep 17 00:00:00 2001 From: tdb3 <106488469+tdb3@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:28:04 -0400 Subject: [PATCH] net: add GetOrphanTransactions() to PeerManager Updates PeerManager (and Impl) to provide orphans with metadata --- src/net_processing.cpp | 7 +++++++ src/net_processing.h | 3 +++ src/txorphanage.cpp | 10 ++++++++++ src/txorphanage.h | 2 ++ 4 files changed, 22 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index b7d0f5360de..be16884011e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -515,6 +515,7 @@ public: std::optional FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + std::vector GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); @@ -1917,6 +1918,12 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c return true; } +std::vector PeerManagerImpl::GetOrphanTransactions() +{ + LOCK(m_tx_download_mutex); + return m_orphanage.GetOrphanTransactions(); +} + PeerManagerInfo PeerManagerImpl::GetInfo() const { return PeerManagerInfo{ diff --git a/src/net_processing.h b/src/net_processing.h index ccacd15e422..0d2dc59c5ae 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -7,6 +7,7 @@ #define BITCOIN_NET_PROCESSING_H #include +#include #include #include @@ -99,6 +100,8 @@ public: /** Get statistics from node state */ virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; + virtual std::vector GetOrphanTransactions() = 0; + /** Get peer manager info. */ virtual PeerManagerInfo GetInfo() const = 0; diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp index 35cf26a7be1..ba4ba6c3b62 100644 --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -277,3 +277,13 @@ std::vector> TxOrphanage::GetChildrenFromDiff } return children_found; } + +std::vector TxOrphanage::GetOrphanTransactions() const +{ + std::vector ret; + ret.reserve(m_orphans.size()); + for (auto const& o : m_orphans) { + ret.push_back({o.second.tx, o.second.fromPeer, o.second.nTimeExpire}); + } + return ret; +} diff --git a/src/txorphanage.h b/src/txorphanage.h index 5123bfe8678..5501d109228 100644 --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -79,6 +79,8 @@ public: NodeSeconds nTimeExpire; }; + std::vector GetOrphanTransactions() const; + protected: struct OrphanTx : public OrphanTxBase { size_t list_pos;