Browse Source

New --coinbase-sig option to add arbitrary data to blocks you generate (GBT only)

Luke Dashjr 13 years ago
parent
commit
5ca55a8abd
3 changed files with 46 additions and 1 deletions
  1. 1 0
      README
  2. 1 1
      libblkmaker
  3. 44 0
      miner.c

+ 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)

+ 1 - 1
libblkmaker

@@ -1 +1 @@
-Subproject commit 243684e40d203bed04a04d665bacab701860a282
+Subproject commit 11f20e6275ae67a96d6ea2c102d922ad8721154a

+ 44 - 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;
@@ -933,6 +937,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",
+		     opt_set_charp, NULL, &opt_coinbase_sig,
+		     "Set coinbase signature when possible"),
+	OPT_WITH_ARG("--coinbase|--cbsig|--cb-sig|--cb|--prayer",
+		     opt_set_charp, 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 +1486,36 @@ 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
+		if (opt_coinbase_sig) {
+			ssize_t ae = blkmk_append_coinbase_safe(work->tmpl, opt_coinbase_sig, 101);
+			static bool appenderr = false;
+			if (ae <= 0) {
+				applog((appenderr ? LOG_DEBUG : LOG_WARNING), "Cannot append coinbase signature at all on pool %u (%d)", ae, work->pool->pool_no);
+				appenderr = true;
+			} else {
+				size_t cbappendsz = strlen(opt_coinbase_sig);
+				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, opt_coinbase_sig, 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);