SChernykh / p2pool

Decentralized pool for Monero mining
GNU General Public License v3.0
1.03k stars 123 forks source link

Improving api reporting (json format and workers stats) #277

Closed BadTigrou closed 9 months ago

BadTigrou commented 9 months ago

First change is in api_update_local_stats to output a full json file :

Before :

{
  "connections": 157,
  "incoming_connections": 0,
  "peer_list_size": 924,
  "peers": [
    "O,481,213,P2Pool v3.2,5622783,81.178.137.127:37888",
    ...   
  ],
  "uptime": 493
}

After :

{
  "connections": 157,
  "incoming_connections": 0,
  "peer_list_size": 924,
  "peers": [
    {"type": "O", "uptime": 481, "ping": 213, "version": "P2Pool v3.2", "height": 5622783, "ip": "81.178.137.127:37888"},
    ...   
  ],
  "uptime":493}
}

Second change is in api_update_local_stats to add workers data in the stratum file

{
  "hashrate_15m": 3881,
  "hashrate_1h": 3881,
  "hashrate_24h": 3881,
  "total_hashes": 1812521,
  "shares_found": 0,
  "shares_failed": 0,
  "average_effort": 0,
  "current_effort": 2.023,
  "connections": 1,
  "incoming_connections": 1,
  "block_reward_share_percent": 0.133,
  "workers": [
    {
      "ip": "127.0.0.1:46514",
      "uptime": 238,
      "difficulty": 344333,
      "hashrate": "11.477 KH/s",
      "name": "x"
    }
  ]
}
SChernykh commented 9 months ago

json api file size is limited to 16 kB: https://github.com/SChernykh/p2pool/blob/master/src/p2pool_api.cpp#L109 So there is a reason for not having worker list (it can be thousands of workers), and for writing p2p peer list in compact form.

BadTigrou commented 9 months ago

Ok got it for the compact version and the 16 kb file size limitation. Is it problematic to increase JSON file size to 32 or even 64kb ? Combining with a compact form it should allow to logs up several thousands of workers.

SChernykh commented 9 months ago

@BadTigrou I've submitted https://github.com/SChernykh/p2pool/commit/0b544bf55aea8a46e21cfe63f3e69b29f2a04256 to fix this. Can you update your PR and keep the compact form for both P2P and Stratum?

BadTigrou commented 9 months ago

I reverted back the changes in p2p_server.ccp to keep compact format. Revert back some change in stratum_server.cpp to minimize code change.

BadTigrou commented 9 months ago

I notice an issue with the compact format for the worker : "127.0.0.1:45076,50,2501,722 H/s,z","192.168.1.2:54630,76,1000225,33.340 KH/s,y" If worker's hashrate is logged in H/s it introduce a new ',' in the worker's line. Changed to log hashrate as an integer

SChernykh commented 9 months ago

You don't need if (s.m_pos + 128 >= s.m_bufSize) check anymore. Otherwise, looks good. Also, when you're done please squash all commits into one (or open a new PR with a single commit, if you can't squash because you already merged master branch into your PR).

BadTigrou commented 9 months ago

Closing this to make a new clean pull request with a single commit. See PR https://github.com/SChernykh/p2pool/pull/278