From 49815aba194d346c4e0079382ed9381213d7dc6d Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Fri, 1 Mar 2024 14:56:00 -0500 Subject: [PATCH] rpc/net: Adds misbehaving_score to getpeerinfo Github-Pull: #29530 Rebased-From: 976d61c974ed045c2e2497dcebc4d1fcc4d60a29 --- src/net_processing.cpp | 1 + src/net_processing.h | 1 + src/rpc/net.cpp | 3 +++ test/functional/rpc_net.py | 1 + 4 files changed, 6 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 3bfb606037..9d1b46e4f9 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1709,6 +1709,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c stats.presync_height = peer->m_headers_sync->GetPresyncHeight(); } } + stats.m_misbehavior_score = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score); return true; } diff --git a/src/net_processing.h b/src/net_processing.h index 80d07648a4..f396dbce80 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -41,6 +41,7 @@ struct CNodeStateStats { bool m_addr_relay_enabled{false}; ServiceFlags their_services; int64_t presync_height{-1}; + int m_misbehavior_score{0}; }; class PeerManager : public CValidationInterface, public NetEventsInterface diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 63788c3a03..8aaaac1ad8 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -173,6 +173,8 @@ static RPCHelpMan getpeerinfo() "best capture connection behaviors."}, {RPCResult::Type::STR, "transport_protocol_type", "Type of transport protocol: \n" + Join(TRANSPORT_TYPE_DOC, ",\n") + ".\n"}, {RPCResult::Type::STR, "session_id", "The session ID for this connection, or \"\" if there is none (\"v2\" transport protocol only).\n"}, + {RPCResult::Type::NUM, "misbehavior_score", "The accumulated misbehavior score for this peer.\n" + "The peer will be disconnected if 100 is reached.\n"}, }}, }}, }, @@ -279,6 +281,7 @@ static RPCHelpMan getpeerinfo() obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type)); obj.pushKV("transport_protocol_type", TransportTypeAsString(stats.m_transport_type)); obj.pushKV("session_id", stats.m_session_id); + obj.pushKV("misbehavior_score", statestats.m_misbehavior_score); ret.push_back(obj); } diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 50a022fc7e..2e367651da 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -152,6 +152,7 @@ class NetTest(BitcoinTestFramework): "timeoffset": 0, "transport_protocol_type": "v1", "version": 0, + "misbehavior_score": 0, }, ) no_version_peer.peer_disconnect()