-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to stop mining after finding X blocks #192
Open
ksynb
wants to merge
1
commit into
pooler:master
Choose a base branch
from
ksynb:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,7 @@ bool use_syslog = false; | |
static bool opt_background = false; | ||
static bool opt_quiet = false; | ||
static int opt_retries = -1; | ||
static int opt_max_blocks = -1; | ||
static int opt_fail_pause = 30; | ||
int opt_timeout = 0; | ||
static int opt_scantime = 5; | ||
|
@@ -194,7 +195,9 @@ Options:\n\ | |
--no-redirect ignore requests to change the URL of the mining server\n\ | ||
-q, --quiet disable per-thread hashmeter output\n\ | ||
-D, --debug enable debug output\n\ | ||
-P, --protocol-dump verbose dump of protocol-level activities\n" | ||
-P, --protocol-dump verbose dump of protocol-level activities\n\ | ||
-X, --max-blocks=N maximum number of blocks to mine before exiting\n" | ||
|
||
#ifdef HAVE_SYSLOG_H | ||
"\ | ||
-S, --syslog use system log for output messages\n" | ||
|
@@ -217,7 +220,7 @@ static char const short_options[] = | |
#ifdef HAVE_SYSLOG_H | ||
"S" | ||
#endif | ||
"a:c:Dhp:Px:qr:R:s:t:T:o:u:O:V"; | ||
"a:c:Dhp:PxX:qr:R:s:t:T:o:u:O:V"; | ||
|
||
static struct option const options[] = { | ||
{ "algo", 1, NULL, 'a' }, | ||
|
@@ -241,6 +244,7 @@ static struct option const options[] = { | |
{ "proxy", 1, NULL, 'x' }, | ||
{ "quiet", 0, NULL, 'q' }, | ||
{ "retries", 1, NULL, 'r' }, | ||
{ "max-blocks", 1, NULL, 'X' }, | ||
{ "retry-pause", 1, NULL, 'R' }, | ||
{ "scantime", 1, NULL, 's' }, | ||
#ifdef HAVE_SYSLOG_H | ||
|
@@ -682,6 +686,11 @@ static void share_result(int result, const char *reason) | |
s, | ||
result ? "(yay!!!)" : "(booooo)"); | ||
|
||
if (accepted_count >= opt_max_blocks) { | ||
applog(LOG_DEBUG, "DEBUG: Maximum blocks found as per set program option, exiting."); | ||
exit(0); | ||
} | ||
|
||
if (opt_debug && reason) | ||
applog(LOG_DEBUG, "DEBUG: reject reason: %s", reason); | ||
} | ||
|
@@ -1717,6 +1726,12 @@ static void parse_arg(int key, char *arg, char *pname) | |
free(opt_proxy); | ||
opt_proxy = strdup(arg); | ||
break; | ||
case 'X': | ||
v = atoi(arg); | ||
if (v < -1) /* sanity check */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
show_usage_and_exit(1); | ||
opt_max_blocks = v; | ||
break; | ||
case 1001: | ||
free(opt_cert); | ||
opt_cert = strdup(arg); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on subtleties of comparing signed and unsigned in C. You may want to make this code more explicit by doing e.g.: