Browse Source

Merge branch 'cg_merges_20130205' into bfgminer

Luke Dashjr 13 years ago
parent
commit
d4ffaa899b
5 changed files with 63 additions and 28 deletions
  1. 1 1
      README
  2. 34 25
      miner.c
  3. 6 0
      miner.h
  4. 15 2
      util.c
  5. 7 0
      util.h

+ 1 - 1
README

@@ -135,6 +135,7 @@ Options for both config file and command line:
 --compact           Use compact display without per device statistics
 --debug|-D          Enable debug output
 --debuglog          Enable debug logging
+--disable-rejecting Automatically disable pools that continually reject shares
 --expiry|-E <arg>   Upper bound on how many seconds after getting work we consider a share from it stale (w/o longpoll active) (default: 120)
 --expiry-lp <arg>   Upper bound on how many seconds after getting work we consider a share from it stale (with longpoll active) (default: 3600)
 --failover-only     Don't leak work to backup pools when primary pool is lagging
@@ -146,7 +147,6 @@ Options for both config file and command line:
 --net-delay         Impose small delays in networking to not overload slow routers
 --no-gbt            Disable getblocktemplate support
 --no-longpoll       Disable X-Long-Polling support
---no-pool-disable   Do not automatically disable pools that continually reject shares
 --no-restart        Do not attempt to restart devices that hang
 --no-stratum        Disable Stratum detection
 --no-submit-stale   Don't submit shares if they are detected as stale

+ 34 - 25
miner.c

@@ -172,7 +172,7 @@ int opt_api_port = 4028;
 bool opt_api_listen;
 bool opt_api_network;
 bool opt_delaynet;
-bool opt_disable_pool = true;
+bool opt_disable_pool;
 char *opt_icarus_options = NULL;
 char *opt_icarus_timing = NULL;
 bool opt_worktime;
@@ -1144,6 +1144,9 @@ static struct opt_table opt_config_table[] = {
 			opt_hidden
 #endif
 	),
+	OPT_WITHOUT_ARG("--disable-rejecting",
+			opt_set_bool, &opt_disable_pool,
+			"Automatically disable pools that continually reject shares"),
 #if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_FPGA))
 	OPT_WITHOUT_ARG("--enable-cpu|-C",
 			opt_set_bool, &opt_usecpu,
@@ -1247,7 +1250,7 @@ static struct opt_table opt_config_table[] = {
 #else
 			opt_hidden
 #endif
-	),
+			),
 	OPT_WITHOUT_ARG("--no-gbt",
 			opt_set_invbool, &want_gbt,
 			"Disable getblocktemplate support"),
@@ -1256,7 +1259,7 @@ static struct opt_table opt_config_table[] = {
 			"Disable X-Long-Polling support"),
 	OPT_WITHOUT_ARG("--no-pool-disable",
 			opt_set_invbool, &opt_disable_pool,
-			"Do not automatically disable pools that continually reject shares"),
+			opt_hidden),
 	OPT_WITHOUT_ARG("--no-restart",
 			opt_set_invbool, &opt_restart,
 			"Do not attempt to restart devices that hang"
@@ -6220,10 +6223,11 @@ static void set_work_target(struct work *work, double diff)
  * other means to detect when the pool has died in stratum_thread */
 static void gen_stratum_work(struct pool *pool, struct work *work)
 {
-	unsigned char *coinbase, merkle_root[32], merkle_sha[64], *merkle_hash;
-	int len, cb1_len, n1_len, cb2_len, i;
+	unsigned char *coinbase, merkle_root[32], merkle_sha[64];
+	char *header, *merkle_hash;
 	uint32_t *data32, *swap32;
-	char *header;
+	size_t alloc_len;
+	int i;
 
 	clean_work(work);
 
@@ -6232,18 +6236,19 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	/* Generate coinbase */
 	work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
 	pool->nonce2++;
-	cb1_len = strlen(pool->swork.coinbase1) / 2;
-	n1_len = strlen(pool->nonce1) / 2;
-	cb2_len = strlen(pool->swork.coinbase2) / 2;
-	len = cb1_len + n1_len + pool->n2size + cb2_len;
-	coinbase = alloca(len + 1);
-	hex2bin(coinbase, pool->swork.coinbase1, cb1_len);
-	hex2bin(coinbase + cb1_len, pool->nonce1, n1_len);
-	hex2bin(coinbase + cb1_len + n1_len, work->nonce2, pool->n2size);
-	hex2bin(coinbase + cb1_len + n1_len + pool->n2size, pool->swork.coinbase2, cb2_len);
+	alloc_len = pool->swork.cb_len;
+	align_len(&alloc_len);
+	coinbase = calloc(alloc_len, 1);
+	if (unlikely(!coinbase))
+		quit(1, "Failed to calloc coinbase in gen_stratum_work");
+	hex2bin(coinbase, pool->swork.coinbase1, pool->swork.cb1_len);
+	hex2bin(coinbase + pool->swork.cb1_len, pool->nonce1, pool->n1_len);
+	hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len, work->nonce2, pool->n2size);
+	hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.coinbase2, pool->swork.cb2_len);
 
 	/* Generate merkle root */
