Remove the sshare hash entry if we failed to send it.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
diff --git a/cgminer.c b/cgminer.c
index a78b1a2..4969315 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2767,7 +2767,12 @@ static void *submit_work_thread(void *userdata)
applog(LOG_INFO, "Submitting share %08lx to pool %d", (unsigned long)(hash32[6]), pool->pool_no);
- stratum_send(pool, s, strlen(s));
+ if (unlikely(!stratum_send(pool, s, strlen(s)))) {
+ mutex_lock(&sshare_lock);
+ HASH_DEL(stratum_shares, sshare);
+ mutex_unlock(&sshare_lock);
+ free(sshare);
+ }
goto out;
}
diff --git a/util.c b/util.c
index c0c85e8..9b6677b 100644
--- a/util.c
+++ b/util.c
@@ -1189,9 +1189,10 @@ out:
bool initiate_stratum(struct pool *pool)
{
json_t *val = NULL, *res_val, *err_val, *notify_val;
+ bool ret = false, notify = false;
char *s, *buf, *sret = NULL;
json_error_t err;
- bool ret = false;
+ int i, arr_size;
if (pool->stratum_active)
return true;
@@ -1232,7 +1233,8 @@ bool initiate_stratum(struct pool *pool)
err_val = json_object_get(val, "error");
if (!res_val || json_is_null(res_val) ||
- (err_val && !json_is_null(err_val))) {
+ (err_val && !json_is_null(err_val)) ||
+ !json_is_array(res_val)) {
char *ss;
if (err_val)
@@ -1247,17 +1249,26 @@ bool initiate_stratum(struct pool *pool)
goto out;
}
- notify_val = json_array_get(res_val, 0);
- if (!notify_val || json_is_null(notify_val)) {
- applog(LOG_INFO, "Failed to parse notify_val in initiate_stratum");
- goto out;
+ arr_size = json_array_size(res_val);
+ for (i = 0; i < arr_size; i++) {
+ notify_val = json_array_get(res_val, i);
+ if (!notify_val || json_is_null(notify_val)) {
+ applog(LOG_INFO, "Failed to parse notify_val in initiate_stratum");
+ goto out;
+ }
+
+ buf = __json_array_string(notify_val, 0);
+ if (buf && !strcasecmp(buf, "mining.notify")) {
+ notify = true;
+ break;
+ }
}
- buf = __json_array_string(notify_val, 0);
- if (!buf || strcasecmp(buf, "mining.notify")) {
+ if (!notify) {
applog(LOG_INFO, "Failed to get mining notify in initiate_stratum");
goto out;
}
+
pool->subscription = json_array_string(notify_val, 1);
if (!pool->subscription) {
applog(LOG_INFO, "Failed to get a subscription in initiate_stratum");