Browse Source

Merge commit '1802238' into bfgminer-2.9.x

Luke Dashjr 13 years ago
parent
commit
17c3547b71
4 changed files with 40 additions and 21 deletions
  1. 13 6
      miner.c
  2. 1 0
      miner.h
  3. 25 14
      util.c
  4. 1 1
      util.h

+ 13 - 6
miner.c

@@ -3397,7 +3397,7 @@ retry:
 	pool = wc->pool;
 
 	if (pool->has_stratum) {
-		while (!pool->stratum_active) {
+		while (!pool->stratum_active || !pool->stratum_notify) {
 			struct pool *altpool = select_pool(true);
 
 			sleep(5);
@@ -5467,6 +5467,16 @@ static void clear_pool_work(struct pool *pool)
 	mutex_unlock(stgd_lock);
 }
 
+static void stratum_resumed(struct pool *pool)
+{
+	if (!pool->stratum_notify)
+		return;
+	if (!pool_tclear(pool, &pool->idle))
+		return;
+	applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
+	pool_resus(pool);
+}
+
 /* 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
  * the connection based on the integrity of the receive side only as the send
@@ -5493,7 +5503,7 @@ static void *stratum_thread(void *userdata)
 		/* If we fail to receive any notify messages for 2 minutes we
 		 * assume the connection has been dropped and treat this pool
 		 * as dead */
-		if (!sock_full(pool, false) && select(pool->sock + 1, &rd, NULL, NULL, &timeout) < 1)
+		if (!sock_full(pool) && select(pool->sock + 1, &rd, NULL, NULL, &timeout) < 1)
 			s = NULL;
 		else
 			s = recv_line(pool);
@@ -5528,10 +5538,7 @@ static void *stratum_thread(void *userdata)
 
 		/* Check this pool hasn't died while being a backup pool and
 		 * 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))
 			applog(LOG_INFO, "Unknown stratum msg: %s", s);

+ 1 - 0
miner.h

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

+ 25 - 14
util.c

@@ -921,16 +921,12 @@ static void clear_sock(struct pool *pool)
 	mutex_unlock(&pool->stratum_lock);
 }
 
-/* Check to see if Santa's been good to you */
-bool sock_full(struct pool *pool, bool wait)
+static bool socket_full(struct pool *pool, bool wait)
 {
 	SOCKETTYPE sock = pool->sock;
 	struct timeval timeout;
 	fd_set rd;
 
-	if (pool->readbuf.buf && memchr(pool->readbuf.buf, '\n', pool->readbuf.len))
-		return true;
-
 	FD_ZERO(&rd);
 	FD_SET(sock, &rd);
 	timeout.tv_usec = 0;
@@ -943,6 +939,15 @@ bool sock_full(struct pool *pool, bool wait)
 	return false;
 }
 
+/* Check to see if Santa's been good to you */
+bool sock_full(struct pool *pool)
+{
+	if (pool->readbuf.buf && memchr(pool->readbuf.buf, '\n', pool->readbuf.len))
+		return true;
+
+	return (socket_full(pool, false));
+}
+
 /* Peeks at a socket to find the first end of line and then reads just that
  * from the socket and returns that as a malloced char */
 char *recv_line(struct pool *pool)
@@ -955,8 +960,8 @@ char *recv_line(struct pool *pool)
 		char s[RBUFSIZE];
 		CURLcode rc;
 
-		if (!sock_full(pool, true)) {
-			applog(LOG_DEBUG, "Timed out waiting for data on sock_full");
+		if (!socket_full(pool, true)) {
+			applog(LOG_DEBUG, "Timed out waiting for data on socket_full");
 			goto out;
 		}
 		memset(s, 0, RBUFSIZE);
@@ -1027,13 +1032,13 @@ static char *json_array_string(json_t *val, unsigned int entry)
 static bool parse_notify(struct pool *pool, json_t *val)
 {
 	char *job_id, *prev_hash, *coinbase1, *coinbase2, *bbversion, *nbit, *ntime;
+	bool clean, ret = false;
 	int merkles, i;
 	json_t *arr;
-	bool clean;
 
 	arr = json_array_get(val, 4);
 	if (!arr || !json_is_array(arr))
-		return false;
+		goto out;
 
 	merkles = json_array_size(arr);
 
@@ -1062,7 +1067,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 			free(nbit);
 		if (ntime)
 			free(ntime);
-		return false;
+		goto out;
 	}
 
 	mutex_lock(&pool->pool_lock);
@@ -1125,7 +1130,9 @@ static bool parse_notify(struct pool *pool, json_t *val)
 			pool->swork.transparency_time = time(NULL);
 	}
 
-	return true;
+	ret = true;
+out:
+	return ret;
 }
 
 static bool parse_diff(struct pool *pool, json_t *val)
@@ -1229,8 +1236,11 @@ bool parse_method(struct pool *pool, char *s)
 	if (!buf)
 		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;
 	}
 
@@ -1298,6 +1308,7 @@ bool auth_stratum(struct pool *pool)
 
 		goto out;
 	}
+
 	ret = true;
 	applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
 	pool->stratum_auth = true;
@@ -1363,7 +1374,7 @@ bool initiate_stratum(struct pool *pool)
 		goto out;
 	}
 
-	if (!sock_full(pool, true)) {
+	if (!socket_full(pool, true)) {
 		applog(LOG_DEBUG, "Timed out waiting for response in initiate_stratum");
 		goto out;
 	}

+ 1 - 1
util.h

@@ -44,7 +44,7 @@
 
 struct pool;
 bool stratum_send(struct pool *pool, char *s, ssize_t len);
-bool sock_full(struct pool *pool, bool wait);
+bool sock_full(struct pool *pool);
 char *recv_line(struct pool *pool);
 bool parse_method(struct pool *pool, char *s);
 bool extract_sockaddr(struct pool *pool, char *url);