Skip to content

Commit 532491f

Browse files
committed
net: add GetOrphanTransactions() to PeerManager
Updates PeerManager (and Impl) to provide orphans with metadata
1 parent 91b65ad commit 532491f

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/net_processing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ class PeerManagerImpl final : public PeerManager
515515
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
516516
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
517517
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
518+
std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
518519
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
519520
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
520521
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
19171918
return true;
19181919
}
19191920

1921+
std::vector<TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
1922+
{
1923+
LOCK(m_tx_download_mutex);
1924+
return m_orphanage.GetOrphanTransactions();
1925+
}
1926+
19201927
PeerManagerInfo PeerManagerImpl::GetInfo() const
19211928
{
19221929
return PeerManagerInfo{

src/net_processing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define BITCOIN_NET_PROCESSING_H
88

99
#include <net.h>
10+
#include <txorphanage.h>
1011
#include <validationinterface.h>
1112

1213
#include <chrono>
@@ -99,6 +100,8 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
99100
/** Get statistics from node state */
100101
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
101102

103+
virtual std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() = 0;
104+
102105
/** Get peer manager info. */
103106
virtual PeerManagerInfo GetInfo() const = 0;
104107

src/txorphanage.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,13 @@ std::vector<std::pair<CTransactionRef, NodeId>> TxOrphanage::GetChildrenFromDiff
277277
}
278278
return children_found;
279279
}
280+
281+
std::vector<TxOrphanage::OrphanTxBase> TxOrphanage::GetOrphanTransactions() const
282+
{
283+
std::vector<OrphanTxBase> ret;
284+
ret.reserve(m_orphans.size());
285+
for (auto const& o : m_orphans) {
286+
ret.push_back({o.second.tx, o.second.fromPeer, o.second.nTimeExpire});
287+
}
288+
return ret;
289+
}

src/txorphanage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class TxOrphanage {
7979
NodeSeconds nTimeExpire;
8080
};
8181

82+
std::vector<OrphanTxBase> GetOrphanTransactions() const;
83+
8284
protected:
8385
struct OrphanTx : public OrphanTxBase {
8486
size_t list_pos;

0 commit comments

Comments
 (0)