Browse Source

Do not try to generate stratum work unless the notify command has succeeded.

Conflicts:

	miner.c
	util.c
Con Kolivas 13 years ago
parent
commit
c352a42612
3 changed files with 26 additions and 10 deletions
  1. 10 4
      miner.c
  2. 1 0
      miner.h
  3. 15 6
      util.c

+ 10 - 4
miner.c

@@ -5467,6 +5467,15 @@ static void clear_pool_work(struct pool *pool)
 	mutex_unlock(stgd_lock);
 	mutex_unlock(stgd_lock);
 }
 }
 
 
+static void stratum_resumed(struct pool *pool)
+{
+	if (!pool->stratum_notify)
+		return;
+	applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
+	pool_tclear(pool, &pool->idle);
+	pool_resus(pool);
+}
+
 /* One stratum thread per pool that has stratum waits on the socket checking
 /* One stratum thread per pool that has stratum waits on the socket checking
  * for new messages and for the integrity of the socket connection. We reset
  * for new messages and for the integrity of the socket connection. We reset
  * the connection based on the integrity of the receive side only as the send
  * the connection based on the integrity of the receive side only as the send
@@ -5528,10 +5537,7 @@ static void *stratum_thread(void *userdata)
 
 
 		/* Check this pool hasn't died while being a backup pool and
 		/* Check this pool hasn't died while being a backup pool and
 		 * has not had its idle flag cleared */
 		 * has not had its idle flag cleared */
-		if (pool_tclear(pool, &pool->idle)) {
-			applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
-			pool_resus(pool);
-		}
+		stratum_resumed(pool);
 
 
 		if (!parse_method(pool, s) && !parse_stratum_response(pool, s))
 		if (!parse_method(pool, s) && !parse_stratum_response(pool, s))
 			applog(LOG_INFO, "Unknown stratum msg: %s", s);
 			applog(LOG_INFO, "Unknown stratum msg: %s", s);

+ 1 - 0
miner.h

@@ -979,6 +979,7 @@ struct pool {
 	bool has_stratum;
 	bool has_stratum;
 	bool stratum_active;
 	bool stratum_active;
 	bool stratum_auth;
 	bool stratum_auth;
+	bool stratum_notify;
 	struct stratum_work swork;
 	struct stratum_work swork;
 	pthread_t stratum_thread;
 	pthread_t stratum_thread;
 	pthread_mutex_t stratum_lock;
 	pthread_mutex_t stratum_lock;

+ 15 - 6
util.c

@@ -1027,13 +1027,13 @@ static char *json_array_string(json_t *val, unsigned int entry)
 static bool parse_notify(struct pool *pool, json_t *val)
 static bool parse_notify(struct pool *pool, json_t *val)
 {
 {
 	char *job_id, *prev_hash, *coinbase1, *coinbase2, *bbversion, *nbit, *ntime;
 	char *job_id, *prev_hash, *coinbase1, *coinbase2, *bbversion, *nbit, *ntime;
+	bool clean, ret = false;
 	int merkles, i;
 	int merkles, i;
 	json_t *arr;
 	json_t *arr;
-	bool clean;
 
 
 	arr = json_array_get(val, 4);
 	arr = json_array_get(val, 4);
 	if (!arr || !json_is_array(arr))
 	if (!arr || !json_is_array(arr))
-		return false;
+		goto out;
 
 
 	merkles = json_array_size(arr);
 	merkles = json_array_size(arr);
 
 
@@ -1062,7 +1062,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 			free(nbit);
 			free(nbit);
 		if (ntime)
 		if (ntime)
 			free(ntime);
 			free(ntime);
-		return false;
+		goto out;
 	}
 	}
 
 
 	mutex_lock(&pool->pool_lock);
 	mutex_lock(&pool->pool_lock);
@@ -1125,7 +1125,9 @@ static bool parse_notify(struct pool *pool, json_t *val)
 			pool->swork.transparency_time = time(NULL);
 			pool->swork.transparency_time = time(NULL);
 	}
 	}
 
 
-	return true;
+	ret = true;
+out:
+	return ret;
 }
 }
 
 
 static bool parse_diff(struct pool *pool, json_t *val)
 static bool parse_diff(struct pool *pool, json_t *val)
@@ -1229,8 +1231,11 @@ bool parse_method(struct pool *pool, char *s)
 	if (!buf)
 	if (!buf)
 		goto out;
 		goto out;
 
 
-	if (!strncasecmp(buf, "mining.notify", 13) && parse_notify(pool, params)) {
-		ret = true;
+	if (!strncasecmp(buf, "mining.notify", 13)) {
+		if (parse_notify(pool, params))
+			pool->stratum_notify = ret = true;
+		else
+			pool->stratum_notify = ret = false;
 		goto out;
 		goto out;
 	}
 	}
 
 
@@ -1298,6 +1303,10 @@ bool auth_stratum(struct pool *pool)
 
 
 		goto out;
 		goto out;
 	}
 	}
+
+	if (!pool->stratum_notify)
+		goto out;
+
 	ret = true;
 	ret = true;
 	applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
 	applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
 	pool->stratum_auth = true;
 	pool->stratum_auth = true;