Browse Source

Merge commit 'ee83228' into bfgminer

Luke Dashjr 10 years ago
parent
commit
93b5716f0b
2 changed files with 21 additions and 6 deletions
  1. 19 6
      miner.c
  2. 2 0
      work2d.c

+ 19 - 6
miner.c

@@ -3443,7 +3443,7 @@ void refresh_bitcoind_address(struct mining_goal_info * const goal, const bool f
 
 
 #define GBT_XNONCESZ (sizeof(uint32_t))
 #define GBT_XNONCESZ (sizeof(uint32_t))
 
 
-#if BLKMAKER_VERSION > 4
+#if BLKMAKER_VERSION > 6
 #define blkmk_append_coinbase_safe(tmpl, append, appendsz)  \
 #define blkmk_append_coinbase_safe(tmpl, append, appendsz)  \
        blkmk_append_coinbase_safe2(tmpl, append, appendsz, GBT_XNONCESZ, false)
        blkmk_append_coinbase_safe2(tmpl, append, appendsz, GBT_XNONCESZ, false)
 #endif
 #endif
@@ -3624,7 +3624,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 
 
 	work->tv_staged = tv_now;
 	work->tv_staged = tv_now;
 	
 	
-#if BLKMAKER_VERSION > 4
+#if BLKMAKER_VERSION > 6
 	if (work->tr)
 	if (work->tr)
 	{
 	{
 		blktemplate_t * const tmpl = work->tr->tmpl;
 		blktemplate_t * const tmpl = work->tr->tmpl;
@@ -3644,15 +3644,18 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 			pool_check_coinbase(pool, cbtxn, cbtxnsz);
 			pool_check_coinbase(pool, cbtxn, cbtxnsz);
 			
 			
 			cg_wlock(&pool->data_lock);
 			cg_wlock(&pool->data_lock);
+			if (swork->tr)
+				tmpl_decref(swork->tr);
 			swork->tr = work->tr;
 			swork->tr = work->tr;
+			tmpl_incref(swork->tr);
 			bytes_assimilate_raw(&swork->coinbase, cbtxn, cbtxnsz, cbtxnsz);
 			bytes_assimilate_raw(&swork->coinbase, cbtxn, cbtxnsz, cbtxnsz);
 			swork->nonce2_offset = cbextranonceoffset;
 			swork->nonce2_offset = cbextranonceoffset;
 			bytes_assimilate_raw(&swork->merkle_bin, branches, branchdatasz, branchdatasz);
 			bytes_assimilate_raw(&swork->merkle_bin, branches, branchdatasz, branchdatasz);
 			swork->merkles = branchcount;
 			swork->merkles = branchcount;
-			memcpy(swork->header1, &buf[0], 36);
+			swap32yes(swork->header1, &buf[0], 36 / 4);
 			swork->ntime = le32toh(*(uint32_t *)(&buf[68]));
 			swork->ntime = le32toh(*(uint32_t *)(&buf[68]));
 			swork->tv_received = tv_now;
 			swork->tv_received = tv_now;
-			memcpy(swork->diffbits, &buf[72], 4);
+			swap32yes(swork->diffbits, &buf[72], 4 / 4);
 			memcpy(swork->target, work->target, sizeof(swork->target));
 			memcpy(swork->target, work->target, sizeof(swork->target));
 			free(swork->job_id);
 			free(swork->job_id);
 			swork->job_id = NULL;
 			swork->job_id = NULL;
@@ -3666,7 +3669,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 		else
 		else
 			applog(LOG_DEBUG, "blkmk_get_mdata failed for pool %u", pool->pool_no);
 			applog(LOG_DEBUG, "blkmk_get_mdata failed for pool %u", pool->pool_no);
 	}
 	}
-#endif  // BLKMAKER_VERSION > 4
+#endif  // BLKMAKER_VERSION > 6
 	pool_set_opaque(pool, !work->tr);
 	pool_set_opaque(pool, !work->tr);
 
 
 	ret = true;
 	ret = true;
@@ -5346,6 +5349,11 @@ static char *submit_upstream_work_request(struct work *work)
 		unsigned char data[80];
 		unsigned char data[80];
 		
 		
 		swap32yes(data, work->data, 80 / 4);
 		swap32yes(data, work->data, 80 / 4);
+#if BLKMAKER_VERSION > 6
+		if (work->stratum) {
+			req = blkmk_submitm_jansson(tmpl, data, bytes_buf(&work->nonce2), bytes_len(&work->nonce2), le32toh(*((uint32_t*)&work->data[76])), work->do_foreign_submit);
+		} else
+#endif
 #if BLKMAKER_VERSION > 3
 #if BLKMAKER_VERSION > 3
 		if (work->do_foreign_submit)
 		if (work->do_foreign_submit)
 			req = blkmk_submit_foreign_jansson(tmpl, data, work->dataid, le32toh(*((uint32_t*)&work->data[76])));
 			req = blkmk_submit_foreign_jansson(tmpl, data, work->dataid, le32toh(*((uint32_t*)&work->data[76])));
@@ -6780,7 +6788,7 @@ static struct submit_work_state *begin_submission(struct work *work)
 		timer_set_delay_from_now(&sws->tv_staleexpire, 300000000);
 		timer_set_delay_from_now(&sws->tv_staleexpire, 300000000);
 	}
 	}
 
 
-	if (work->stratum) {
+	if (work->getwork_mode == GETWORK_MODE_STRATUM) {
 		char *s;
 		char *s;
 
 
 		s = malloc(1024);
 		s = malloc(1024);
@@ -10383,6 +10391,11 @@ void gen_stratum_work2(struct work *work, struct stratum_work *swork)
 	work->id = total_work++;
 	work->id = total_work++;
 	work->longpoll = false;
 	work->longpoll = false;
 	work->getwork_mode = GETWORK_MODE_STRATUM;
 	work->getwork_mode = GETWORK_MODE_STRATUM;
+	if (swork->tr) {
+		work->getwork_mode = GETWORK_MODE_GBT;
+		work->tr = swork->tr;
+		tmpl_incref(work->tr);
+	}
 	calc_diff(work, 0);
 	calc_diff(work, 0);
 }
 }
 
 

+ 2 - 0
work2d.c

@@ -9,6 +9,7 @@
 
 
 #include "config.h"
 #include "config.h"
 
 
+#include <limits.h>
 #include <stdbool.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <string.h>
 #include <string.h>
@@ -104,6 +105,7 @@ bool work2d_submit_nonce(struct thr_info * const thr, struct stratum_work * cons
 	work2d_gen_dummy_work(work, swork, tvp_prepared, xnonce2, xnonce1);
 	work2d_gen_dummy_work(work, swork, tvp_prepared, xnonce2, xnonce1);
 	*(uint32_t *)&work->data[68] = htobe32(ntime);
 	*(uint32_t *)&work->data[68] = htobe32(ntime);
 	work->nonce_diff = nonce_diff;
 	work->nonce_diff = nonce_diff;
+	work->rolltime = INT_MAX;  // FIXME
 	
 	
 	// Check if it's stale, if desired
 	// Check if it's stale, if desired
 	if (out_is_stale)
 	if (out_is_stale)