Skip to content

Commit 46cd87c

Browse files
committed
fix: /rate, /users, /p2pool_global_stats return correct sharechain data for MiningPoolStats
- /rate now returns pool hashrate from sharechain (was returning 0.0) - /users now returns unique miners from sharechain (was returning 0) - /p2pool_global_stats delegates to rest_global_stats() for consistent data - Dashboard unaffected (uses /global_stats and /local_stats directly)
1 parent e014bbf commit 46cd87c

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

src/core/web_server.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,15 @@ nlohmann::json MiningInterface::rest_current_payouts()
28892889

28902890
nlohmann::json MiningInterface::rest_users()
28912891
{
2892+
// Prefer sharechain unique miners count (matches /global_stats)
2893+
if (m_sharechain_stats_fn) {
2894+
auto sc = m_sharechain_stats_fn();
2895+
if (sc.contains("shares_by_miner") && sc["shares_by_miner"].is_object()) {
2896+
int count = static_cast<int>(sc["shares_by_miner"].size());
2897+
if (count > 0) return nlohmann::json(count);
2898+
}
2899+
}
2900+
// Fallback to payout manager
28922901
auto* pm = m_payout_manager_ptr ? m_payout_manager_ptr : m_payout_manager.get();
28932902
return pm ? nlohmann::json(pm->get_active_miners_count()) : nlohmann::json(0);
28942903
}
@@ -4180,17 +4189,15 @@ nlohmann::json MiningInterface::rest_local_stats()
41804189

41814190
nlohmann::json MiningInterface::rest_p2pool_global_stats()
41824191
{
4183-
// Original p2pool /global_stats shape
4192+
// Original p2pool /global_stats shape — delegate to full implementation
4193+
auto full = rest_global_stats();
41844194
nlohmann::json result = nlohmann::json::object();
4185-
double pool_rate = 0.0;
4186-
if (m_node) {
4187-
auto hs = m_node->get_hashrate_stats();
4188-
if (hs.contains("global_hashrate"))
4189-
pool_rate = hs["global_hashrate"];
4190-
}
4191-
result["pool_hash_rate"] = pool_rate;
4192-
result["pool_stale_prop"] = 0.0;
4193-
result["min_difficulty"] = 1.0;
4195+
result["pool_hash_rate"] = full.value("pool_hash_rate", 0.0);
4196+
result["pool_stale_prop"] = full.value("pool_stale_prop", 0.0);
4197+
result["min_difficulty"] = full.value("min_difficulty", 1.0);
4198+
result["pool_nonstale_hash_rate"] = full.value("pool_nonstale_hash_rate", 0.0);
4199+
result["network_block_difficulty"] = full.value("network_block_difficulty", 0.0);
4200+
result["network_hashrate"] = full.value("network_hashrate", 0.0);
41944201
return result;
41954202
}
41964203

@@ -4367,6 +4374,12 @@ std::string MiningInterface::rest_logs_export(const std::string& scope,
43674374

43684375
nlohmann::json MiningInterface::rest_rate()
43694376
{
4377+
// Use sharechain-based pool hashrate (same source as /global_stats)
4378+
if (m_pool_hashrate_fn) {
4379+
double hr = m_pool_hashrate_fn();
4380+
if (hr > 0) return hr;
4381+
}
4382+
// Fallback to node hashrate tracker
43704383
double rate = 0.0;
43714384
if (m_node) {
43724385
auto hs = m_node->get_hashrate_stats();

0 commit comments

Comments
 (0)