Commit 1c456d4fb33bffb14fe38c7024366dbaa7891647

Con Kolivas 2012-11-01T13:53:12

Check for GBT support on first probing the pool and convert to using the GBT request as the rpc request for that pool.

diff --git a/cgminer.c b/cgminer.c
index c681294..2055db6 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -407,7 +407,7 @@ static void sharelog(const char*disposition, const struct work*work)
 
 static char *getwork_req = "{\"method\": \"getwork\", \"params\": [], \"id\":0}\n";
 
-// static char *gbt_req = "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"]}]}\n";
+static char *gbt_req = "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"]}]}\n";
 
 /* Return value is ignored if not called from add_pool_details */
 struct pool *add_pool(void)
@@ -4441,6 +4441,21 @@ retry_stratum:
 		return false;
 	}
 
+	/* Probe for GBT support on first pass */
+	if (!pool->probed && !opt_fix_protocol) {
+		applog(LOG_DEBUG, "Probing for GBT support");
+		val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass,
+				    gbt_req, true, false, &rolltime, pool, false);
+		if (val) {
+			pool->has_gbt = true;
+			pool->rpc_req = gbt_req;
+			applog(LOG_DEBUG, "GBT support found, switching to GBT protocol");
+			json_decref(val);
+		} else
+			applog(LOG_DEBUG, "No GBT support found, using getwork protocol");
+		pool->probed = false;
+	}
+
 	gettimeofday(&tv_getwork, NULL);
 	val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass,
 			    pool->rpc_req, true, false, &rolltime, pool, false);
diff --git a/miner.h b/miner.h
index 85111e6..70cbfdf 100644
--- a/miner.h
+++ b/miner.h
@@ -883,6 +883,9 @@ struct pool {
 	struct stratum_work swork;
 	pthread_t stratum_thread;
 	pthread_mutex_t stratum_lock;
+
+	/* GBT  variables */
+	bool has_gbt;
 };
 
 #define GETWORK_MODE_TESTPOOL 'T'