Skip to content

Commit e7f43e3

Browse files
miner auto-selects difficulty
1 parent 595a9bb commit e7f43e3

File tree

6 files changed

+85
-23
lines changed

6 files changed

+85
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cmake global
22
cmake_minimum_required(VERSION 2.8.12)
33

4-
set(PROJECT_VERSION "2.1.5")
4+
set(PROJECT_VERSION "2.1.6")
55
if (${CMAKE_VERSION} VERSION_GREATER 3.0)
66
cmake_policy(SET CMP0042 OLD) # fix MACOSX_RPATH
77
cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project()

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ Node configuration:
7575
#### INI File Settings
7676

7777
```
78-
79-
8078
[General]
8179
8280
;--------------------------------------------------------
@@ -109,9 +107,9 @@ RPCPort=
109107
[0xBitcoin]
110108
111109
; POOL MINING: Your ETH account, to which payouts will be made. THE PRIVATE
112-
; KEY IS NOT REQUIRED.
113-
; SOLO MINING: Your ETH account and private key. Note the acct starts with 0x, but
114-
; not the PK. Mining rewards will be deposited to this account. Transaction
110+
; KEY IS NOT REQUIRED. Note the acct should start with 0x.
111+
; SOLO MINING: Your ETH account and private key. Note the PK does NOT start
112+
; with 0x. Mining rewards will be deposited to this account. Transaction
115113
; fees will be DRAWN from this account. Make sure you have enough funds!!
116114
; If you have multiple mining rigs, make sure each rig is running under a
117115
; separate ETH account, to prevent nonce collisions if they happen to submit
@@ -120,6 +118,10 @@ RPCPort=
120118
MinerAcct=0x........................................
121119
AcctPK=................................................................
122120
121+
; Desired average minutes between shares. Defaults to 2. Miner will
122+
; auto-adjust difficulty based on your hash rate. You can also specify
123+
; 'Pool' to use the difficulty assigned by your mining pool.
124+
MinutesPerShare=
123125
124126
; The remaining settings in this section apply only to SOLO MINING:
125127
@@ -164,7 +166,6 @@ ThrottleTemp=80
164166
; remain at or above ThrottleTemp.
165167
ShutDown=20
166168
167-
168169
```
169170

170171
### Building on Windows

ethminer/FarmClient.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class FarmClient : public jsonrpc::Client
7575
data.append(userAcct);
7676
result = CallMethod("getMinimumShareTarget", data);
7777
m_target = u256(result.asString());
78-
78+
7979
if (s_lastFetch.elapsedSeconds() > 20 || m_hashingAcct == "")
8080
{
8181
// no reason to retrieve this stuff every time.
@@ -134,22 +134,14 @@ class FarmClient : public jsonrpc::Client
134134

135135
}
136136

137-
void submitWork(h256 _nonce, bytes _hash, bytes _challenge)
138-
{
139-
if (m_opMode == OperationMode::Solo)
140-
submitWorkSolo(_nonce, _hash, _challenge);
141-
else
142-
submitWorkPool(_nonce, _hash, _challenge);
143-
}
144-
145-
void submitWorkPool(h256 _nonce, bytes _hash, bytes _challenge)
137+
void submitWorkPool(h256 _nonce, bytes _hash, bytes _challenge, uint64_t _difficulty)
146138
{
147139

148140
Json::Value data;
149141
data.append("0x" + _nonce.hex());
150142
data.append(devFeeMining ? DonationAddress : userAcct);
151143
data.append("0x" + toHex(_hash));
152-
data.append(m_difficulty);
144+
data.append(_difficulty);
153145
data.append("0x" + toHex(_challenge));
154146
Json::Value result = CallMethod("submitShare", data);
155147
string res = result.asString();

ethminer/MinerAux.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,22 @@ class MinerCLI
437437
LogS << "Invalid 'MinerAcct' in tokenminer.ini";
438438
exit(0);
439439
}
440+
441+
string mps = ProgOpt::Get("0xBitcoin", "MinutesPerShare","2");
442+
LowerCase(mps);
443+
if (mps == "pool")
444+
m_minutesPerShare = -1;
445+
else
446+
{
447+
m_minutesPerShare = atoi(mps.c_str());
448+
if (m_minutesPerShare < 1)
449+
{
450+
LogS << "Invalid 'MinutesPerShare' in tokenminer.ini. Defaulting to 2";
451+
m_minutesPerShare = 2;
452+
}
453+
}
454+
455+
440456
LogD << " ";
441457
LogD << "--- Program Start ---";
442458

@@ -712,6 +728,45 @@ class MinerCLI
712728
}
713729
}
714730

