|
|
@ -7,14 +7,14 @@ |
|
|
|
namespace Stratum |
|
|
|
namespace Stratum |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Returning false will stop any further share verifications (DoS prevention, etc)
|
|
|
|
// Returning false will stop any further share verifications (DoS prevention, etc)
|
|
|
|
bool ShareLimiter::Submit() |
|
|
|
bool ShareLimiter::Submit(uint64 diff) |
|
|
|
{ |
|
|
|
{ |
|
|
|
++_totalShares; |
|
|
|
++_totalShares; |
|
|
|
|
|
|
|
|
|
|
|
uint64 curTime = Util::Date(); |
|
|
|
uint64 curTime = Util::Date(); |
|
|
|
uint64 sinceLast = curTime - _lastRetarget; |
|
|
|
uint64 sinceLast = curTime - _lastRetarget; |
|
|
|
|
|
|
|
|
|
|
|
_shares.push_back(curTime); |
|
|
|
_shares.push_back(ShareLimiterRecord(diff, curTime)); |
|
|
|
|
|
|
|
|
|
|
|
if (sinceLast < sConfig.Get<uint32>("RetargetInterval")) |
|
|
|
if (sinceLast < sConfig.Get<uint32>("RetargetInterval")) |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -27,34 +27,40 @@ namespace Stratum |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Drop old shares
|
|
|
|
while (_shares.size()) { |
|
|
|
while (_shares.size()) { |
|
|
|
if (_shares.front() > curTime - sConfig.Get<uint32>("RetargetTimeBuffer")) |
|
|
|
if (_shares.front().time > curTime - sConfig.Get<uint32>("RetargetTimeBuffer")) |
|
|
|
break; |
|
|
|
break; |
|
|
|
_shares.pop_front(); |
|
|
|
_shares.pop_front(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32 interval = sConfig.Get<uint32>("RetargetTimeBuffer"); |
|
|
|
double totalWeighted = 0; |
|
|
|
|
|
|
|
for (uint32 i = 0; i < _shares.size(); ++i) |
|
|
|
|
|
|
|
totalWeighted += _shares[i].diff; |
|
|
|
|
|
|
|
|
|
|
|
// Calculate shares/min
|
|
|
|
double interval = std::min(curTime - _startTime, uint64(sConfig.Get<uint32>("RetargetTimeBuffer"))); |
|
|
|
double speed = double(_shares.size()*60) / double(interval); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate difference from pool target in %
|
|
|
|
// Calculate hashrate in MH/s
|
|
|
|
double variance = speed / double(sConfig.Get<uint32>("RetargetSharesPerMin")); |
|
|
|
double hashrate = (MEGAHASHCONST*totalWeighted)/interval; |
|
|
|
|
|
|
|
|
|
|
|
sLog.Debug(LOG_STRATUM, "Miner variance: %f speed: %f", variance, speed); |
|
|
|
// Calculate new diff
|
|
|
|
|
|
|
|
uint64 newDiff = (hashrate * sConfig.Get<double>("RetargetTimePerShare")) / MEGAHASHCONST; |
|
|
|
// Check if we need to retarget
|
|
|
|
|
|
|
|
if (variance*100 < sConfig.Get<uint32>("RetargetVariance")) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64 newDiff = double(_client->GetDifficulty()) * variance; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check Limits
|
|
|
|
if (newDiff < sConfig.Get<uint32>("RetargetMinDiff")) |
|
|
|
if (newDiff < sConfig.Get<uint32>("RetargetMinDiff")) |
|
|
|
newDiff = sConfig.Get<uint32>("RetargetMinDiff"); |
|
|
|
newDiff = sConfig.Get<uint32>("RetargetMinDiff"); |
|
|
|
|
|
|
|
|
|
|
|
if (newDiff > sConfig.Get<uint32>("RetargetMaxDiff")) |
|
|
|
if (newDiff > sConfig.Get<uint32>("RetargetMaxDiff")) |
|
|
|
newDiff = sConfig.Get<uint32>("RetargetMaxDiff"); |
|
|
|
newDiff = sConfig.Get<uint32>("RetargetMaxDiff"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate variance in %
|
|
|
|
|
|
|
|
uint32 variance = abs(((newDiff - _client->GetDifficulty()) * 100) / _client->GetDifficulty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sLog.Debug(LOG_STRATUM, "Miner new diff: %u Variance: %u%% Hashrate: %f MH/s", newDiff, variance, hashrate); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if we need to retarget
|
|
|
|
|
|
|
|
if (variance < sConfig.Get<uint32>("RetargetVariance")) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
_client->SetDifficulty(newDiff, true); |
|
|
|
_client->SetDifficulty(newDiff, true); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|