Browse Source

Bugfix: avalon2: Maintain our own jobid by just incrementing

Luke Dashjr 12 years ago
parent
commit
016e02b30d
2 changed files with 10 additions and 24 deletions
  1. 9 24
      driver-avalonmm.c
  2. 1 0
      driver-avalonmm.h

+ 9 - 24
driver-avalonmm.c

@@ -146,16 +146,6 @@ static int avalon2_init_pkg(struct avalon2_pkg *pkg, uint8_t type, uint8_t idx,
 	return 0;
 	return 0;
 }
 }
 
 
-static int job_idcmp(uint8_t *job_id, char *pool_job_id)
-{
-	int i = 0;
-	for (i = 0; i < 4; i++) {
-		if (job_id[i] != *(pool_job_id + strlen(pool_job_id) - 4 + i))
-			return 1;
-	}
-	return 0;
-}
-
 static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg)
 static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg)
 {
 {
 	struct cgpu_info *avalon2 = NULL;
 	struct cgpu_info *avalon2 = NULL;
@@ -166,7 +156,7 @@ static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg
 	uint32_t nonce, nonce2, miner, modular_id;
 	uint32_t nonce, nonce2, miner, modular_id;
 	void *xnonce2;
 	void *xnonce2;
 	int pool_no;
 	int pool_no;
-	uint8_t job_id[5];
+	uint32_t jobid;
 	int tmp;
 	int tmp;
 
 
 	int type = AVA2_GETS_ERROR;
 	int type = AVA2_GETS_ERROR;
@@ -202,8 +192,7 @@ static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg
 			memcpy(&nonce2, ar->data + 8, 4);
 			memcpy(&nonce2, ar->data + 8, 4);
 			/* Calc time    ar->data + 12 */
 			/* Calc time    ar->data + 12 */
 			memcpy(&nonce, ar->data + 16, 4);
 			memcpy(&nonce, ar->data + 16, 4);
-			memset(job_id, 0, 5);
-			memcpy(job_id, ar->data + 20, 4);
+			memcpy(&jobid, ar->data + 20, sizeof(jobid));
 
 
 			miner = be32toh(miner);
 			miner = be32toh(miner);
 			pool_no = be32toh(pool_no);
 			pool_no = be32toh(pool_no);
@@ -220,9 +209,9 @@ static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg
 			nonce = be32toh(nonce);
 			nonce = be32toh(nonce);
 			nonce -= 0x180;
 			nonce -= 0x180;
 
 
-			applog(LOG_DEBUG, "Avalon2: Found! [%s] %d:(%08x) (%08x)",
-			       job_id, pool_no, nonce2, nonce);
-			if (job_idcmp(job_id, info->swork.job_id))
+			applog(LOG_DEBUG, "Avalon2: Found! [%08lx] %d:(%08x) (%08x)",
+			       (unsigned long)jobid, pool_no, nonce2, nonce);
+			if (jobid != info->jobid)
 				break;
 				break;
 
 
 			if (thr && !info->new_stratum)
 			if (thr && !info->new_stratum)
@@ -376,7 +365,6 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 	struct avalon2_pkg pkg;
 	struct avalon2_pkg pkg;
 	int i, a, b, tmp;
 	int i, a, b, tmp;
 	unsigned char target[32];
 	unsigned char target[32];
-	int job_id_len;
 	const size_t xnonce2_offset = pool->swork.nonce2_offset + work2d_pad_xnonce_size(swork) + work2d_xnonce1sz;
 	const size_t xnonce2_offset = pool->swork.nonce2_offset + work2d_pad_xnonce_size(swork) + work2d_xnonce1sz;
 	bytes_t coinbase = BYTES_INIT;
 	bytes_t coinbase = BYTES_INIT;
 
 
@@ -426,15 +414,12 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 		;
 		;
 
 
 
 
-	applog(LOG_DEBUG, "Avalon2: Pool stratum message JOBS_ID: %s",
-	       pool->swork.job_id);
+	++info->jobid;
+	applog(LOG_DEBUG, "Avalon2: Pool stratum message JOBS_ID: %08lx",
+	       (unsigned long)info->jobid);
 	memset(pkg.data, 0, AVA2_P_DATA_LEN);
 	memset(pkg.data, 0, AVA2_P_DATA_LEN);
 
 
-	job_id_len = strlen(pool->swork.job_id);
-	job_id_len = job_id_len >= 4 ? 4 : job_id_len;
-	for (i = 0; i < job_id_len; i++) {
-		pkg.data[i] = *(pool->swork.job_id + strlen(pool->swork.job_id) - 4 + i);
-	}
+	memcpy(pkg.data, &info->jobid, sizeof(info->jobid));
 	avalon2_init_pkg(&pkg, AVA2_P_JOB_ID, 1, 1);
 	avalon2_init_pkg(&pkg, AVA2_P_JOB_ID, 1, 1);
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		;
 		;

+ 1 - 0
driver-avalonmm.h

@@ -114,6 +114,7 @@ struct avalon2_info {
 	int modulars[AVA2_DEFAULT_MODULARS];
 	int modulars[AVA2_DEFAULT_MODULARS];
 	char mm_version[AVA2_DEFAULT_MODULARS][16];
 	char mm_version[AVA2_DEFAULT_MODULARS][16];
 	
 	
+	uint32_t jobid;
 	struct timeval tv_prepared;
 	struct timeval tv_prepared;
 	struct stratum_work swork;
 	struct stratum_work swork;
 };
 };