731+
h256 targetFromDiff(uint64_t _difficulty)
732+
{
733+
// 2^234
734+
u256 pow_2_234 = u256("0x040000000000000000000000000000000000000000000000000000000000");
735+
return pow_2_234 / _difficulty;
736+
}
737+
738+
uint64_t diffFromTarget(h256 _target)
739+
{
740+
// 2^234
741+
u256 pow_2_234 = u256("0x040000000000000000000000000000000000000000000000000000000000");
742+
u256 t = pow_2_234 / u256(_target);
743+
return static_cast<uint64_t>(t);
744+
}
745+
746+
void calcFinalTarget(GenericFarm<EthashProofOfWork>& f, h256& _target, uint64_t& _difficulty)
747+
{
748+
static float s_lastRate = 0;
749+
750+
float currentRate;
751+
752+
// if we're going by the pool difficulty, do nothing
753+
if (m_minutesPerShare == -1) return;
754+
755+
currentRate = f.hashRates().farmRate();
756+
if (s_lastRate == 0 || currentRate == 0)
757+
currentRate = f.minerCount() * 500; // assume 500 MH/s per gpu
758+
759+
// only recalculate if change is > 10%
760+
if (abs(s_lastRate - currentRate) / s_lastRate > 0.1)
761+
s_lastRate = currentRate;
762+
763+
double divisor = s_lastRate * 1000000.0 * m_minutesPerShare * 60;
764+
uint64_t target64 = (divisor == 0) ? 0 : ~uint64_t(0) / divisor;
765+
u256 target256 = target64;
766+
_target = target256 << 192;
767+
_difficulty = diffFromTarget(_target);
768+
}
769+
715770

716771
/*-----------------------------------------------------------------------------------
717772
* doFarm
@@ -825,6 +880,8 @@ class MinerCLI
825880
workRPC.getWorkSolo(_challenge, _target);
826881
lastGetWork.restart();
827882

883+
calcFinalTarget(f, _target, difficulty);
884+
828885
if (!connectedToNode)
829886
{
830887
connectedToNode = true;
@@ -894,10 +951,15 @@ class MinerCLI
894951
keccak256_0xBitcoin(challenge, sender, solution, hash);
895952
if (h256(hash) < target) {
896953
if (m_opMode == OperationMode::Pool)
954+
{
897955
LogS << "Solution found; Submitting to pool" << ((nextDevFeeSwitch >= 0) ? "" : " on the dev account");
956+
workRPC.submitWorkPool(solution, hash, challenge, difficulty);
957+
}
898958
else
959+
{
899960
LogB << "Solution found; Submitting to node";
900-
workRPC.submitWork(solution, hash, challenge);
961+
workRPC.submitWorkSolo(solution, hash, challenge);
962+
}
901963
f.solutionFound(SolutionState::Accepted, false, solutionMiner);
902964
} else {
903965
LogB << "Solution found, but invalid. Possibly stale.";
@@ -975,6 +1037,7 @@ class MinerCLI
9751037
/// Mining options
9761038
MinerType m_minerType = MinerType::Undefined;
9771039
OperationMode m_opMode = OperationMode::None;
1040+
int m_minutesPerShare = 2; // set to -1 to use pool difficulty
9781041
unsigned m_openclPlatform = 0;
9791042
unsigned m_openclDevice = 0;
9801043
unsigned m_miningThreads = UINT_MAX;

libethcore/Farm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ class GenericFarm
200200
*----------------------------------------------------------------------------------*/
201201
void setWork_token(bytes _challenge, h256 _target)
202202
{
203-
LogF << "Trace: GenericFarm::setWork, challenge=" << toHex(_challenge).substr(0, 8);
203+
204+
LogF << "Trace: GenericFarm::setWork, challenge=" << toHex(_challenge).substr(0, 8)
205+
<< ", target=" << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target);
204206
if (m_onSetWork)
205207
m_onSetWork(upper64OfHash(_target));
206208

tokenminer.ini

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ RPCPort=
3131
[0xBitcoin]
3232

3333
; POOL MINING: Your ETH account, to which payouts will be made. THE PRIVATE
34-
; KEY IS NOT REQUIRED.
35-
; SOLO MINING: Your ETH account and private key. Note the acct starts with 0x, but
36-
; not the PK. Mining rewards will be deposited to this account. Transaction
34+
; KEY IS NOT REQUIRED. Note the acct should start with 0x.
35+
; SOLO MINING: Your ETH account and private key. Note the PK does NOT start
36+
; with 0x. Mining rewards will be deposited to this account. Transaction
3737
; fees will be DRAWN from this account. Make sure you have enough funds!!
3838
; If you have multiple mining rigs, make sure each rig is running under a
3939
; separate ETH account, to prevent nonce collisions if they happen to submit
@@ -42,6 +42,10 @@ RPCPort=
4242
MinerAcct=0x........................................
4343
AcctPK=................................................................
4444

45+
; Desired average minutes between shares. Defaults to 2. Miner will
46+
; auto-adjust difficulty based on your hash rate. You can also specify
47+
; 'Pool' to use the difficulty assigned by your mining pool.
48+
MinutesPerShare=
4549

4650
; The remaining settings in this section apply only to SOLO MINING:
4751

0 commit comments

Comments
 (0)