Skip to content

Commit 7d9c3ec

Browse files
dergoeggestickies-v
authored andcommitted
[net processing] Introduce PeerManagerInfo
For querying statistics/info from PeerManager. The median outbound time offset is the only initial field.
1 parent ee178df commit 7d9c3ec

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/net_processing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ class PeerManagerImpl final : public PeerManager
518518
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
519519
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
520520
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
521+
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
521522
bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
522523
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
523524
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
@@ -1804,6 +1805,13 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
18041805
return true;
18051806
}
18061807

1808+
PeerManagerInfo PeerManagerImpl::GetInfo() const
1809+
{
1810+
return PeerManagerInfo{
1811+
.median_outbound_time_offset = m_outbound_time_offsets.Median(),
1812+
};
1813+
}
1814+
18071815
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
18081816
{
18091817
if (m_opts.max_extra_txs <= 0)

src/net_processing.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct CNodeStateStats {
4646
std::chrono::seconds time_offset{0};
4747
};
4848

49+
struct PeerManagerInfo {
50+
std::chrono::seconds median_outbound_time_offset{0s};
51+
};
52+
4953
class PeerManager : public CValidationInterface, public NetEventsInterface
5054
{
5155
public:
@@ -86,6 +90,9 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
8690
/** Get statistics from node state */
8791
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
8892

93+
/** Get peer manager info. */
94+
virtual PeerManagerInfo GetInfo() const = 0;
95+
8996
/** Whether this node ignores txs received over p2p. */
9097
virtual bool IgnoresIncomingTxs() = 0;
9198

src/rpc/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <rpc/server_util.h>
2424
#include <rpc/util.h>
2525
#include <sync.h>
26-
#include <timedata.h>
2726
#include <util/chaintype.h>
2827
#include <util/strencodings.h>
2928
#include <util/string.h>
@@ -679,9 +678,10 @@ static RPCHelpMan getnetworkinfo()
679678
obj.pushKV("localservicesnames", GetServicesNames(services));
680679
}
681680
if (node.peerman) {
681+
auto peerman_info{node.peerman->GetInfo()};
682682
obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
683+
obj.pushKV("timeoffset", Ticks<std::chrono::seconds>(peerman_info.median_outbound_time_offset));
683684
}
684-
obj.pushKV("timeoffset", GetTimeOffset());
685685
if (node.connman) {
686686
obj.pushKV("networkactive", node.connman->GetNetworkActive());
687687
obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both));

0 commit comments

Comments
 (0)