mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
[net processing] Move GetNodeStateStats into PeerManager
This commit is contained in:
parent
257cf05f9b
commit
a529fd3e3f
4 changed files with 21 additions and 18 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue