Browse Source

Merge branch 'cg_merges_20121115' into bfgminer

Luke Dashjr 13 years ago
parent
commit
325d51c641
4 changed files with 49 additions and 32 deletions
  1. 11 0
      NEWS
  2. 7 3
      driver-cpu.c
  3. 31 28
      miner.c
  4. 0 1
      miner.h

+ 11 - 0
NEWS

@@ -1,3 +1,14 @@
+BFGMiner Version 2.10.0 - Future
+
+- Use stratum block change from backup pools as an alternative to longpoll for
+pools that don't support LP.
+- Round some more static string arrays to 4 byte boundaries.
+- There is no need for the static arrays to be larger than required, so long as
+they're 4 byte aligned to appease ARM.
+- Hash1 is only used by the CPU mining code and never changes so remove it from
+the work struct and bypass needing to process the value for all other mining.
+
+
 BFGMiner Version 2.9.3 - November 16, 2012
 BFGMiner Version 2.9.3 - November 16, 2012
 
 
 - Bugfix: Properly process new stratum jobs through test_work_current, even if
 - Bugfix: Properly process new stratum jobs through test_work_current, even if

+ 7 - 3
driver-cpu.c

@@ -226,6 +226,7 @@ double bench_algo_stage3(
 	// Use a random work block pulled from a pool
 	// Use a random work block pulled from a pool
 	static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK };
 	static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK };
 	struct work work __attribute__((aligned(128)));
 	struct work work __attribute__((aligned(128)));
+	unsigned char hash1[64];
 
 
 	size_t bench_size = sizeof(work);
 	size_t bench_size = sizeof(work);
 	size_t work_size = sizeof(bench_block);
 	size_t work_size = sizeof(bench_block);
