summaryrefslogtreecommitdiffstats
path: root/xmrstak/net/jpsock.cpp
diff options
context:
space:
mode:
authorpsychocrypt <psychocryptHPC@gmail.com>2018-05-07 22:30:12 +0200
committerpsychocrypt <psychocryptHPC@gmail.com>2018-05-09 20:59:27 +0200
commitc263be5bc4e3d6497cc08d898a70ce8be308e296 (patch)
treed9215c93e5e356dd5732dcfb570a5abbeb148bf1 /xmrstak/net/jpsock.cpp
parent1a7e695f8b71f644b9840e778039229ce393f75c (diff)
downloadxmr-stak-c263be5bc4e3d6497cc08d898a70ce8be308e296.zip
xmr-stak-c263be5bc4e3d6497cc08d898a70ce8be308e296.tar.gz
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.
Diffstat (limited to 'xmrstak/net/jpsock.cpp')
-rw-r--r--xmrstak/net/jpsock.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/xmrstak/net/jpsock.cpp b/xmrstak/net/jpsock.cpp
index f9217c5..7864182 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<std::mutex> 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<std::mutex> 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<std::mutex> 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);
executor::inst()->push_event(ex_event(oPoolJob, pool_id));
OpenPOWER on IntegriCloud