Skip to content

Commit a2ebb27

Browse files
protect against divide by zero
1 parent e7f43e3 commit a2ebb27

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
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.6")
4+
set(PROJECT_VERSION "2.1.7")
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()

ethminer/MinerAux.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,26 +745,32 @@ class MinerCLI
745745

746746
void calcFinalTarget(GenericFarm<EthashProofOfWork>& f, h256& _target, uint64_t& _difficulty)
747747
{
748+
// on input we're expecting that target and difficulty are set to the values specified by the pool.
748749
static float s_lastRate = 0;
749750

750-
float currentRate;
751-
752751
// if we're going by the pool difficulty, do nothing
753752
if (m_minutesPerShare == -1) return;
754753

755-
currentRate = f.hashRates().farmRate();
754+
float currentRate = f.hashRates().farmRate();
755+
LogF << "Trace: calcFinalTarget - s_lastRate : " << s_lastRate << ", farmRate : " << currentRate;
756+
// the first time around we usually don't have good hash rate information yet.
756757
if (s_lastRate == 0 || currentRate == 0)
757-
currentRate = f.minerCount() * 500; // assume 500 MH/s per gpu
758+
currentRate = f.minerCount() * 400; // take a guess at hash rates
758759

759760
// only recalculate if change is > 10%
760-
if (abs(s_lastRate - currentRate) / s_lastRate > 0.1)
761+
if (s_lastRate == 0 || abs(s_lastRate - currentRate) / s_lastRate > 0.1)
762+
{
761763
s_lastRate = currentRate;
764+
LogF << "Trace: calcFinalTarget - New s_lastRate : " << s_lastRate;
765+
}
762766

763767
double divisor = s_lastRate * 1000000.0 * m_minutesPerShare * 60;
764768
uint64_t target64 = (divisor == 0) ? 0 : ~uint64_t(0) / divisor;
765769
u256 target256 = target64;
766770
_target = target256 << 192;
767771
_difficulty = diffFromTarget(_target);
772+
LogF << "Trace: calcFinalTarget - Target : " << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target)
773+
<< ", difficulty : " << std::dec << _difficulty;
768774
}
769775

770776

libethcore/Farm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class GenericFarm
170170
mutable SharedMutex x_hashRates;
171171
std::vector<EMA> m_minerRates;
172172
std::vector<float> m_lastReportedRate; // used for delta change calculations
173-
float m_farmRate;
173+
float m_farmRate = 0;
174174

175175
}; // class HashRates
176176

0 commit comments

Comments
 (0)