summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpsychocrypt <psychocryptHPC@gmail.com>2018-05-07 22:30:12 +0200
committerTimothy Pearson <tpearson@raptorengineering.com>2018-06-04 21:07:11 +0000
commite13b0d27b1e3e31bf79342153bcc705d326b20b1 (patch)
tree35a6c5c95b1e02d1f5f457b7ff737330ae2b495a
parentdac939f4fa5e0f625fa7ebf8fc738bf5c4e66920 (diff)
downloadxmr-stak-e13b0d27b1e3e31bf79342153bcc705d326b20b1.zip
xmr-stak-e13b0d27b1e3e31bf79342153bcc705d326b20b1.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.
-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 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<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);
std::unique_lock<std::mutex> lck(job_mutex);
OpenPOWER on IntegriCloud