Browse Source

New --skip-security-checks option to allow miners to skip checks when it saves bandwidth

Luke Dashjr 13 years ago
parent
commit
2708f3466e
4 changed files with 12 additions and 1 deletions
  1. 1 0
      README
  2. 6 0
      cgminer.c
  3. 2 0
      miner.h
  4. 3 1
      util.c

+ 1 - 0
README

@@ -171,6 +171,7 @@ Options for both config file and command line:
 --scrypt            Use the scrypt algorithm for mining (litecoin only)
 --sharelog <arg>    Append share log to file
 --shares <arg>      Quit after mining N shares (default: unlimited)
+--skip-security-checks <arg> Skip security checks sometimes to save bandwidth; only check 1/<arg>th of the time (default: never skip)
 --socks-proxy <arg> Set socks4 proxy (host:port) for all pools without a proxy specified
 --syslog            Use system log for output messages (default: standard error)
 --temp-cutoff <arg> Temperature where a device will be automatically disabled, one value or comma separated list (default: 95)

+ 6 - 0
cgminer.c

@@ -87,6 +87,7 @@ static char packagename[255];
 bool opt_protocol;
 static bool opt_benchmark;
 bool have_longpoll;
+int opt_skip_checks;
 bool want_per_device_stats;
 bool use_syslog;
 bool opt_quiet;
@@ -1055,6 +1056,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--shares",
 		     opt_set_intval, NULL, &opt_shares,
 		     "Quit after mining N shares (default: unlimited)"),
+	OPT_WITH_ARG("--skip-security-checks",
+			set_int_0_to_9999, NULL, &opt_skip_checks,
+			"Skip security checks sometimes to save bandwidth; only check 1/<arg>th of the time (default: never skip)"),
 	OPT_WITH_ARG("--socks-proxy",
 		     opt_set_charp, NULL, &opt_socks_proxy,
 		     "Set socks4 proxy (host:port)"),
@@ -4349,6 +4353,8 @@ static void *stratum_thread(void *userdata)
 
 	pthread_detach(pthread_self());
 
+	srand(time(NULL) + (intptr_t)userdata);
+
 	while (42) {
 		struct timeval timeout;
 		fd_set rd;

+ 2 - 0
miner.h

@@ -607,6 +607,7 @@ struct pool;
 
 extern bool opt_protocol;
 extern bool have_longpoll;
+extern int opt_skip_checks;
 extern char *opt_kernel_path;
 extern char *opt_socks_proxy;
 extern char *cgminer_path;
@@ -799,6 +800,7 @@ struct stratum_work {
 	int merkles;
 	int diff;
 
+	bool transparency_probed;
 	time_t transparency_time;
 	bool opaque;
 };

+ 3 - 1
util.c

@@ -1118,7 +1118,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->getwork_requested++;
 	total_getworks++;
 
-	if (merkles)
+	if ((merkles && (!pool->swork.transparency_probed || rand() <= RAND_MAX / (opt_skip_checks + 1))) || pool->swork.transparency_time != (time_t)-1)
 	{
 		// Request transaction data to discourage pools from doing anything shady
 		char s[1024];
@@ -1129,6 +1129,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 		stratum_send(pool, s, sLen);
 		if ((!pool->swork.opaque) && pool->swork.transparency_time == (time_t)-1)
 			pool->swork.transparency_time = time(NULL);
+		pool->swork.transparency_probed = true;
 	}
 
 	return true;
@@ -1336,6 +1337,7 @@ bool initiate_stratum(struct pool *pool)
 
 	mutex_lock(&pool->stratum_lock);
 	pool->stratum_active = false;
+	pool->swork.transparency_probed = false;
 	if (!pool->stratum_curl) {
 		pool->stratum_curl = curl_easy_init();
 		if (unlikely(!pool->stratum_curl))