Skip to content

Commit 9996a1e

Browse files
committed
rpc/net: Adds misbehaving_score to getpeerinfo
Github-Pull: bitcoin#29530 Rebased-From: 976d61c
1 parent 1248d0d commit 9996a1e

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
19141914
}
19151915
}
19161916
stats.time_offset = peer->m_time_offset;
1917+
stats.m_misbehavior_score = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_should_discourage) ? 100 : 0;
19171918

19181919
return true;
19191920
}

src/net_processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct CNodeStateStats {
4646
ServiceFlags their_services;
4747
int64_t presync_height{-1};
4848
std::chrono::seconds time_offset{0};
49+
int m_misbehavior_score{0};
4950
};
5051

5152
struct PeerManagerInfo {

src/rpc/net.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ static RPCHelpMan getpeerinfo()
187187
"best capture connection behaviors."},
188188
{RPCResult::Type::STR, "transport_protocol_type", "Type of transport protocol: \n" + Join(TRANSPORT_TYPE_DOC, ",\n") + ".\n"},
189189
{RPCResult::Type::STR, "session_id", "The session ID for this connection, or \"\" if there is none (\"v2\" transport protocol only).\n"},
190+
{RPCResult::Type::NUM, "misbehavior_score", "The accumulated misbehavior score for this peer.\n"
191+
"The peer will be disconnected if 100 is reached.\n"},
190192
}},
191193
}},
192194
},
@@ -293,6 +295,7 @@ static RPCHelpMan getpeerinfo()
293295
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
294296
obj.pushKV("transport_protocol_type", TransportTypeAsString(stats.m_transport_type));
295297
obj.pushKV("session_id", stats.m_session_id);
298+
obj.pushKV("misbehavior_score", statestats.m_misbehavior_score);
296299

297300
ret.push_back(std::move(obj));
298301
}

test/functional/rpc_net.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def test_getpeerinfo(self):
173173
"timeoffset": 0,
174174
"transport_protocol_type": "v1" if not self.options.v2transport else "v2",
175175
"version": 0,
176+
"misbehavior_score": 0,
176177
},
177178
)
178179
no_version_peer.peer_disconnect()

0 commit comments

Comments
 (0)