Browse Source

Merge commit '923b9e0' into cgmerges

Conflicts:
	miner.h
Luke Dashjr 13 years ago
parent
commit
0552fe2ce8
3 changed files with 35 additions and 24 deletions
  1. 2 1
      README
  2. 32 22
      miner.c
  3. 1 1
      miner.h

+ 2 - 1
README

@@ -484,12 +484,13 @@ and pipe the output directly to that command.
 The WorkTime details 'debug' option adds details on the end of each line
 displayed for Accepted or Rejected work done. An example would be:
 
- <-00000059.ed4834a3 M:X G:17:02:38:0.405 C:1.855 (2.995) W:3.440 (0.000) S:0.461 R:17:02:47
+ <-00000059.ed4834a3 M:X D:1.0 G:17:02:38:0.405 C:1.855 (2.995) W:3.440 (0.000) S:0.461 R:17:02:47
 
 The first 2 hex codes are the previous block hash, the rest are reported in
 seconds unless stated otherwise:
 The previous hash is followed by the getwork mode used M:X where X is one of
 P:Pool, T:Test Pool, L:LP or B:Benchmark,
+then D:d.ddd is the difficulty required to get a share from the work,
 then G:hh:mm:ss:n.nnn, which is when the getwork or LP was sent to the pool and
 the n.nnn is how long it took to reply,
 followed by 'O' on it's own if it is an original getwork, or 'C:n.nnn' if it was

+ 32 - 22
miner.c

@@ -1453,8 +1453,6 @@ static void calc_midstate(struct work *work)
 
 static bool work_decode(const json_t *val, struct work *work)
 {
-	unsigned char bits = 0, i;
-	
 	if (unlikely(detect_algo == 1)) {
 		json_t *tmp = json_object_get(val, "algorithm");
 		const char *v = tmp ? json_string_value(tmp) : "";
@@ -1526,22 +1524,6 @@ static bool work_decode(const json_t *val, struct work *work)
 			work->target[p] = c;
 		}
 	}
-	
-	for (i = 32; i--; )
-	{
-		if (work->target[i])
-		{
-			unsigned char j = ~work->target[i];
-			while (j & 0x80)
-			{
-				++bits;
-				j <<= 1;
-			}
-			break;
-		}
-		bits += 8;
-	}
-	work->difficulty = pow(2, bits - 32);
 
 	memset(work->hash, 0, sizeof(work->hash));
 
@@ -2176,6 +2158,7 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 			double work_to_submit = tdiff(&tv_submit,
 							(struct timeval *)&(work->tv_work_found));
 			double submit_time = tdiff(&tv_submit_reply, &tv_submit);
+			int diffplaces = 3;
 
 			tm = localtime(&(work->tv_getwork.tv_sec));
 			memcpy(&tm_getwork, tm, sizeof(struct tm));
@@ -2190,10 +2173,14 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 			else
 				strcpy(workclone, "O");
 
-			sprintf(worktime, " <-%08lx.%08lx M:%c G:%02d:%02d:%02d:%1.3f %s (%1.3f) W:%1.3f (%1.3f) S:%1.3f R:%02d:%02d:%02d",
+			if (work->work_difficulty < 1)
+				diffplaces = 6;
+
+			sprintf(worktime, " <-%08lx.%08lx M:%c D:%1.*f G:%02d:%02d:%02d:%1.3f %s (%1.3f) W:%1.3f (%1.3f) S:%1.3f R:%02d:%02d:%02d",
 				(unsigned long)swab32(*(uint32_t *)&(work->data[28])),
 				(unsigned long)swab32(*(uint32_t *)&(work->data[24])),
-				work->getwork_mode, tm_getwork.tm_hour, tm_getwork.tm_min,
+				work->getwork_mode, diffplaces, work->work_difficulty,
+				tm_getwork.tm_hour, tm_getwork.tm_min,
 				tm_getwork.tm_sec, getwork_time, workclone,
 				getwork_to_work, work_time, work_to_submit, submit_time,
 				tm_submit_reply.tm_hour, tm_submit_reply.tm_min,
@@ -2206,9 +2193,9 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 	 * same time is zero so there is no point adding extra locking */
 	if (json_is_null(res) || json_is_true(res)) {
 		cgpu->accepted++;
-		cgpu->accepted_weighed += work->difficulty;
+		cgpu->accepted_weighed += work->work_difficulty;
 		total_accepted++;
-		total_accepted_weighed += work->difficulty;
+		total_accepted_weighed += work->work_difficulty;
 		pool->accepted++;
 		pool->seq_rejects = 0;
 		cgpu->last_share_pool = pool->pool_no;
@@ -2373,6 +2360,25 @@ static inline struct pool *select_pool(bool lagging)
 	return pool;
 }
 
+static double DIFFEXACTONE = 26959946667150639794667015087019630673637144422540572481103610249216.0;
+
+/*
+ * Calculate the work share difficulty
+ */
+static void calc_diff(struct work *work)
+{
+	double targ;
+	int i;
+
+	targ = 0;
+	for (i = 31; i >= 0; i--) {
+		targ *= 256;
+		targ += work->target[i];
+	}
+
+	work->work_difficulty = DIFFEXACTONE / (targ ? : DIFFEXACTONE);
+}
+
 static void get_benchmark_work(struct work *work)
 {
 	// Use a random work block pulled from a pool
@@ -2388,6 +2394,7 @@ static void get_benchmark_work(struct work *work)
 	gettimeofday(&(work->tv_getwork), NULL);
 	memcpy(&(work->tv_getwork_reply), &(work->tv_getwork), sizeof(struct timeval));
 	work->getwork_mode = GETWORK_MODE_BENCHMARK;
+	calc_diff(work);
 }
 
 static char *prepare_rpc_req(struct work *work, enum pool_protocol proto, const char *lpid)
@@ -2513,6 +2520,7 @@ tryagain:
 	work->pool = pool;
 	work->longpoll = false;
 	work->getwork_mode = GETWORK_MODE_POOL;
+	calc_diff(work);
 	total_getworks++;
 	pool->getwork_requested++;
 
@@ -4658,6 +4666,7 @@ tryagain:
 			memcpy(&(work->tv_getwork), &tv_getwork, sizeof(struct timeval));
 			memcpy(&(work->tv_getwork_reply), &tv_getwork_reply, sizeof(struct timeval));
 			work->getwork_mode = GETWORK_MODE_TESTPOOL;
+			calc_diff(work);
 			applog(LOG_DEBUG, "Pushing pooltest work to base pool");
 
 			tq_push(thr_info[stage_thr_id].q, work);
@@ -5281,6 +5290,7 @@ static void convert_to_work(json_t *val, int rolltime, struct pool *pool, struct
 	memcpy(&(work->tv_getwork), tv_lp, sizeof(struct timeval));
 	memcpy(&(work->tv_getwork_reply), tv_lp_reply, sizeof(struct timeval));
 	work->getwork_mode = GETWORK_MODE_LP;
+	calc_diff(work);
 
 	if (pool->enabled == POOL_REJECTING)
 		work->mandatory = true;

+ 1 - 1
miner.h

@@ -909,7 +909,7 @@ struct work {
 	int		id;
 	UT_hash_handle hh;
 	
-	float		difficulty;
+	double		work_difficulty;
 
 	blktemplate_t	*tmpl;
 	int		*tmpl_refcount;