StratumServer: fixed data race in api update

This commit is contained in:
SChernykh 2023-09-17 22:30:21 +02:00
parent e355f45544
commit 954b9252c1

View file

@ -1337,9 +1337,8 @@ void StratumServer::api_update_local_stats(uint64_t timestamp)
const double block_reward_share_percent = m_pool->side_chain().get_reward_share(m_pool->params().m_wallet) * 100.0; const double block_reward_share_percent = m_pool->side_chain().get_reward_share(m_pool->params().m_wallet) * 100.0;
m_pool->api()->set(p2pool_api::Category::LOCAL, "stratum", CallOnLoop(&m_loop, [=]() {
[hashrate_15m, hashrate_1h, hashrate_24h, total_hashes, shares_found, shares_failed, average_effort, current_effort, connections, incoming_connections, block_reward_share_percent,timestamp, this](log::Stream& s) m_pool->api()->set(p2pool_api::Category::LOCAL, "stratum", [=](log::Stream& s) {
{
s << "{\"hashrate_15m\":" << hashrate_15m s << "{\"hashrate_15m\":" << hashrate_15m
<< ",\"hashrate_1h\":" << hashrate_1h << ",\"hashrate_1h\":" << hashrate_1h
<< ",\"hashrate_24h\":" << hashrate_24h << ",\"hashrate_24h\":" << hashrate_24h
@ -1353,13 +1352,13 @@ void StratumServer::api_update_local_stats(uint64_t timestamp)
<< ",\"block_reward_share_percent\":" << block_reward_share_percent << ",\"block_reward_share_percent\":" << block_reward_share_percent
<< ",\"workers\":["; << ",\"workers\":[";
const difficulty_type pool_diff = m_pool->side_chain().difficulty();
bool first = true; bool first = true;
for (const StratumClient* client = static_cast<StratumClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<StratumClient*>(client->m_next)) { for (const StratumClient* client = static_cast<StratumClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<StratumClient*>(client->m_next)) {
if (!first) { if (!first) {
s << ','; s << ',';
} }
const difficulty_type pool_diff = m_pool->side_chain().difficulty();
difficulty_type diff = pool_diff; difficulty_type diff = pool_diff;
if (client->m_lastJobTarget > 1) { if (client->m_lastJobTarget > 1) {
uint64_t r; uint64_t r;
@ -1377,12 +1376,12 @@ void StratumServer::api_update_local_stats(uint64_t timestamp)
<< (client->m_rpcId ? client->m_customUser : "not logged in") << (client->m_rpcId ? client->m_customUser : "not logged in")
<< '"'; << '"';
first = false; first = false;
} }
s << "]}"; s << "]}";
}); });
});
} }
} // namespace p2pool } // namespace p2pool