Skip to content

Commit

Permalink
rpc/net: Adds misbehaving_score to getpeerinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-gi committed Mar 1, 2024
1 parent 8da62a1 commit 020a8ef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,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;
}
Expand Down
1 change: 1 addition & 0 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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"},
}},
}},
},
Expand Down Expand Up @@ -292,6 +294,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);
}
Expand Down

0 comments on commit 020a8ef

Please sign in to comment.