Cope with out of order messages coming in upon attempting to auth_stratum.
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
diff --git a/util.c b/util.c
index 2769f81..e95334c 100644
--- a/util.c
+++ b/util.c
@@ -1363,38 +1363,46 @@ bool auth_stratum(struct pool *pool)
json_error_t err;
bool ret = false;
+ pool->stratum_notify = false;
+
sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}",
swork_id++, pool->rpc_user, pool->rpc_pass);
if (!stratum_send(pool, s, strlen(s)))
goto out;
- /* Parse all data in the queue and anything left should be auth */
+ /* Parse all data in the queue and break out should we run out of data
+ * or we have successfully parsed a notify message. */
while (42) {
sret = recv_line(pool);
if (!sret)
goto out;
- if (parse_method(pool, sret))
+ if (parse_method(pool, sret)) {
free(sret);
- else
+ if (pool->stratum_notify)
+ break;
+ } else
break;
}
- val = JSON_LOADS(sret, &err);
- free(sret);
- res_val = json_object_get(val, "result");
- err_val = json_object_get(val, "error");
-
- if (!res_val || json_is_false(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_WARNING, "JSON stratum auth failed: %s", ss);
- free(ss);
-
+ if (!pool->stratum_notify) {
+ val = JSON_LOADS(sret, &err);
+ free(sret);
+ res_val = json_object_get(val, "result");
+ err_val = json_object_get(val, "error");
+
+ if (!res_val || json_is_false(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_WARNING, "JSON stratum auth failed: %s", ss);
+ free(ss);
+ goto out;
+ }
+ applog(LOG_WARNING, "Failed to auth stratum");
goto out;
}