Skip to content

Commit

Permalink
[net processing] Introduce PeerManagerInfo
Browse files Browse the repository at this point in the history
For querying statistics/info from PeerManager. The median outbound time
offset is the only initial field.
  • Loading branch information
dergoegge authored and stickies-v committed Apr 10, 2024
1 parent ee178df commit 7d9c3ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ class PeerManagerImpl final : public PeerManager
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);
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
Expand Down Expand Up @@ -1804,6 +1805,13 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
return true;
}

PeerManagerInfo PeerManagerImpl::GetInfo() const
{
return PeerManagerInfo{
.median_outbound_time_offset = m_outbound_time_offsets.Median(),
};
}

void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
{
if (m_opts.max_extra_txs <= 0)
Expand Down
7 changes: 7 additions & 0 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct CNodeStateStats {
std::chrono::seconds time_offset{0};
};

struct PeerManagerInfo {
std::chrono::seconds median_outbound_time_offset{0s};
};

class PeerManager : public CValidationInterface, public NetEventsInterface
{
public:
Expand Down Expand Up @@ -86,6 +90,9 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
/** Get statistics from node state */
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;

/** Get peer manager info. */
virtual PeerManagerInfo GetInfo() const = 0;

/** Whether this node ignores txs received over p2p. */
virtual bool IgnoresIncomingTxs() = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <rpc/server_util.h>
#include <rpc/util.h>
#include <sync.h>
#include <timedata.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <util/string.h>
Expand Down Expand Up @@ -679,9 +678,10 @@ static RPCHelpMan getnetworkinfo()
obj.pushKV("localservicesnames", GetServicesNames(services));
}
if (node.peerman) {
auto peerman_info{node.peerman->GetInfo()};
obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
obj.pushKV("timeoffset", Ticks<std::chrono::seconds>(peerman_info.median_outbound_time_offset));
}
obj.pushKV("timeoffset", GetTimeOffset());
if (node.connman) {
obj.pushKV("networkactive", node.connman->GetNetworkActive());
obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both));
Expand Down

0 comments on commit 7d9c3ec

Please sign in to comment.