Skip to content

Commit

Permalink
Add option to stop rieMiner when a tuple is found in Search mode (Rie…
Browse files Browse the repository at this point in the history
  • Loading branch information
MakisChristou authored Mar 1, 2023
1 parent 6bffce4 commit 77a45b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ thread_local uint64_t** factorsCacheCounts{nullptr};
thread_local uint16_t threadId(65535);

void Miner::init(const MinerParameters &minerParameters) {
_tupleFound = false;
_shouldRestart = false;
if (_inited) {
logger.log("The miner is already initialized\n"s, MessageType::ERROR);
Expand Down Expand Up @@ -1114,6 +1115,8 @@ void Miner::_doCheckTask(Task task) {
message += "-tuple found by worker thread "s + std::to_string(threadId) + "\n"s;
logger.log(message, MessageType::BOLD);
logger.log("Base prime: "s + basePrime.get_str() + "\n"s);
if((_mode == "Search" && primeCount >= _parameters.pattern.size()))
_tupleFound = true;
}
Job filledJob(_works[workIndex].job);
filledJob.result = basePrime;
Expand Down
5 changes: 4 additions & 1 deletion Miner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Miner {
std::vector<mpz_class> _primorialOffsets;
std::vector<uint64_t> _halfPattern, _primorialOffsetDiff;
// Miner state variables
bool _inited, _running, _shouldRestart, _keepStats;
bool _inited, _running, _shouldRestart, _keepStats, _tupleFound;
double _difficultyAtInit; // Restart the miner if the Difficulty changed a lot to retune
TsQueue<Task> _presieveTasks, _tasks;
TsQueue<TaskDoneInfo> _tasksDoneInfos;
Expand Down Expand Up @@ -212,6 +212,9 @@ class Miner {
bool benchmarkFinishedEnoughPrimes(const uint64_t) const;
void printBenchmarkResults() const;
void printTupleStats() const;
bool tupleFound() {
return _tupleFound;
}
};

#endif
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ rieMiner proposes the following Modes depending on what you want to do. Use the
* `RefreshInterval`: refresh rate of the stats in seconds. <= 0 to disable them and only notify when a long enough tuple or share is found, or when the network finds a block. Default: 30;
* `GeneratePrimeTableFileUpTo`: if > 1, generates the table of primes up to the given limit and saves it to a `PrimeTable64.bin` file, which will be reused instead of recomputing the table at every miner initialization. This does not affect mining, but is useful if restarting rieMiner often with large Prime Table Limits, notably for debugging or benchmarks. However, the file will take a few GB of disk space for large limits and you should have a fast SSD. Default: 0;
* `RawOutput`: if you need to disable the coloring in the outputs, set this to `Yes`. Default : disabled;
* `APIPort`: sets the port to use for the rieMiner's API server. 0 to disable the API. Default : 0.
* `APIPort`: sets the port to use for the rieMiner's API server. 0 to disable the API. Default : 0;
* `KeepRunning`: if you need to continue running the miner even if you find a tuple in Search mode, set this to `Yes` Default : disabled.

## Interface

Expand Down
17 changes: 16 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ bool Configuration::parse(const int argc, char** argv, std::string &parsingMessa
else
logger.setRawMode(false);
}
else if (key == "KeepRunning")
{
if(value == "Yes")
_options.keepRunning = true;
else
_options.keepRunning = false;
}
else
parsingMessages += "Ignoring option with unused key '"s + key + "'\n"s;
}
Expand Down Expand Up @@ -427,7 +434,15 @@ int main(int argc, char** argv) {
miner->startThreads();
timer = std::chrono::steady_clock::now();
while (running) {
if (configuration.options().mode == "Benchmark" && miner->running()) {
if (!configuration.options().keepRunning && configuration.options().mode == "Search" && miner->running()) {
if(miner->tupleFound()) {
miner->printStats();
miner->stop();
running = false;
break;
}
}
else if (configuration.options().mode == "Benchmark" && miner->running()) {
if (miner->benchmarkFinishedTimeOut(configuration.options().benchmarkTimeLimit) || miner->benchmarkFinishedEnoughPrimes(configuration.options().benchmarkPrimeCountLimit)) {
miner->printBenchmarkResults();
miner->stop();
Expand Down
4 changes: 3 additions & 1 deletion main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Options {
uint64_t benchmarkPrimeCountLimit;
std::vector<std::string> rules;
uint16_t apiPort;
bool keepRunning;
Options() : // Default options: Standard Benchmark with 8 threads
host("127.0.0.1"),
username(""),
Expand All @@ -107,7 +108,8 @@ struct Options {
benchmarkTimeLimit(86400.),
benchmarkPrimeCountLimit(1000000),
rules{"segwit"},
apiPort(0) {}
apiPort(0),
keepRunning(false) {}
};

class Configuration {
Expand Down

0 comments on commit 77a45b5

Please sign in to comment.