From e13b0d27b1e3e31bf79342153bcc705d326b20b1 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Mon, 7 May 2018 22:30:12 +0200 Subject: ignore duplicated equal job from pools Some pools or proxys are sending multiple times in row the same job to the miner. This PR will extent the miner to trigger an socket error if job with the same `jobID` than the current active job is received. Move motd evaluation before the possibil part where a job is ignored. --- xmrstak/net/jpsock.cpp | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/xmrstak/net/jpsock.cpp b/xmrstak/net/jpsock.cpp index 7f7e833..08bf99f 100644 --- a/xmrstak/net/jpsock.cpp +++ b/xmrstak/net/jpsock.cpp @@ -399,18 +399,45 @@ bool jpsock::process_pool_job(const opq_json_val* params) return set_socket_error("PARSE error: Job error 2"); } + if(motd != nullptr && motd->IsString() && (motd->GetStringLength() & 0x01) == 0) + { + std::unique_lock lck(motd_mutex); + if(motd->GetStringLength() > 0) + { + pool_motd.resize(motd->GetStringLength()/2 + 1); + if(!hex2bin(motd->GetString(), motd->GetStringLength(), (unsigned char*)&pool_motd.front())) + pool_motd.clear(); + } + else + pool_motd.clear(); + } + if (jobid->GetStringLength() >= sizeof(pool_job::sJobID)) // Note >= return set_socket_error("PARSE error: Job error 3"); - uint32_t iWorkLen = blob->GetStringLength() / 2; + pool_job oPoolJob; + + const uint32_t iWorkLen = blob->GetStringLength() / 2; + oPoolJob.iWorkLen = iWorkLen; + if (iWorkLen > sizeof(pool_job::bWorkBlob)) return set_socket_error("PARSE error: Invalid job length. Are you sure you are mining the correct coin?"); - pool_job oPoolJob; if (!hex2bin(blob->GetString(), iWorkLen * 2, oPoolJob.bWorkBlob)) return set_socket_error("PARSE error: Job error 4"); - oPoolJob.iWorkLen = iWorkLen; + // lock reading of oCurrentJob + std::unique_lock jobIdLock(job_mutex); + // compare possible non equal length job id's + if(iWorkLen == oCurrentJob.iWorkLen && + memcmp(oPoolJob.bWorkBlob, oCurrentJob.bWorkBlob, iWorkLen) == 0 && + strcmp(jobid->GetString(), oCurrentJob.sJobID) == 0 + ) + { + return set_socket_error("Duplicate equal job detected! Please contact your pool admin."); + } + jobIdLock.unlock(); + memset(oPoolJob.sJobID, 0, sizeof(pool_job::sJobID)); memcpy(oPoolJob.sJobID, jobid->GetString(), jobid->GetStringLength()); //Bounds checking at proto error 3 @@ -437,19 +464,6 @@ bool jpsock::process_pool_job(const opq_json_val* params) else return set_socket_error("PARSE error: Job error 5"); - if(motd != nullptr && motd->IsString() && (motd->GetStringLength() & 0x01) == 0) - { - std::unique_lock lck(motd_mutex); - if(motd->GetStringLength() > 0) - { - pool_motd.resize(motd->GetStringLength()/2 + 1); - if(!hex2bin(motd->GetString(), motd->GetStringLength(), (unsigned char*)&pool_motd.front())) - pool_motd.clear(); - } - else - pool_motd.clear(); - } - iJobDiff = t64_to_diff(oPoolJob.iTarget); std::unique_lock lck(job_mutex); -- cgit v1.1