Add share to stratum database before sending it again in case we get a response from the pool before it's added.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/cgminer.c b/cgminer.c
index 92de983..8ec4f6b 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++;