From da95132c4a7d612ccff4e7fb41779a5902934782 Mon Sep 17 00:00:00 2001 From: Pttn <28868425+Pttn@users.noreply.github.com> Date: Thu, 1 Apr 2021 23:43:03 +0200 Subject: [PATCH] Keep Tuple Counts if restarting due to Difficulty Changes Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com> --- Miner.cpp | 12 +++++++++--- Miner.hpp | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Miner.cpp b/Miner.cpp index 2fd3327..c689de5 100644 --- a/Miner.cpp +++ b/Miner.cpp @@ -347,7 +347,9 @@ void Miner::startThreads() { ERRORMSG("The miner is already running"); else { _running = true; - _statManager.start(_parameters.pattern.size()); + if (!_keepStats) + _statManager.start(_parameters.pattern.size()); + _keepStats = false; std::cout << "Starting the miner's master thread..." << std::endl; _masterThread = std::thread(&Miner::_manageTasks, this); std::cout << "Starting " << _parameters.threads << " miner's worker threads..." << std::endl; @@ -880,12 +882,16 @@ void Miner::_manageTasks() { _currentWorkIndex = 0; uint32_t oldHeight(0); while (_running && _client->getJob(job)) { - if (job.difficulty < _difficultyAtInit/_parameters.restartDifficultyFactor || job.difficulty > _difficultyAtInit*_parameters.restartDifficultyFactor) // Restart to retune parameters. + if (job.difficulty < _difficultyAtInit/_parameters.restartDifficultyFactor || job.difficulty > _difficultyAtInit*_parameters.restartDifficultyFactor) { // Restart to retune parameters. + _keepStats = true; _shouldRestart = true; + } if (std::dynamic_pointer_cast(_client) != nullptr) { const NetworkInfo networkInfo(std::dynamic_pointer_cast(_client)->info()); - if (!hasAcceptedPatterns(networkInfo.acceptedPatterns)) // Restart if the pattern changed and is no longer compatible with the current one (notably, for the 0.20 fork) + if (!hasAcceptedPatterns(networkInfo.acceptedPatterns)) { // Restart if the pattern changed and is no longer compatible with the current one (notably, for the 0.20 fork) + _keepStats = false; _shouldRestart = true; + } } _presieveTime = _presieveTime.zero(); _sieveTime = _sieveTime.zero(); diff --git a/Miner.hpp b/Miner.hpp index 208d682..edc7f74 100644 --- a/Miner.hpp +++ b/Miner.hpp @@ -117,7 +117,7 @@ class Miner { std::vector _primorialOffsets; std::vector _halfPattern, _primorialOffsetDiff; // Miner state variables - bool _inited, _running, _shouldRestart; + bool _inited, _running, _shouldRestart, _keepStats; double _difficultyAtInit; // Restart the miner if the Difficulty changed a lot to retune TsQueue _presieveTasks, _tasks; TsQueue _tasksDoneInfos; @@ -166,7 +166,7 @@ class Miner { Miner(const Options &options) : _mode(options.mode()), _parameters(MinerParameters()), _client(nullptr), - _inited(false), _running(false), _shouldRestart(false) { + _inited(false), _running(false), _shouldRestart(false), _keepStats(false) { _nPrimes = 0; _primesIndexThreshold = 0; }