@@ -240,6 +241,8 @@ double bench_algo_stage3(
 	uint32_t max_nonce = (1<<22);
 	uint32_t max_nonce = (1<<22);
 	uint32_t last_nonce = 0;
 	uint32_t last_nonce = 0;
 
 
+	hex2bin(hash1, "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000", 64);
+
 	gettimeofday(&start, 0);
 	gettimeofday(&start, 0);
 			{
 			{
 				sha256_func func = sha256_funcs[algo];
 				sha256_func func = sha256_funcs[algo];
@@ -247,7 +250,7 @@ double bench_algo_stage3(
 					&dummy,
 					&dummy,
 					work.midstate,
 					work.midstate,
 					work.data,
 					work.data,
-					work.hash1,
+					hash1,
 					work.hash,
 					work.hash,
 					work.target,
 					work.target,
 					max_nonce,
 					max_nonce,
@@ -806,11 +809,12 @@ static bool cpu_thread_init(struct thr_info *thr)
 static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce)
 static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce)
 {
 {
 	const int thr_id = thr->id;
 	const int thr_id = thr->id;
-
+	unsigned char hash1[64];
 	uint32_t first_nonce = work->blk.nonce;
 	uint32_t first_nonce = work->blk.nonce;
 	uint32_t last_nonce;
 	uint32_t last_nonce;
 	bool rc;
 	bool rc;
 
 
+	hex2bin(hash1, "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000", 64);
 CPUSearch:
 CPUSearch:
 	last_nonce = first_nonce;
 	last_nonce = first_nonce;
 	rc = false;
 	rc = false;
@@ -822,7 +826,7 @@ CPUSearch:
 			thr,
 			thr,
 			work->midstate,
 			work->midstate,
 			work->data,
 			work->data,
-			work->hash1,
+			hash1,
 			work->hash,
 			work->hash,
 			work->target,
 			work->target,
 			max_nonce,
 			max_nonce,

+ 31 - 28
miner.c

@@ -97,7 +97,7 @@ struct strategies strategies[] = {
 	{ "Balance" },
 	{ "Balance" },
 };
 };
 
 
-static char packagename[255];
+static char packagename[256];
 
 
 bool opt_protocol;
 bool opt_protocol;
 static bool opt_benchmark;
 static bool opt_benchmark;
@@ -260,7 +260,7 @@ static char *current_hash;
 static uint32_t current_block_id;
 static uint32_t current_block_id;
 char *current_fullhash;
 char *current_fullhash;
 static char datestamp[40];
 static char datestamp[40];
-static char blocktime[30];
+static char blocktime[32];
 struct timeval block_timeval;
 struct timeval block_timeval;
 static char best_share[8] = "0";
 static char best_share[8] = "0";
 static uint64_t best_diff = 0;
 static uint64_t best_diff = 0;
@@ -1731,11 +1731,6 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 		calc_midstate(work);
 		calc_midstate(work);
 	}
 	}
 
 
-	if (!jobj_binary(res_val, "hash1", work->hash1, sizeof(work->hash1), false)) {
-		// Always the same anyway
-		memcpy(work->hash1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0", 64);
-	}
-
 	if (unlikely(!jobj_binary(res_val, "target", work->target, sizeof(work->target), true))) {
 	if (unlikely(!jobj_binary(res_val, "target", work->target, sizeof(work->target), true))) {
 		applog(LOG_ERR, "JSON inval target");
 		applog(LOG_ERR, "JSON inval target");
 		return false;
 		return false;
@@ -2030,7 +2025,7 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
 static void text_print_status(int thr_id)
 static void text_print_status(int thr_id)
 {
 {
 	struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
 	struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
-	char logline[255];
+	char logline[256];
 
 
 	if (cgpu) {
 	if (cgpu) {
 		get_statline(logline, cgpu);
 		get_statline(logline, cgpu);
@@ -2107,7 +2102,7 @@ static void curses_print_devstatus(int thr_id)
 {
 {
 	static int awidth = 1, rwidth = 1, hwwidth = 1, uwidth = 1;
 	static int awidth = 1, rwidth = 1, hwwidth = 1, uwidth = 1;
 	struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
 	struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
-	char logline[255];
+	char logline[256];
 	char cHr[h2bs_fmt_size[H2B_NOUNIT]], aHr[h2bs_fmt_size[H2B_NOUNIT]], uHr[h2bs_fmt_size[H2B_SHORT]];
 	char cHr[h2bs_fmt_size[H2B_NOUNIT]], aHr[h2bs_fmt_size[H2B_NOUNIT]], uHr[h2bs_fmt_size[H2B_SHORT]];
 	int ypos;
 	int ypos;
 
 
@@ -2449,7 +2444,7 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
 		pool->seq_rejects++;
 		pool->seq_rejects++;
 		applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
 		applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
 		if (!QUIET) {
 		if (!QUIET) {
-			char where[17];
+			char where[20];
 			char disposition[36] = "reject";
 			char disposition[36] = "reject";
 			char reason[32];
 			char reason[32];
 
 
@@ -2513,7 +2508,7 @@ static const uint64_t diffone = 0xFFFF000000000000ull;
 static uint64_t share_diff(const struct work *work)
 static uint64_t share_diff(const struct work *work)
 {
 {
 	uint64_t *data64, d64;
 	uint64_t *data64, d64;
-	char rhash[36];
+	char rhash[32];
 	uint64_t ret;
 	uint64_t ret;
 
 
 	swab256(rhash, work->hash);
 	swab256(rhash, work->hash);
@@ -2556,7 +2551,7 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
 	int rolltime;
 	int rolltime;
 	uint32_t *hash32;
 	uint32_t *hash32;
 	struct timeval tv_submit, tv_submit_reply;
 	struct timeval tv_submit, tv_submit_reply;
-	char hashshow[64 + 1] = "";
+	char hashshow[64 + 4] = "";
 	char worktime[200] = "";
 	char worktime[200] = "";
 
 
 	if (work->tmpl) {
 	if (work->tmpl) {
@@ -2678,7 +2673,7 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
 	if (!opt_realquiet)
 	if (!opt_realquiet)
 		print_status(thr_id);
 		print_status(thr_id);
 	if (!want_per_device_stats) {
 	if (!want_per_device_stats) {
-		char logline[255];
+		char logline[256];
 
 
 		get_statline(logline, cgpu);
 		get_statline(logline, cgpu);
 		applog(LOG_INFO, "%s", logline);
 		applog(LOG_INFO, "%s", logline);
@@ -2756,7 +2751,7 @@ static void calc_diff(struct work *work, int known)
 
 
 	if (opt_scrypt) {
 	if (opt_scrypt) {
 		uint64_t *data64, d64;
 		uint64_t *data64, d64;
-		char rtarget[36];
+		char rtarget[32];
 
 
 		swab256(rtarget, work->target);
 		swab256(rtarget, work->target);
 		data64 = (uint64_t *)(rtarget + 2);
 		data64 = (uint64_t *)(rtarget + 2);
@@ -5906,7 +5901,7 @@ static struct work *clone_work(struct work *work)
 
 
 static void gen_hash(unsigned char *data, unsigned char *hash, int len)
 static void gen_hash(unsigned char *data, unsigned char *hash, int len)
 {
 {
-	unsigned char hash1[36];
+	unsigned char hash1[32];
 
 
 	sha2(data, len, hash1, false);
 	sha2(data, len, hash1, false);
 	sha2(hash1, 32, hash, false);
 	sha2(hash1, 32, hash, false);
@@ -5918,7 +5913,7 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
  * cover a huge range of difficulty targets, though not all 256 bits' worth */
  * cover a huge range of difficulty targets, though not all 256 bits' worth */
 static void set_work_target(struct work *work, double diff)
 static void set_work_target(struct work *work, double diff)
 {
 {
-	unsigned char rtarget[36], target[36];
+	unsigned char rtarget[32], target[32];
 	double d64;
 	double d64;
 	uint64_t *data64, h64;
 	uint64_t *data64, h64;
 
 
@@ -5952,9 +5947,9 @@ static void set_work_target(struct work *work, double diff)
  * other means to detect when the pool has died in stratum_thread */
  * other means to detect when the pool has died in stratum_thread */
 static void gen_stratum_work(struct pool *pool, struct work *work)
 static void gen_stratum_work(struct pool *pool, struct work *work)
 {
 {
-	unsigned char *coinbase, merkle_root[36], merkle_sha[68], *merkle_hash;
-	char header[260], hash1[132], *nonce2;
+	unsigned char *coinbase, merkle_root[32], merkle_sha[64], *merkle_hash;
 	int len, cb1_len, n1_len, cb2_len, i;
 	int len, cb1_len, n1_len, cb2_len, i;
+	char header[260], *nonce2;
 	uint32_t *data32, *swap32;
 	uint32_t *data32, *swap32;
 
 
 	memset(work->job_id, 0, 64);
 	memset(work->job_id, 0, 64);
@@ -5980,7 +5975,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	gen_hash(coinbase, merkle_root, len);
 	gen_hash(coinbase, merkle_root, len);
 	memcpy(merkle_sha, merkle_root, 32);
 	memcpy(merkle_sha, merkle_root, 32);
 	for (i = 0; i < pool->swork.merkles; i++) {
 	for (i = 0; i < pool->swork.merkles; i++) {
-		unsigned char merkle_bin[36];
+		unsigned char merkle_bin[32];
 
 
 		hex2bin(merkle_bin, pool->swork.merkle[i], 32);
 		hex2bin(merkle_bin, pool->swork.merkle[i], 32);
 		memcpy(merkle_sha + 32, merkle_bin, 32);
 		memcpy(merkle_sha + 32, merkle_bin, 32);
@@ -6023,9 +6018,6 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	if (unlikely(!hex2bin(work->data, header, 128)))
 	if (unlikely(!hex2bin(work->data, header, 128)))
 		quit(1, "Failed to convert header to data in gen_stratum_work");
 		quit(1, "Failed to convert header to data in gen_stratum_work");
 	calc_midstate(work);
 	calc_midstate(work);
-	sprintf(hash1, "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000");
-	if (unlikely(!hex2bin(work->hash1, hash1, 64)))
-		quit(1,  "Failed to convert hash1 in gen_stratum_work");
 
 
 	set_work_target(work, work->sdiff);
 	set_work_target(work, work->sdiff);
 
 
@@ -6560,7 +6552,7 @@ static struct pool *select_longpoll_pool(struct pool *cp)
 	for (i = 0; i < total_pools; i++) {
 	for (i = 0; i < total_pools; i++) {
 		struct pool *pool = pools[i];
 		struct pool *pool = pools[i];
 
 
-		if (pool->lp_url)
+		if (pool->has_stratum || pool->lp_url)
 			return pool;
 			return pool;
 	}
 	}
 	return NULL;
 	return NULL;
@@ -6605,19 +6597,25 @@ static void *longpoll_thread(void *userdata)
 	curl = curl_easy_init();
 	curl = curl_easy_init();
 	if (unlikely(!curl)) {
 	if (unlikely(!curl)) {
 		applog(LOG_ERR, "CURL initialisation failed");
 		applog(LOG_ERR, "CURL initialisation failed");
-		goto out;
+		return NULL;
 	}
 	}
 
 
 retry_pool:
 retry_pool:
 	pool = select_longpoll_pool(cp);
 	pool = select_longpoll_pool(cp);
 	if (!pool) {
 	if (!pool) {
-		applog(LOG_WARNING, "No suitable long-poll found for pool %s", cp->rpc_url);
+		applog(LOG_WARNING, "No suitable long-poll found for %s", cp->rpc_url);
 		while (!pool) {
 		while (!pool) {
 			sleep(60);
 			sleep(60);
 			pool = select_longpoll_pool(cp);
 			pool = select_longpoll_pool(cp);
 		}
 		}
 	}
 	}
 
 
+	if (pool->has_stratum) {
+		applog(LOG_WARNING, "Block change for %s detection via %s stratum",
+		       cp->rpc_url, pool->rpc_url);
+		goto out;
+	}
+
 	/* Any longpoll from any pool is enough for this to be true */
 	/* Any longpoll from any pool is enough for this to be true */
 	have_longpoll = true;
 	have_longpoll = true;
 
 
@@ -6628,7 +6626,7 @@ retry_pool:
 		if (cp == pool)
 		if (cp == pool)
 			applog(LOG_WARNING, "Long-polling activated for %s (%s)", lp_url, pool_protocol_name(pool->lp_proto));
 			applog(LOG_WARNING, "Long-polling activated for %s (%s)", lp_url, pool_protocol_name(pool->lp_proto));
 		else
 		else
-			applog(LOG_WARNING, "Long-polling activated for pool %s via %s (%s)", cp->rpc_url, lp_url, pool_protocol_name(pool->lp_proto));
+			applog(LOG_WARNING, "Long-polling activated for %s via %s (%s)", cp->rpc_url, lp_url, pool_protocol_name(pool->lp_proto));
 	}
 	}
 
 
 	while (42) {
 	while (42) {
@@ -6683,8 +6681,14 @@ retry_pool:
 lpfail:
 lpfail:
 			sleep(30);
 			sleep(30);
 		}
 		}
+
 		if (pool != cp) {
 		if (pool != cp) {
 			pool = select_longpoll_pool(cp);
 			pool = select_longpoll_pool(cp);
+			if (pool->has_stratum) {
+				applog(LOG_WARNING, "Block change for %s detection via %s stratum",
+				       cp->rpc_url, pool->rpc_url);
+				break;
+			}
 			if (unlikely(!pool))
 			if (unlikely(!pool))
 				goto retry_pool;
 				goto retry_pool;
 		}
 		}
@@ -6694,8 +6698,7 @@ lpfail:
 	}
 	}
 
 
 out:
 out:
-	if (curl)
-		curl_easy_cleanup(curl);
+	curl_easy_cleanup(curl);
 
 
 	return NULL;
 	return NULL;
 }
 }

+ 0 - 1
miner.h

@@ -1005,7 +1005,6 @@ struct pool {
 
 
 struct work {
 struct work {
 	unsigned char	data[128];
 	unsigned char	data[128];
-	unsigned char	hash1[64];
 	unsigned char	midstate[32];
 	unsigned char	midstate[32];
 	unsigned char	target[32];
 	unsigned char	target[32];
 	unsigned char	hash[32];
 	unsigned char	hash[32];