From 03a3423da01058dd4a19fee9905f6d29fce348c8 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 27 Feb 2023 18:58:56 +0100 Subject: [PATCH] StratumServer: fixed data race --- src/stratum_server.cpp | 8 +++++--- src/stratum_server.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index 936bb88..571db98 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -420,6 +420,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo uint64_t rem; share->m_hashes = (target > 1) ? udiv128(1, 0, target, &rem) : 1; share->m_highEnoughDifficulty = sidechain_diff.check_pow(resultHash); + share->m_score = 0; // Don't count shares that were found during sync const SideChain& side_chain = m_pool->side_chain(); @@ -884,11 +885,11 @@ void StratumServer::on_share_found(uv_work_t* req) if (pow_hash != share->m_resultHash) { LOGWARN(4, "client " << static_cast(client->m_addrString) << " submitted a share with invalid PoW"); share->m_result = SubmittedShare::Result::INVALID_POW; - client->m_score += BAD_SHARE_POINTS; + share->m_score = BAD_SHARE_POINTS; return; } - client->m_score += GOOD_SHARE_POINTS; + share->m_score = GOOD_SHARE_POINTS; const double diff = sidechain_difficulty.to_double(); { @@ -924,7 +925,7 @@ void StratumServer::on_share_found(uv_work_t* req) else { LOGWARN(4, "client " << static_cast(client->m_addrString) << " got a low diff share"); share->m_result = SubmittedShare::Result::LOW_DIFF; - client->m_score += BAD_SHARE_POINTS; + share->m_score = BAD_SHARE_POINTS; } } @@ -932,6 +933,7 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/) { SubmittedShare* share = reinterpret_cast(req->data); StratumClient* client = share->m_client; + client->m_score += share->m_score; if (share->m_highEnoughDifficulty) { const char* s = client->m_customUser; diff --git a/src/stratum_server.h b/src/stratum_server.h index e281006..7a74c50 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -154,6 +154,7 @@ private: uint64_t m_timestamp; uint64_t m_hashes; bool m_highEnoughDifficulty; + int32_t m_score; enum class Result { STALE,