mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 05:57:59 +01:00
[net processing] Introduce PeerManagerInfo
For querying statistics/info from PeerManager. The median outbound time offset is the only initial field.
This commit is contained in:
@@ -518,6 +518,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);
|
||||
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);
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
@@ -86,6 +90,9 @@ public:
|
||||
/** 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;
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user