net: add GetOrphanTransactions() to PeerManager

Updates PeerManager (and Impl) to provide
orphans with metadata
This commit is contained in:
tdb3 2024-09-18 12:28:04 -04:00
parent 91b65adff2
commit 532491faf1
No known key found for this signature in database
4 changed files with 22 additions and 0 deletions

View file

@ -515,6 +515,7 @@ public:
std::optional<std::string> 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<TxOrphanage::OrphanTxBase> 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<TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
{
LOCK(m_tx_download_mutex);
return m_orphanage.GetOrphanTransactions();
}
PeerManagerInfo PeerManagerImpl::GetInfo() const
{
return PeerManagerInfo{

View file

@ -7,6 +7,7 @@
#define BITCOIN_NET_PROCESSING_H
#include <net.h>
#include <txorphanage.h>
#include <validationinterface.h>
#include <chrono>
@ -99,6 +100,8 @@ public:
/** Get statistics from node state */
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
virtual std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() = 0;
/** Get peer manager info. */
virtual PeerManagerInfo GetInfo() const = 0;

View file

@ -277,3 +277,13 @@ std::vector<std::pair<CTransactionRef, NodeId>> TxOrphanage::GetChildrenFromDiff
}
return children_found;
}
std::vector<TxOrphanage::OrphanTxBase> TxOrphanage::GetOrphanTransactions() const
{
std::vector<OrphanTxBase> 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;
}

View file

@ -79,6 +79,8 @@ public:
NodeSeconds nTimeExpire;
};
std::vector<OrphanTxBase> GetOrphanTransactions() const;
protected:
struct OrphanTx : public OrphanTxBase {
size_t list_pos;