Browse Source

Bugfix: Minimal support for handling real difficulties from stratum server

Luke Dashjr 13 years ago
parent
commit
320edb30e2
2 changed files with 12 additions and 2 deletions
  1. 8 0
      miner.c
  2. 4 2
      util.c

+ 8 - 0
miner.c

@@ -5601,12 +5601,20 @@ static void set_work_target(struct work *work, int diff)
 	unsigned char rtarget[36], target[36];
 	uint64_t *data64, h64;
 
+	if (!diff) {
+		// Special support is needed for difficulties < 1
+		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);
 

+ 4 - 2
util.c

@@ -1114,11 +1114,13 @@ static bool parse_notify(struct pool *pool, json_t *val)
 
 static bool parse_diff(struct pool *pool, json_t *val)
 {
+	double fpdiff;
 	int diff;
 
-	diff = json_integer_value(json_array_get(val, 0));
-	if (diff < 1)
+	fpdiff = json_number_value(json_array_get(val, 0));
+	if (fpdiff < 0.9999)
 		return false;
+	diff = floor(fpdiff);
 
 	mutex_lock(&pool->pool_lock);
 	pool->swork.diff = diff;