mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-25 14:04:25 +00:00
Use the sessionid as passed on stratum connect to attempt to resume a connection once and then clear it if it fails, to use a new connection.
This commit is contained in:
parent
68d691093c
commit
6a0882f05b
@ -3194,7 +3194,7 @@ static void *submit_work_thread(void *userdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&pool->pool_lock);
|
mutex_lock(&pool->pool_lock);
|
||||||
sessionid_match = !strcmp(work->nonce1, pool->nonce1);
|
sessionid_match = (pool->nonce1 && !strcmp(work->nonce1, pool->nonce1));
|
||||||
mutex_unlock(&pool->pool_lock);
|
mutex_unlock(&pool->pool_lock);
|
||||||
|
|
||||||
if (!sessionid_match) {
|
if (!sessionid_match) {
|
||||||
|
54
util.c
54
util.c
@ -1426,14 +1426,16 @@ static bool setup_stratum_curl(struct pool *pool)
|
|||||||
|
|
||||||
bool initiate_stratum(struct pool *pool)
|
bool initiate_stratum(struct pool *pool)
|
||||||
{
|
{
|
||||||
|
char s[RBUFSIZE], *sret = NULL, *nonce1, *sessionid;
|
||||||
json_t *val = NULL, *res_val, *err_val;
|
json_t *val = NULL, *res_val, *err_val;
|
||||||
char s[RBUFSIZE], *sret = NULL;
|
bool ret = false, recvd = false;
|
||||||
json_error_t err;
|
json_error_t err;
|
||||||
bool ret = false;
|
int n2size;
|
||||||
|
|
||||||
if (!setup_stratum_curl(pool))
|
if (!setup_stratum_curl(pool))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
resend:
|
||||||
if (pool->sessionid)
|
if (pool->sessionid)
|
||||||
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid);
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid);
|
||||||
else
|
else
|
||||||
@ -1453,6 +1455,8 @@ bool initiate_stratum(struct pool *pool)
|
|||||||
if (!sret)
|
if (!sret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
recvd = true;
|
||||||
|
|
||||||
val = JSON_LOADS(sret, &err);
|
val = JSON_LOADS(sret, &err);
|
||||||
free(sret);
|
free(sret);
|
||||||
if (!val) {
|
if (!val) {
|
||||||
@ -1479,22 +1483,33 @@ bool initiate_stratum(struct pool *pool)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool->nonce1 = json_array_string(res_val, 1);
|
sessionid = json_array_string(json_array_get(res_val, 0), 1);
|
||||||
if (!pool->nonce1) {
|
if (!sessionid) {
|
||||||
|
applog(LOG_INFO, "Failed to get sessionid in initiate_stratum");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
nonce1 = json_array_string(res_val, 1);
|
||||||
|
if (!nonce1) {
|
||||||
applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
|
applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
|
||||||
|
free(sessionid);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
pool->n1_len = strlen(pool->nonce1) / 2;
|
n2size = json_integer_value(json_array_get(res_val, 2));
|
||||||
pool->n2size = json_integer_value(json_array_get(res_val, 2));
|
if (!n2size) {
|
||||||
if (!pool->n2size) {
|
|
||||||
applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
|
||||||
|
free(sessionid);
|
||||||
|
free(nonce1);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
//pool->sessionid = json_array_string(res_val, 3);
|
|
||||||
if (pool->sessionid)
|
mutex_lock(&pool->pool_lock);
|
||||||
applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);
|
pool->sessionid = sessionid;
|
||||||
else
|
pool->nonce1 = nonce1;
|
||||||
applog(LOG_DEBUG, "Pool %d stratum session id does not exist", pool->pool_no);
|
pool->n1_len = strlen(nonce1) / 2;
|
||||||
|
pool->n2size = n2size;
|
||||||
|
mutex_unlock(&pool->pool_lock);
|
||||||
|
|
||||||
|
applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
out:
|
out:
|
||||||
@ -1510,8 +1525,21 @@ out:
|
|||||||
applog(LOG_DEBUG, "Pool %d confirmed mining.subscribe with extranonce1 %s extran2size %d",
|
applog(LOG_DEBUG, "Pool %d confirmed mining.subscribe with extranonce1 %s extran2size %d",
|
||||||
pool->pool_no, pool->nonce1, pool->n2size);
|
pool->pool_no, pool->nonce1, pool->n2size);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
|
if (recvd && pool->sessionid) {
|
||||||
|
/* Reset the sessionid used for stratum resuming in case the pool
|
||||||
|
* does not support it, or does not know how to respond to the
|
||||||
|
* presence of the sessionid parameter. */
|
||||||
|
mutex_lock(&pool->pool_lock);
|
||||||
|
free(pool->sessionid);
|
||||||
|
free(pool->nonce1);
|
||||||
|
pool->sessionid = pool->nonce1 = NULL;
|
||||||
|
mutex_unlock(&pool->pool_lock);
|
||||||
|
applog(LOG_DEBUG, "Failed to resume stratum, trying afresh");
|
||||||
|
goto resend;
|
||||||
|
}
|
||||||
applog(LOG_DEBUG, "Initiate stratum failed");
|
applog(LOG_DEBUG, "Initiate stratum failed");
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user