-	gen_hash(coinbase, merkle_root, len);
+	gen_hash(coinbase, merkle_root, pool->swork.cb_len);
+	free(coinbase);
 	memcpy(merkle_sha, merkle_root, 32);
 	for (i = 0; i < pool->swork.merkles; i++) {
 		unsigned char merkle_bin[32];
@@ -6257,15 +6262,19 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	swap32 = (uint32_t *)merkle_root;
 	for (i = 0; i < 32 / 4; i++)
 		swap32[i] = swab32(data32[i]);
-	merkle_hash = (unsigned char *)bin2hex((const unsigned char *)merkle_root, 32);
-
-	header = strdup(pool->swork.bbversion);
-	header = realloc_strcat(header, pool->swork.prev_hash);
-	header = realloc_strcat(header, (char *)merkle_hash);
-	header = realloc_strcat(header, pool->swork.ntime);
-	header = realloc_strcat(header, pool->swork.nbit);
-	header = realloc_strcat(header, "00000000"); /* nonce */
-	header = realloc_strcat(header, workpadding);
+	merkle_hash = bin2hex((const unsigned char *)merkle_root, 32);
+
+	header = calloc(pool->swork.header_len, 1);
+	if (unlikely(!header))
+		quit(1, "Failed to calloc header in gen_stratum_work");
+	sprintf(header, "%s%s%s%s%s%s%s",
+		pool->swork.bbversion,
+		pool->swork.prev_hash,
+		merkle_hash,
+		pool->swork.ntime,
+		pool->swork.nbit,
+		"00000000", /* nonce */
+		workpadding);
 
 	/* Store the stratum work diff to check it still matches the pool's
 	 * stratum diff when submitting shares */

+ 6 - 0
miner.h

@@ -887,6 +887,11 @@ struct stratum_work {
 	char *ntime;
 	bool clean;
 
+	size_t cb1_len;
+	size_t cb2_len;
+	size_t cb_len;
+
+	size_t header_len;
 	int merkles;
 	double diff;
 
@@ -976,6 +981,7 @@ struct pool {
 	size_t sockbuf_size;
 	char *sockaddr_url; /* stripped url used for sockaddr */
 	char *nonce1;
+	size_t n1_len;
 	uint32_t nonce2;
 	int n2size;
 	bool has_stratum;

+ 15 - 2
util.c

@@ -1249,12 +1249,16 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->swork.job_id = job_id;
 	pool->swork.prev_hash = prev_hash;
 	pool->swork.coinbase1 = coinbase1;
+	pool->swork.cb1_len = strlen(coinbase1) / 2;
 	pool->swork.coinbase2 = coinbase2;
+	pool->swork.cb2_len = strlen(coinbase2) / 2;
 	pool->swork.bbversion = bbversion;
 	pool->swork.nbit = nbit;
 	pool->swork.ntime = ntime;
 	pool->submit_old = !clean;
 	pool->swork.clean = true;
+	pool->swork.cb_len = pool->swork.cb1_len + pool->n1_len + pool->n2size + pool->swork.cb2_len;
+
 	for (i = 0; i < pool->swork.merkles; i++)
 		free(pool->swork.merkle[i]);
 	if (merkles) {
@@ -1265,6 +1269,15 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->swork.merkles = merkles;
 	if (clean)
 		pool->nonce2 = 0;
+	pool->swork.header_len = strlen(pool->swork.bbversion) +
+				 strlen(pool->swork.prev_hash) +
+				 strlen(pool->swork.ntime) +
+				 strlen(pool->swork.nbit) +
+	/* merkle_hash */	 32 +
+	/* nonce */		 8 +
+	/* workpadding */	 96;
+	pool->swork.header_len = pool->swork.header_len * 2 + 1;
+	align_len(&pool->swork.header_len);
 	mutex_unlock(&pool->pool_lock);
 
 	applog(LOG_DEBUG, "Received stratum notify from pool %u with job_id=%s",
@@ -1624,6 +1637,7 @@ bool initiate_stratum(struct pool *pool)
 		applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
 		goto out;
 	}
+	pool->n1_len = strlen(pool->nonce1) / 2;
 	pool->n2size = json_integer_value(json_array_get(res_val, 2));
 	if (!pool->n2size) {
 		applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
@@ -1715,8 +1729,7 @@ void *realloc_strcat(char *ptr, char *s)
 		return ptr;
 
 	len += old + 1;
-	if (len % 4)
-		len += 4 - (len % 4);
+	align_len(&len);
 
 	ret = malloc(len);
 	if (unlikely(!ret))

+ 7 - 0
util.h

@@ -74,4 +74,11 @@ extern void notifier_init(int pipefd[2]);
 extern void notifier_wake(int fd[2]);
 extern void notifier_read(int fd[2]);
 
+/* Align a size_t to 4 byte boundaries for fussy arches */
+static inline void align_len(size_t *len)
+{
+	if (*len % 4)
+		*len += 4 - (*len % 4);
+}
+
 #endif /* __UTIL_H__ */