Browse Source

Merge commit '7a01578' into stratum

Conflicts:
	miner.c
Luke Dashjr 13 years ago
parent
commit
8cfe715515
2 changed files with 17 additions and 9 deletions
  1. 15 8
      miner.c
  2. 2 1
      util.c

+ 15 - 8
miner.c

@@ -5032,6 +5032,18 @@ static void init_stratum_thread(struct pool *pool)
 
 static void *longpoll_thread(void *userdata);
 
+static bool stratum_works(struct pool *pool)
+{
+	applog(LOG_INFO, "Testing pool %d stratum %s", pool->pool_no, pool->stratum_url);
+	if (!extract_sockaddr(pool, pool->stratum_url))
+		return false;
+
+	if (!initiate_stratum(pool))
+		return false;
+
+	return true;
+}
+
 // NOTE: This assumes reference URI is a root
 static char *absolute_uri(char *uri, const char *ref)
 {
@@ -5107,18 +5119,13 @@ tryagain:
 	gettimeofday(&tv_getwork_reply, NULL);
 
 	/* Detect if a http getwork pool has an X-Stratum header at startup,
-	 * and if so, switch to that in preference to getwork. Currently no
-	 * proxy support so don't try to switch if a proxy is in use. */
-	if (unlikely(pool->stratum_url)) {
+	 * and if so, switch to that in preference to getwork if it works */
+	if (pool->stratum_url && stratum_works(pool)) {
 		applog(LOG_NOTICE, "Switching pool %d %s to %s", pool->pool_no, pool->rpc_url, pool->stratum_url);
 		pool->has_stratum = true;
-		pool->rpc_url = pool->stratum_url;
-		/* pool->stratum_url will be set again in extract_sockaddr */
-		pool->stratum_url = NULL;
-		extract_sockaddr(pool, pool->rpc_url);
 		curl_easy_cleanup(curl);
 
-		goto  retry_stratum;
+		goto retry_stratum;
 	}
 
 	if (val) {

+ 2 - 1
util.c

@@ -1287,7 +1287,8 @@ out:
 		json_decref(val);
 
 	if (ret) {
-		pool->stratum_url = pool->sockaddr_url;
+		if (!pool->stratum_url)
+			pool->stratum_url = pool->sockaddr_url;
 		pool->stratum_active = true;
 		pool->swork.diff = 1;
 		if (opt_protocol) {