diff options
author | John Newbery <john@johnnewbery.com> | 2020-08-24 17:39:54 +0100 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2020-12-04 11:37:45 +0000 |
commit | a529fd3e3f2391e592ac937e291fec51e067ea2e (patch) | |
tree | eafa7eadf6bfe611afe40a3bb8d325cbef602c18 /src | |
parent | 257cf05f9b841ba30202f23a94bcdb1743feded2 (diff) | |
download | bitcoin-a529fd3e3f2391e592ac937e291fec51e067ea2e.tar.xz |
[net processing] Move GetNodeStateStats into PeerManager
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 2 | ||||
-rw-r--r-- | src/net_processing.h | 20 | ||||
-rw-r--r-- | src/node/interfaces.cpp | 12 | ||||
-rw-r--r-- | src/rpc/net.cpp | 5 |
4 files changed, 21 insertions, 18 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ec5400c3d8..d65b066dbd 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -887,7 +887,7 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) { LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); } -bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { +bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { { LOCK(cs_main); CNodeState* state = State(nodeid); diff --git a/src/net_processing.h b/src/net_processing.h index 87eee566de..8f4ba4c0bb 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -32,6 +32,13 @@ static const bool DEFAULT_PEERBLOCKFILTERS = false; /** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */ static const int DISCOURAGEMENT_THRESHOLD{100}; +struct CNodeStateStats { + int m_misbehavior_score = 0; + int nSyncHeight = -1; + int nCommonHeight = -1; + std::vector<int> vHeightInFlight; +}; + class PeerManager final : public CValidationInterface, public NetEventsInterface { public: PeerManager(const CChainParams& chainparams, CConnman& connman, BanMan* banman, @@ -94,6 +101,9 @@ public: */ void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message); + /** Get statistics from node state */ + bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats); + private: /** * Potentially mark a node discouraged based on the contents of a BlockValidationState object @@ -145,16 +155,6 @@ private: int64_t m_stale_tip_check_time; //!< Next time to check for stale tip }; -struct CNodeStateStats { - int m_misbehavior_score = 0; - int nSyncHeight = -1; - int nCommonHeight = -1; - std::vector<int> vHeightInFlight; -}; - -/** Get statistics from node state */ -bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); - /** Relay transaction to every node */ void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main); diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index a8c8be05fb..3c315c0a53 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -121,11 +121,13 @@ public: } // Try to retrieve the CNodeStateStats for each node. - TRY_LOCK(::cs_main, lockMain); - if (lockMain) { - for (auto& node_stats : stats) { - std::get<1>(node_stats) = - GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats)); + if (m_context->peerman) { + TRY_LOCK(::cs_main, lockMain); + if (lockMain) { + for (auto& node_stats : stats) { + std::get<1>(node_stats) = + m_context->peerman->GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats)); + } } } return true; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index e72ef24d12..fa71ea1181 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -165,8 +165,9 @@ static RPCHelpMan getpeerinfo() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { NodeContext& node = EnsureNodeContext(request.context); - if(!node.connman) + if(!node.connman || !node.peerman) { throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); + } std::vector<CNodeStats> vstats; node.connman->GetNodeStats(vstats); @@ -176,7 +177,7 @@ static RPCHelpMan getpeerinfo() for (const CNodeStats& stats : vstats) { UniValue obj(UniValue::VOBJ); CNodeStateStats statestats; - bool fStateStats = GetNodeStateStats(stats.nodeid, statestats); + bool fStateStats = node.peerman->GetNodeStateStats(stats.nodeid, statestats); obj.pushKV("id", stats.nodeid); obj.pushKV("addr", stats.addrName); if (stats.addrBind.IsValid()) { |