MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetNodeStateStats

Method GetNodeStateStats

src/net_processing.cpp:1311–1346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1309}
1310
1311bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const
1312{
1313 {
1314 LOCK(cs_main);
1315 CNodeState* state = State(nodeid);
1316 if (state == nullptr)
1317 return false;
1318 stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
1319 stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
1320 for (const QueuedBlock& queue : state->vBlocksInFlight) {
1321 if (queue.pindex)
1322 stats.vHeightInFlight.push_back(queue.pindex->nHeight);
1323 }
1324 }
1325
1326 PeerRef peer = GetPeerRef(nodeid);
1327 if (peer == nullptr) return false;
1328 stats.m_starting_height = peer->m_starting_height;
1329 // It is common for nodes with good ping times to suddenly become lagged,
1330 // due to a new block arriving or other large transfer.
1331 // Merely reporting pingtime might fool the caller into thinking the node was still responsive,
1332 // since pingtime does not update until the ping is complete, which might take a while.
1333 // So, if a ping is taking an unusually long time in flight,
1334 // the caller can immediately detect that this is happening.
1335 auto ping_wait{0us};
1336 if ((0 != peer->m_ping_nonce_sent) && (0 != peer->m_ping_start.load().count())) {
1337 ping_wait = GetTime<std::chrono::microseconds>() - peer->m_ping_start.load();
1338 }
1339
1340 stats.m_ping_wait = ping_wait;
1341 stats.m_addr_processed = peer->m_addr_processed.load();
1342 stats.m_addr_rate_limited = peer->m_addr_rate_limited.load();
1343 stats.m_addr_relay_enabled = peer->m_addr_relay_enabled.load();
1344
1345 return true;
1346}
1347
1348void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
1349{

Callers 2

getpeerinfoFunction · 0.80
getNodesStatsMethod · 0.80

Calls 4

countMethod · 0.80
StateEnum · 0.70
push_backMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected