Browse Source

Support for fractional diffs and the classic just-below-1 share all FFs diff target.

Con Kolivas 13 years ago
parent
commit
4e7edf0bc2
3 changed files with 27 additions and 39 deletions
  1. 13 11
      miner.c
  2. 2 2
      miner.h
  3. 12 26
      util.c

+ 13 - 11
miner.c

@@ -5915,25 +5915,27 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
  * 0x00000000ffff0000000000000000000000000000000000000000000000000000
  * so we use a big endian 64 bit unsigned integer centred on the 5th byte to
  * cover a huge range of difficulty targets, though not all 256 bits' worth */
-static void set_work_target(struct work *work, int diff)
+static void set_work_target(struct work *work, double diff)
 {
 	unsigned char rtarget[36], target[36];
+	double d64;
 	uint64_t *data64, h64;
 
-	if (!diff) {
-		// Special support is needed for difficulties < 1
+	d64 = diffone;
+	d64 /= diff;
+	h64 = d64;
+
+	if (h64) {
+		memset(rtarget, 0, 32);
+		data64 = (uint64_t *)(rtarget + 4);
+		*data64 = htobe64(h64);
+		swab256(target, rtarget);
+	} else {
+		/* Support for the classic all FFs just-below-1 diff */
 		memset(target, 0xff, 28);
 		memset(&target[28], 0, 4);
-		goto havetarget;
 	}
 
-	h64 = diffone;
-	h64 /= (uint64_t)diff;
-	memset(rtarget, 0, 32);
-	data64 = (uint64_t *)(rtarget + 4);
-	*data64 = htobe64(h64);
-	swab256(target, rtarget);
-havetarget:
 	if (opt_debug) {
 		char *htarget = bin2hex(target, 32);
 

+ 2 - 2
miner.h

@@ -894,7 +894,7 @@ struct stratum_work {
 	bool clean;
 
 	int merkles;
-	int diff;
+	double diff;
 
 	time_t transparency_time;
 	bool opaque;
@@ -1037,7 +1037,7 @@ struct work {
 	char 		job_id[64];
 	char		nonce2[64];
 	char		ntime[16];
-	int		sdiff;
+	double		sdiff;
 
 	unsigned char	work_restart_id;
 	int		id;

+ 12 - 26
util.c

@@ -1119,19 +1119,17 @@ static bool parse_notify(struct pool *pool, json_t *val)
 
 static bool parse_diff(struct pool *pool, json_t *val)
 {
-	double fpdiff;
-	int diff;
+	double diff;
 
-	fpdiff = json_number_value(json_array_get(val, 0));
-	if (fpdiff < 0.9999)
+	diff = json_number_value(json_array_get(val, 0));
+	if (diff == 0)
 		return false;
-	diff = floor(fpdiff);
 
 	mutex_lock(&pool->pool_lock);
 	pool->swork.diff = diff;
 	mutex_unlock(&pool->pool_lock);
 
-	applog(LOG_DEBUG, "Pool %d difficulty set to %d", pool->pool_no, diff);
+	applog(LOG_DEBUG, "Pool %d difficulty set to %f", pool->pool_no, diff);
 
 	return true;
 }
@@ -1261,30 +1259,18 @@ bool auth_stratum(struct pool *pool)
 	if (!stratum_send(pool, s, strlen(s)))
 		goto out;
 
-	while (1) {
-		if (!sock_full(pool, true)) {
-			applog(LOG_ERR, "Stratum authentication timed out for pool %d", pool->pool_no);
-			goto out;
-		}
+	/* Parse all data in the queue and anything left should be auth */
+	while (42) {
 		sret = recv_line(pool);
-		if (!parse_method(pool, sret) && !parse_stratum_response(pool, sret)) {
-			// Check for auth response
-			val = JSON_LOADS(sret, &err);
-			if (val) {
-				json_t *id_val = json_object_get(val, "id");
-				if (json_is_string(id_val) && !strcmp(json_string_value(id_val), "auth"))
-					break;
-				json_decref(val);
-			}
-
-			clear_sock(pool);
-			applog(LOG_INFO, "Failed to parse stratum buffer");
+		if (!sret)
+			goto out;
+		if (parse_method(pool, sret))
 			free(sret);
-			return ret;
-		}
-		free(sret);
+		else
+			break;
 	}
 
+	val = JSON_LOADS(sret, &err);
 	free(sret);
 	res_val = json_object_get(val, "result");
 	err_val = json_object_get(val, "error");