summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfireice-uk <fireice2@o2.pl>2017-02-07 22:54:59 +0000
committerfireice-uk <fireice2@o2.pl>2017-02-07 22:54:59 +0000
commit2078969378be6cc08c15ae08660db84688b1493e (patch)
tree5b6a88bc68fdf277c8645a8bcbb4415f2e5a46c6
parentbdad7f566292b07d9cd578c62ac509c817e043cf (diff)
downloadxmr-stak-2078969378be6cc08c15ae08660db84688b1493e.zip
xmr-stak-2078969378be6cc08c15ae08660db84688b1493e.tar.gz
NiceHash support
-rw-r--r--config.txt8
-rw-r--r--executor.cpp7
-rw-r--r--jconf.cpp8
-rw-r--r--jconf.h2
-rw-r--r--minethd.cpp10
-rw-r--r--minethd.h11
6 files changed, 39 insertions, 7 deletions
diff --git a/config.txt b/config.txt
index 23f5dc3..4b55989 100644
--- a/config.txt
+++ b/config.txt
@@ -70,6 +70,14 @@
"use_slow_memory" : "warn",
/*
+ * NiceHash mode
+ * nicehash_nonce - Limit the noce to 3 bytes as required by nicehash. This cuts all the safety margins, and
+ * if a block isn't found within 30 minutes then you might run into nonce collisions. Number
+ * of threads in this mode is hard-limited to 32.
+ */
+"nicehash_nonce" : false,
+
+/*
* pool_address - Pool address should be in the form "pool.supportxmr.com:3333". Only stratum pools are supported.
* wallet_address - Your wallet, or pool login.
* pool_password - Can be empty in most cases or "x".
diff --git a/executor.cpp b/executor.cpp
index 016ac57..92e1baa 100644
--- a/executor.cpp
+++ b/executor.cpp
@@ -210,7 +210,9 @@ void executor::on_pool_have_job(size_t pool_id, pool_job& oPoolJob)
jpsock* pool = pick_pool_by_id(pool_id);
minethd::miner_work oWork(oPoolJob.sJobID, oPoolJob.bWorkBlob,
- oPoolJob.iWorkLen, oPoolJob.iResumeCnt, oPoolJob.iTarget, pool_id);
+ oPoolJob.iWorkLen, oPoolJob.iResumeCnt, oPoolJob.iTarget,
+ (pool_id != dev_pool_id) ? jconf::inst()->NiceHashMode() : false,
+ pool_id);
minethd::switch_work(oWork);
@@ -328,7 +330,8 @@ void executor::on_switch_pool(size_t pool_id)
}
minethd::miner_work oWork(oPoolJob.sJobID, oPoolJob.bWorkBlob,
- oPoolJob.iWorkLen, oPoolJob.iResumeCnt, oPoolJob.iTarget, pool_id);
+ oPoolJob.iWorkLen, oPoolJob.iResumeCnt, oPoolJob.iTarget,
+ jconf::inst()->NiceHashMode(), pool_id);
minethd::switch_work(oWork);
diff --git a/jconf.cpp b/jconf.cpp
index a944075..ee501fa 100644
--- a/jconf.cpp
+++ b/jconf.cpp
@@ -37,7 +37,7 @@ using namespace rapidjson;
/*
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
*/
-enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, sPoolAddr, sWalletAddr,
+enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode, sPoolAddr, sWalletAddr,
sPoolPwd, iCallTimeout, iNetRetry, iVerboseLevel, iAutohashTime, iHttpdPort, bPreferIpv4 };
struct configVal {
@@ -51,6 +51,7 @@ configVal oConfigValues[] = {
{ iCpuThreadNum, "cpu_thread_num", kNumberType },
{ aCpuThreadsConf, "cpu_threads_conf", kArrayType },
{ sUseSlowMem, "use_slow_memory", kStringType },
+ { bNiceHashMode, "nicehash_nonce", kTrueType },
{ sPoolAddr, "pool_address", kStringType },
{ sWalletAddr, "wallet_address", kStringType },
{ sPoolPwd, "pool_password", kStringType },
@@ -203,6 +204,11 @@ uint16_t jconf::GetHttpdPort()
return prv->configValues[iHttpdPort]->GetUint();
}
+bool jconf::NiceHashMode()
+{
+ return prv->configValues[bNiceHashMode]->GetBool();
+}
+
bool jconf::check_cpu_features()
{
constexpr int AESNI_BIT = 1 << 25;
diff --git a/jconf.h b/jconf.h
index 73f6870..e756d34 100644
--- a/jconf.h
+++ b/jconf.h
@@ -44,6 +44,8 @@ public:
uint16_t GetHttpdPort();
+ bool NiceHashMode();
+
bool PreferIpv4();
inline bool HaveHardwareAes() { return bHaveAes; }
diff --git a/minethd.cpp b/minethd.cpp
index ca9a852..641ef02 100644
--- a/minethd.cpp
+++ b/minethd.cpp
@@ -350,7 +350,10 @@ void minethd::work_main()
continue;
}
- result.iNonce = calc_start_nonce(oWork.iResumeCnt);
+ if(oWork.bNiceHash)
+ result.iNonce = calc_nicehash_nonce(*piNonce, oWork.iResumeCnt);
+ else
+ result.iNonce = calc_start_nonce(oWork.iResumeCnt);
assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID));
memcpy(result.sJobID, oWork.sJobID, sizeof(job_result::sJobID));
@@ -430,7 +433,10 @@ void minethd::double_work_main()
continue;
}
- iNonce = calc_start_nonce(oWork.iResumeCnt);
+ if(oWork.bNiceHash)
+ iNonce = calc_nicehash_nonce(*piNonce0, oWork.iResumeCnt);
+ else
+ iNonce = calc_start_nonce(oWork.iResumeCnt);
assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID));
diff --git a/minethd.h b/minethd.h
index 6d6104f..d4470b1 100644
--- a/minethd.h
+++ b/minethd.h
@@ -27,14 +27,15 @@ public:
uint32_t iWorkSize;
uint32_t iResumeCnt;
uint64_t iTarget;
+ bool bNiceHash;
bool bStall;
size_t iPoolId;
miner_work() : iWorkSize(0), bStall(true), iPoolId(0) { }
miner_work(const char* sJobID, const uint8_t* bWork, uint32_t iWorkSize, uint32_t iResumeCnt,
- uint64_t iTarget, size_t iPoolId) : iWorkSize(iWorkSize), iResumeCnt(iResumeCnt),
- iTarget(iTarget), bStall(false), iPoolId(iPoolId)
+ uint64_t iTarget, bool bNiceHash, size_t iPoolId) : iWorkSize(iWorkSize), iResumeCnt(iResumeCnt),
+ iTarget(iTarget), bNiceHash(bNiceHash), bStall(false), iPoolId(iPoolId)
{
assert(iWorkSize <= sizeof(bWorkBlob));
memcpy(this->sJobID, sJobID, sizeof(miner_work::sJobID));
@@ -50,6 +51,7 @@ public:
iWorkSize = from.iWorkSize;
iResumeCnt = from.iResumeCnt;
iTarget = from.iTarget;
+ bNiceHash = from.bNiceHash;
bStall = from.bStall;
iPoolId = from.iPoolId;
@@ -75,6 +77,7 @@ public:
iWorkSize = from.iWorkSize;
iResumeCnt = from.iResumeCnt;
iTarget = from.iTarget;
+ bNiceHash = from.bNiceHash;
bStall = from.bStall;
iPoolId = from.iPoolId;
@@ -103,6 +106,10 @@ private:
inline uint32_t calc_start_nonce(uint32_t resume)
{ return (resume * iThreadCount + iThreadNo) << 22; }
+ // Limited version of the nonce calc above
+ inline uint32_t calc_nicehash_nonce(uint32_t start, uint32_t resume)
+ { return start | (resume * iThreadCount + iThreadNo) << 18; }
+
void work_main();
void double_work_main();
void consume_work();
OpenPOWER on IntegriCloud