Skip to content

Commit

Permalink
Keep Tuple Counts if restarting due to Difficulty Changes
Browse files Browse the repository at this point in the history
Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
  • Loading branch information
Pttn committed Apr 1, 2021
1 parent bfffe51 commit da95132
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NetworkedClient>(_client) != nullptr) {
const NetworkInfo networkInfo(std::dynamic_pointer_cast<NetworkedClient>(_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();
Expand Down
4 changes: 2 additions & 2 deletions Miner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Miner {
std::vector<mpz_class> _primorialOffsets;
std::vector<uint64_t> _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<Task> _presieveTasks, _tasks;
TsQueue<TaskDoneInfo> _tasksDoneInfos;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit da95132

Please sign in to comment.