Browse Source

Merge commit '662ab1e' into stratum

Luke Dashjr 13 years ago
parent
commit
228bc6ca1c
2 changed files with 34 additions and 7 deletions
  1. 30 6
      miner.c
  2. 4 1
      util.c

+ 30 - 6
miner.c

@@ -3158,18 +3158,28 @@ static void gen_stratum_work(struct pool *pool, struct work *work);
 static void *get_work_thread(void *userdata)
 static void *get_work_thread(void *userdata)
 {
 {
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
-	struct pool *pool = current_pool();
 	struct work *ret_work= NULL;
 	struct work *ret_work= NULL;
 	struct curl_ent *ce = NULL;
 	struct curl_ent *ce = NULL;
+	struct pool *pool;
 
 
 	pthread_detach(pthread_self());
 	pthread_detach(pthread_self());
 	rename_thr("bfg-get_work");
 	rename_thr("bfg-get_work");
 
 
 	applog(LOG_DEBUG, "Creating extra get work thread");
 	applog(LOG_DEBUG, "Creating extra get work thread");
 
 
+retry:
 	pool = wc->pool;
 	pool = wc->pool;
 
 
 	if (pool->has_stratum) {
 	if (pool->has_stratum) {
+		while (!pool->stratum_active) {
+			struct pool *altpool = select_pool(true);
+
+			if (altpool != pool) {
+				wc->pool = altpool;
+				goto retry;
+			}
+			sleep(5);
+		}
 		ret_work = make_work();
 		ret_work = make_work();
 		gen_stratum_work(pool, ret_work);
 		gen_stratum_work(pool, ret_work);
 		if (unlikely(!stage_work(ret_work))) {
 		if (unlikely(!stage_work(ret_work))) {
@@ -4989,24 +4999,28 @@ static void *stratum_thread(void *userdata)
 		 * every minute so if we fail to receive any for 2 minutes we
 		 * every minute so if we fail to receive any for 2 minutes we
 		 * assume the connection has been dropped and treat this pool
 		 * assume the connection has been dropped and treat this pool
 		 * as dead */
 		 * as dead */
-		if (select(pool->sock + 1, &rd, NULL, NULL, &timeout) < 1) {
+		select(pool->sock + 1, &rd, NULL, NULL, &timeout);
+		s = recv_line(pool);
+		if (!s) {
 			applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no);
 			applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no);
 			pool->getfail_occasions++;
 			pool->getfail_occasions++;
 			total_go++;
 			total_go++;
 
 
+			pool->stratum_active = false;
+			if (initiate_stratum(pool) && auth_stratum(pool))
+				continue;
+
 			pool_died(pool);
 			pool_died(pool);
 			while (!initiate_stratum(pool) || !auth_stratum(pool)) {
 			while (!initiate_stratum(pool) || !auth_stratum(pool)) {
 				if (pool->removed)
 				if (pool->removed)
 					goto out;
 					goto out;
-				sleep(5);
+				sleep(30);
 			}
 			}
 			applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
 			applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
 			pool_resus(pool);
 			pool_resus(pool);
 			continue;
 			continue;
 		}
 		}
-		s = recv_line(pool);
-		if (unlikely(!s))
-			continue;
+
 		if (!parse_method(pool, s) && !parse_stratum_response(s))
 		if (!parse_method(pool, s) && !parse_stratum_response(s))
 			applog(LOG_INFO, "Unknown stratum msg: %s", s);
 			applog(LOG_INFO, "Unknown stratum msg: %s", s);
 		free(s);
 		free(s);
@@ -5325,6 +5339,8 @@ static struct work *hash_pop(const struct timespec *abstime)
 static bool reuse_work(struct work *work, struct pool *pool)
 static bool reuse_work(struct work *work, struct pool *pool)
 {
 {
 	if (pool->has_stratum) {
 	if (pool->has_stratum) {
+		if (!pool->stratum_active)
+			return false;
 		applog(LOG_DEBUG, "Reusing stratum work");
 		applog(LOG_DEBUG, "Reusing stratum work");
 		gen_stratum_work(pool, work);;
 		gen_stratum_work(pool, work);;
 		return true;
 		return true;
@@ -5496,6 +5512,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 
 
 	set_work_target(work, work->sdiff);
 	set_work_target(work, work->sdiff);
 
 
+	local_work++;
 	work->pool = pool;
 	work->pool = pool;
 	work->stratum = true;
 	work->stratum = true;
 	work->blk.nonce = 0;
 	work->blk.nonce = 0;
@@ -5529,6 +5546,13 @@ retry:
 	if (reuse_work(work, pool))
 	if (reuse_work(work, pool))
 		goto out;
 		goto out;
 
 
+	/* If we were unable to reuse work from a stratum pool, it implies the
+	 * pool is inactive and unless we have another pool to grab work from
+	 * we can only wait till it comes alive or another pool comes online */
+	if (pool->has_stratum) {
+		sleep(5);
+		goto retry;
+	}
 	if (!pool->lagging && !total_staged() && global_queued() >= mining_threads + opt_queue) {
 	if (!pool->lagging && !total_staged() && global_queued() >= mining_threads + opt_queue) {
 		struct cgpu_info *cgpu = thr->cgpu;
 		struct cgpu_info *cgpu = thr->cgpu;
 		bool stalled = true;
 		bool stalled = true;

+ 4 - 1
util.c

@@ -1081,6 +1081,9 @@ bool parse_method(struct pool *pool, char *s)
 	bool ret = false;
 	bool ret = false;
 	char *buf;
 	char *buf;
 
 
+	if (!s)
+		goto out;
+
 	val = JSON_LOADS(s, &err);
 	val = JSON_LOADS(s, &err);
 	if (!val) {
 	if (!val) {
 		applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
 		applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
@@ -1144,7 +1147,7 @@ bool auth_stratum(struct pool *pool)
 		sret = recv_line(pool);
 		sret = recv_line(pool);
 		if (!parse_method(pool, sret)) {
 		if (!parse_method(pool, sret)) {
 			clear_sock(pool);
 			clear_sock(pool);
-			applog(LOG_WARNING, "Failed to parse stratum buffer");
+			applog(LOG_INFO, "Failed to parse stratum buffer");
 			free(sret);
 			free(sret);
 			return ret;
 			return ret;
 		}
 		}