Browse Source

Move to storing the nonce1 in the work struct instead of the sessionid for the now defunct first draft mining.resume protocol.

Conflicts:
	miner.c
ckolivas 13 years ago
parent
commit
17acca66f5
3 changed files with 13 additions and 107 deletions
  1. 5 7
      miner.c
  2. 1 1
      miner.h
  3. 7 99
      util.c

+ 5 - 7
miner.c

@@ -1742,7 +1742,7 @@ void clean_work(struct work *work)
 	free(work->job_id);
 	free(work->job_id);
 	free(work->nonce2);
 	free(work->nonce2);
 	free(work->ntime);
 	free(work->ntime);
-	free(work->sessionid);
+	free(work->nonce1);
 
 
 	if (work->tmpl) {
 	if (work->tmpl) {
 		struct pool *pool = work->pool;
 		struct pool *pool = work->pool;
@@ -3576,12 +3576,12 @@ void __copy_work(struct work *work, struct work *base_work)
 	work->id = id;
 	work->id = id;
 	if (base_work->job_id)
 	if (base_work->job_id)
 		work->job_id = strdup(base_work->job_id);
 		work->job_id = strdup(base_work->job_id);
+	if (base_work->nonce1)
+		work->nonce1 = strdup(base_work->nonce1);
 	if (base_work->nonce2)
 	if (base_work->nonce2)
 		work->nonce2 = strdup(base_work->nonce2);
 		work->nonce2 = strdup(base_work->nonce2);
 	if (base_work->ntime)
 	if (base_work->ntime)
 		work->ntime = strdup(base_work->ntime);
 		work->ntime = strdup(base_work->ntime);
-	if (base_work->sessionid)
-		work->sessionid = strdup(base_work->sessionid);
 
 
 	if (base_work->tmpl) {
 	if (base_work->tmpl) {
 		struct pool *pool = work->pool;
 		struct pool *pool = work->pool;
@@ -4026,8 +4026,7 @@ static void *submit_work_thread(__maybe_unused void *userdata)
 			bool sessionid_match;
 			bool sessionid_match;
 			
 			
 			mutex_lock(&pool->pool_lock);
 			mutex_lock(&pool->pool_lock);
-			sessionid_match = true;  // FIXME: pool->sessionid && work->sessionid && !strcmp(pool->sessionid, work->sessionid);
-			// FIXME: Above check won't work without sessionid support
+			sessionid_match = !strcmp(work->nonce1, pool->nonce1);
 			mutex_unlock(&pool->pool_lock);
 			mutex_unlock(&pool->pool_lock);
 			if (!sessionid_match)
 			if (!sessionid_match)
 			{
 			{
@@ -6527,9 +6526,8 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 
 
 	/* Copy parameters required for share submission */
 	/* Copy parameters required for share submission */
 	work->job_id = strdup(pool->swork.job_id);
 	work->job_id = strdup(pool->swork.job_id);
+	work->nonce1 = strdup(pool->nonce1);
 	work->ntime = strdup(pool->swork.ntime);
 	work->ntime = strdup(pool->swork.ntime);
-	if (pool->sessionid)
-		work->sessionid = strdup(pool->sessionid);
 	mutex_unlock(&pool->pool_lock);
 	mutex_unlock(&pool->pool_lock);
 
 
 	applog(LOG_DEBUG, "Generated stratum merkle %s", merkle_hash);
 	applog(LOG_DEBUG, "Generated stratum merkle %s", merkle_hash);

+ 1 - 1
miner.h

@@ -1086,7 +1086,7 @@ struct work {
 	char		*nonce2;
 	char		*nonce2;
 	char		*ntime;
 	char		*ntime;
 	double		sdiff;
 	double		sdiff;
-	char		*sessionid;
+	char		*nonce1;
 
 
 	unsigned char	work_restart_id;
 	unsigned char	work_restart_id;
 	int		id;
 	int		id;

+ 7 - 99
util.c

@@ -1637,7 +1637,10 @@ bool initiate_stratum(struct pool *pool)
 	if (!setup_stratum_curl(pool))
 	if (!setup_stratum_curl(pool))
 		goto out;
 		goto out;
 
 
-	sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
+	if (pool->sessionid)
+		sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid);
+	else
+		sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
 
 
 	if (!__stratum_send(pool, s, strlen(s))) {
 	if (!__stratum_send(pool, s, strlen(s))) {
 		applog(LOG_DEBUG, "Failed to send s in initiate_stratum");
 		applog(LOG_DEBUG, "Failed to send s in initiate_stratum");
@@ -1691,7 +1694,7 @@ bool initiate_stratum(struct pool *pool)
 		applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
 		applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
 		goto out;
 		goto out;
 	}
 	}
-	pool->sessionid = json_array_string(res_val, 3);
+	//pool->sessionid = json_array_string(res_val, 3);
 	if (pool->sessionid)
 	if (pool->sessionid)
 		applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);
 		applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);
 	else
 	else
@@ -1723,105 +1726,10 @@ out:
 	return ret;
 	return ret;
 }
 }
 
 
-static void reset_sessionid(struct pool *pool)
-{
-	mutex_lock(&pool->pool_lock);
-	free(pool->sessionid);
-	pool->sessionid = NULL;
-	mutex_unlock(&pool->pool_lock);
-}
-
-/* Placeholder for real resume function in the future */
-static bool resume_stratum(struct pool *pool)
-{
-	json_t *val = NULL, *err_val, *res_val;
-	char s[RBUFSIZE], *sret = NULL;
-	json_error_t err;
-	bool ret = false;
-
-	if (!setup_stratum_curl(pool))
-		goto out;
-
-	mutex_lock(&pool->pool_lock);
-	sprintf(s, "{\"id\": %d, \"method\": \"mining.resume\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid);
-	mutex_unlock(&pool->pool_lock);
-
-	if (!__stratum_send(pool, s, strlen(s))) {
-		applog(LOG_DEBUG, "Failed to send s in resume_stratum");
-		goto out;
-	}
-
-	if (!socket_full(pool, true)) {
-		applog(LOG_DEBUG, "Timed out waiting for response in resume_stratum");
-		goto out;
-	}
-
-	sret = recv_line(pool);
-	if (!sret)
-		goto out;
-
-	val = JSON_LOADS(sret, &err);
-	free(sret);
-	if (!val) {
-		applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
-		goto out;
-	}
-
-	res_val = json_object_get(val, "result");
-	err_val = json_object_get(val, "error");
-
-	/* If there is an error, assume resume support is not there or broken */
-	if (!res_val || json_is_null(res_val) ||
-	    (err_val && !json_is_null(err_val))) {
-		char *ss;
-
-		if (err_val)
-			ss = json_dumps(err_val, JSON_INDENT(3));
-		else
-			ss = strdup("(unknown reason)");
-
-		applog(LOG_INFO, "JSON-RPC decode failed: %s", ss);
-
-		free(ss);
-
-		reset_sessionid(pool);
-		goto out;
-	}
-
-	if (json_is_true(res_val)) {
-		applog(LOG_NOTICE, "Resumed stratum connection to pool %d", pool->pool_no);
-		pool->stratum_active = true;
-		ret = true;
-	} else {
-		applog(LOG_NOTICE, "Unable to resume old stratum connection to pool %d", pool->pool_no);
-		reset_sessionid(pool);
-		clear_stratum_shares(pool);
-		json_decref(val);
-
-		return initiate_stratum(pool);
-	}
-out:
-	if (val)
-		json_decref(val);
-
-	return ret;
-}
-
 bool restart_stratum(struct pool *pool)
 bool restart_stratum(struct pool *pool)
 {
 {
-	bool resume;
-
-	mutex_lock(&pool->pool_lock);
-	resume = pool->sessionid != NULL;
-	mutex_unlock(&pool->pool_lock);
-
-	if (resume) {
-		if (!resume_stratum(pool))
-			return false;
-	} else {
-		if (!initiate_stratum(pool))
-			return false;
-	}
+	if (!initiate_stratum(pool))
+		return false;
 	if (!auth_stratum(pool))
 	if (!auth_stratum(pool))
 		return false;
 		return false;
 	return true;
 	return true;