Browse Source

Merge branch 'gbtmsg' into bfgminer

Luke Dashjr 13 years ago
parent
commit
fafe4f7610
6 changed files with 81 additions and 5 deletions
  1. 6 4
      API-README
  2. 1 0
      README
  3. 9 0
      api.c
  4. 1 1
      libblkmaker
  5. 63 0
      miner.c
  6. 1 0
      miner.h

+ 6 - 4
API-README

@@ -324,12 +324,13 @@ The list of requests - a (*) means it requires privileged access - and replies a
                               PerDevice=true/false,
                               WorkTime=true/false|
 
- setconfig|name,N (*)
+ setconfig|name,value (*)
                none           There is no reply section just the STATUS section
-                              stating the results of setting 'name' to N
+                              stating the results of setting 'name'
                               The valid values for name are currently:
-                              queue, scantime, expiry
-                              N is an integer in the range 0 to 9999
+                              queue, scantime, expiry (integer in the range
+                                                       0 to 9999)
+                              coinbase-sig (string)
 
 When you enable, disable or restart a GPU or PGA, you will also get Thread messages
 in the BFGMiner status window
@@ -401,6 +402,7 @@ Modified API commands:
                'Difficulty Stale', 'Last Share Difficulty'
  'stats' - add 'Work Diff', 'Min Diff', 'Max Diff', 'Min Diff Count',
                'Max Diff Count' to the pool stats
+ 'setconfig|name,value' - add 'Coinbase-Sig' string
 
 ----------
 

+ 1 - 0
README

@@ -133,6 +133,7 @@ Options for both config file and command line:
 --api-port          Port number of miner API (default: 4028)
 --balance           Change multipool strategy from failover to even share balance
 --benchmark         Run BFGMiner in benchmark mode - produces no shares
+--coinbase-sig <arg> Set coinbase signature when possible
 --debug|-D          Enable debug output
 --debuglog          Enable debug logging
 --expiry|-E <arg>   Upper bound on how many seconds after getting work we consider a share from it stale (default: 120)

+ 9 - 0
api.c

@@ -1323,6 +1323,7 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
 	root = api_add_int(root, "ScanTime", &opt_scantime, false);
 	root = api_add_int(root, "Queue", &opt_queue, false);
 	root = api_add_int(root, "Expiry", &opt_expiry, false);
+	root = api_add_string(root, "Coinbase-Sig", opt_coinbase_sig, true);
 
 	root = print_data(root, buf, isjson);
 	if (isjson)
@@ -2911,6 +2912,14 @@ static void setconfig(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __m
 	}
 
 	*(comma++) = '\0';
+
+	if (strcasecmp(param, "coinbase-sig") == 0) {
+		free(opt_coinbase_sig);
+		opt_coinbase_sig = strdup(comma);
+		strcpy(io_buffer, message(MSG_SETCONFIG, 1, param, isjson));
+		return;
+	}
+
 	value = atoi(comma);
 	if (value < 0 || value > 9999) {
 		strcpy(io_buffer, message(MSG_INVNUM, value, param, isjson));

+ 1 - 1
libblkmaker

@@ -1 +1 @@
-Subproject commit 243684e40d203bed04a04d665bacab701860a282
+Subproject commit 04fa99034bfd533e6d8a9ecb89302d3db5b28156

+ 63 - 0
miner.c

@@ -100,6 +100,10 @@ bool opt_protocol;
 static bool opt_benchmark;
 static bool want_longpoll = true;
 static bool want_gbt = true;
+#if BLKMAKER_VERSION < 1
+const
+#endif
+char *opt_coinbase_sig;
 bool have_longpoll;
 bool want_per_device_stats;
 bool use_syslog;
@@ -510,6 +514,12 @@ static char *set_int_1_to_10(const char *arg, int *i)
 	return set_int_range(arg, i, 1, 10);
 }
 
+char *set_strdup(const char *arg, char **p)
+{
+	*p = strdup((char *)arg);
+	return NULL;
+}
+
 #ifdef HAVE_LIBUDEV
 #include <libudev.h>
 #endif
@@ -933,6 +943,16 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--bench-algo|-b",
 		     set_int_0_to_9999, opt_show_intval, &opt_bench_algo,
 		     opt_hidden),
+#endif
+#if BLKMAKER_VERSION > 0
+	OPT_WITH_ARG("--coinbase-sig",
+		     set_strdup, NULL, &opt_coinbase_sig,
+		     "Set coinbase signature when possible"),
+	OPT_WITH_ARG("--coinbase|--cbsig|--cb-sig|--cb|--prayer",
+		     set_strdup, NULL, &opt_coinbase_sig,
+		     opt_hidden),
+#endif
+#ifdef WANT_CPUMINE
 	OPT_WITH_ARG("--cpu-threads|-t",
 		     force_nthreads_int, opt_show_intval, &opt_n_threads,
 		     "Number of miner CPU threads"),
@@ -1472,6 +1492,49 @@ static bool work_decode(const json_t *val, struct work *work)
 			goto err_out;
 		}
 		work->rolltime = blkmk_time_left(work->tmpl, time(NULL));
+#if BLKMAKER_VERSION > 0
+		{
+			ssize_t ae = blkmk_append_coinbase_safe(work->tmpl, opt_coinbase_sig, 101);
+			static bool appenderr = false;
+			if (ae <= 0) {
+				if (opt_coinbase_sig) {
+					applog((appenderr ? LOG_DEBUG : LOG_WARNING), "Cannot append coinbase signature at all on pool %u (%d)", ae, work->pool->pool_no);
+					appenderr = true;
+				}
+			} else if (ae >= 3 || opt_coinbase_sig) {
+				const char *cbappend = opt_coinbase_sig;
+				if (!cbappend) {
+					const char full[] = PACKAGE " " VERSION;
+					// NOTE: Intentially including a trailing \0 on long forms so extranonce doesn't confuse things
+					if ((size_t)ae >= sizeof(full))
+						cbappend = full;
+					else if ((size_t)ae >= sizeof(PACKAGE))
+						cbappend = PACKAGE;
+					else
+						cbappend = "BFG";
+				}
+				size_t cbappendsz = strlen(cbappend);
+				static bool truncatewarning = false;
+				if (cbappendsz <= (size_t)ae) {
+					ae = cbappendsz;
+					truncatewarning = false;
+				} else {
+					char *tmp = strndup(opt_coinbase_sig, ae);
+					applog((truncatewarning ? LOG_DEBUG : LOG_WARNING),
+					       "Pool %u truncating appended coinbase signature at %d bytes: %s(%s)",
+					       work->pool->pool_no, ae, tmp, &opt_coinbase_sig[ae]);
+					free(tmp);
+					truncatewarning = true;
+				}
+				ae = blkmk_append_coinbase_safe(work->tmpl, cbappend, ae);
+				if (ae <= 0) {
+					applog((appenderr ? LOG_DEBUG : LOG_WARNING), "Error appending coinbase signature (%d)", ae);
+					appenderr = true;
+				} else
+					appenderr = false;
+			}
+		}
+#endif
 		if (blkmk_get_data(work->tmpl, work->data, 80, time(NULL), NULL, &work->dataid) < 76)
 			goto err_out;
 		swap32yes(work->data, work->data, 80 / 4);

+ 1 - 0
miner.h

@@ -633,6 +633,7 @@ static inline void rwlock_init(pthread_rwlock_t *lock)
 struct pool;
 
 extern bool opt_protocol;
+extern char *opt_coinbase_sig;
 extern bool have_longpoll;
 extern char *opt_kernel_path;
 extern char *opt_socks_proxy;