From 843fa3397e0e7473a978837367e0731d9d2aa7f5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 29 Oct 2012 16:35:54 +1100 Subject: [PATCH 1/8] Add share to stratum database before sending it again in case we get a response from the pool before it's added. --- cgminer.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cgminer.c b/cgminer.c index 92de9834..8ec4f6ba 100644 --- a/cgminer.c +++ b/cgminer.c @@ -2915,15 +2915,21 @@ static void *submit_work_thread(void *userdata) } if (work->stratum) { + struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1); uint32_t *hash32 = (uint32_t *)work->hash, nonce; char *noncehex; char s[1024]; /* Give the stratum share a unique id */ swork_id++; + memcpy(&sshare->work, work, sizeof(struct work)); + mutex_lock(&sshare_lock); + sshare->id = swork_id; + HASH_ADD_INT(stratum_shares, id, sshare); + mutex_unlock(&sshare_lock); + nonce = *((uint32_t *)(work->data + 76)); noncehex = bin2hex((const unsigned char *)&nonce, 4); - memset(s, 0, 1024); sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}", pool->rpc_user, work->job_id, work->nonce2, work->ntime, noncehex, swork_id); @@ -2932,19 +2938,16 @@ static void *submit_work_thread(void *userdata) applog(LOG_INFO, "Submitting share %08lx to pool %d", (unsigned long)(hash32[6]), pool->pool_no); if (likely(stratum_send(pool, s, strlen(s)))) { - struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1); - if (pool_tclear(pool, &pool->submit_fail)) applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no); applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db"); - memcpy(&sshare->work, work, sizeof(struct work)); - - mutex_lock(&sshare_lock); - sshare->id = swork_id; - HASH_ADD_INT(stratum_shares, id, sshare); - mutex_unlock(&sshare_lock); } else { applog(LOG_INFO, "Failed to submit stratum share"); + mutex_lock(&sshare_lock); + HASH_DEL(stratum_shares, sshare); + mutex_unlock(&sshare_lock); + free(sshare); + if (!pool_tset(pool, &pool->submit_fail)) { total_ro++; pool->remotefail_occasions++; From d92609e665d5cd95cc9c6a1a82eae3fffe94a683 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 28 Oct 2012 19:58:35 +1100 Subject: [PATCH 2/8] Fail on select() failing in stratum thread without needing to attempt recv_line. --- cgminer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cgminer.c b/cgminer.c index 8ec4f6ba..cbed74f6 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4333,8 +4333,10 @@ static void *stratum_thread(void *userdata) * every minute so if we fail to receive any for 90 seconds we * assume the connection has been dropped and treat this pool * as dead */ - select(pool->sock + 1, &rd, NULL, NULL, &timeout); - s = recv_line(pool); + if (unlikely(select(pool->sock + 1, &rd, NULL, NULL, &timeout) < 1)) + s = NULL; + else + s = recv_line(pool); if (!s) { applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no); pool->getfail_occasions++; From bbe5636ec48d88f4d694f65e13532426dd9b9a0a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 29 Oct 2012 16:50:24 +1100 Subject: [PATCH 3/8] Bump version and NEWS to 2.8.7 --- NEWS | 8 ++++++++ configure.ac | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a696a7e5..4c270f38 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Version 2.8.7 - October 29, 2012 + +- Fail on select() failing in stratum thread without needing to attempt +recv_line. +- Add share to stratum database before sending it again in case we get a +response from the pool before it's added. + + Version 2.8.6 - October 29, 2012 - Shorten the initiate stratum connect timeout to 30 seconds. diff --git a/configure.ac b/configure.ac index 13fb2462..a88f2b7a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## m4_define([v_maj], [2]) m4_define([v_min], [8]) -m4_define([v_mic], [6]) +m4_define([v_mic], [7]) ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## m4_define([v_ver], [v_maj.v_min.v_mic]) m4_define([lt_rev], m4_eval(v_maj + v_min)) From 280486a74869c80a98187ffe903c23381c7aff12 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 29 Oct 2012 07:14:29 +0000 Subject: [PATCH 4/8] Bugfix: Initialize temporary stratum work Without this, work.mandatory might have been true skipping block change handling code This caused newfound shares to be considered stale always, and bitforce devices to constantly restart work --- cgminer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cgminer.c b/cgminer.c index af8c63ac..6edc5f4a 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4150,6 +4150,7 @@ static void *stratum_thread(void *userdata) free(s); if (pool->swork.clean) { struct work work; + memset(&work, 0, sizeof(work)); /* Generate a single work item to update the current * block database */ From e19c5d9db90b1738b1a90afe3d7f7f5688397902 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 29 Oct 2012 21:28:15 +1100 Subject: [PATCH 5/8] Set sshare id and swork_id within the sshare mutex to avoid multiple share submits with the same id. --- cgminer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cgminer.c b/cgminer.c index cbed74f6..ef94d601 100644 --- a/cgminer.c +++ b/cgminer.c @@ -2920,11 +2920,10 @@ static void *submit_work_thread(void *userdata) char *noncehex; char s[1024]; - /* Give the stratum share a unique id */ - swork_id++; memcpy(&sshare->work, work, sizeof(struct work)); mutex_lock(&sshare_lock); - sshare->id = swork_id; + /* Give the stratum share a unique id */ + sshare->id = swork_id++; HASH_ADD_INT(stratum_shares, id, sshare); mutex_unlock(&sshare_lock); @@ -2932,7 +2931,7 @@ static void *submit_work_thread(void *userdata) noncehex = bin2hex((const unsigned char *)&nonce, 4); memset(s, 0, 1024); sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}", - pool->rpc_user, work->job_id, work->nonce2, work->ntime, noncehex, swork_id); + pool->rpc_user, work->job_id, work->nonce2, work->ntime, noncehex, sshare->id); free(noncehex); applog(LOG_INFO, "Submitting share %08lx to pool %d", (unsigned long)(hash32[6]), pool->pool_no); From a2d57835094cd5f258df38bdf31eb29e6fede750 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Tue, 30 Oct 2012 16:45:27 +1100 Subject: [PATCH 6/8] server and client sockaddr_in are no longer used in struct pool. --- miner.h | 1 - util.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/miner.h b/miner.h index 16dcbe3a..4f79da2a 100644 --- a/miner.h +++ b/miner.h @@ -872,7 +872,6 @@ struct pool { CURL *stratum_curl; SOCKETTYPE sock; char sockbuf[RBUFSIZE]; - struct sockaddr_in *server, client; char *sockaddr_url; /* stripped url used for sockaddr */ char *nonce1; uint32_t nonce2; diff --git a/util.c b/util.c index 02de1730..dcc11c4e 100644 --- a/util.c +++ b/util.c @@ -876,8 +876,8 @@ bool extract_sockaddr(struct pool *pool, char *url) applog(LOG_DEBUG, "Failed to extract sock addr"); return false; } + freeaddrinfo(res); - pool->server = (struct sockaddr_in *)res->ai_addr; pool->sockaddr_url = strdup(url_address); return true; From c2861d683a22d831d28c8806b3fa16b69e7670f0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 30 Oct 2012 19:22:02 +1100 Subject: [PATCH 7/8] There is no need for addrinfo any more. --- util.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/util.c b/util.c index dcc11c4e..2856915b 100644 --- a/util.c +++ b/util.c @@ -836,7 +836,6 @@ bool extract_sockaddr(struct pool *pool, char *url) { char *url_begin, *url_end, *port_start = NULL; char url_address[256], port[6]; - struct addrinfo hints, *res; int url_len, port_len = 0; pool->sockaddr_url = url; @@ -866,18 +865,6 @@ bool extract_sockaddr(struct pool *pool, char *url) strcpy(port, "80"); pool->stratum_port = strdup(port); - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - if (getaddrinfo(url_address, port, &hints, &res)) { - applog(LOG_DEBUG, "Failed to extract sock addr"); - return false; - } - freeaddrinfo(res); - pool->sockaddr_url = strdup(url_address); return true; From c2b5c5ee4ca529798154d16cd5da43b88fe44ff9 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 29 Oct 2012 07:50:47 +0000 Subject: [PATCH 8/8] Bugfix: Free old stratum_work data before replacing it --- util.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util.c b/util.c index 2856915b..439c6035 100644 --- a/util.c +++ b/util.c @@ -1084,6 +1084,13 @@ static bool parse_notify(struct pool *pool, json_t *val) } mutex_lock(&pool->pool_lock); + free(pool->swork.job_id); + free(pool->swork.prev_hash); + free(pool->swork.coinbase1); + free(pool->swork.coinbase2); + free(pool->swork.bbversion); + free(pool->swork.nbit); + free(pool->swork.ntime); pool->swork.job_id = job_id; pool->swork.prev_hash = prev_hash; pool->swork.coinbase1 = coinbase1;