From 55a14d4ea513b19f621c2da826ff1e13eb4f22a7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 5 Sep 2014 14:09:57 +1000 Subject: [PATCH] Revert "Mining subscribe does not return true as the result so use a subscribed boolean" This reverts commit 27a7a36e3802c893860b664349bec8a0d679f956. --- src/stratifier.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 83f5b1c1..bbced5c1 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -232,7 +232,7 @@ struct stratum_instance { char address[INET6_ADDRSTRLEN]; bool authorised; - bool subscribed; + bool invalid; bool idle; bool notified_idle; @@ -1245,8 +1245,9 @@ static void new_enonce1(stratum_instance_t *client) } /* Extranonce1 must be set here */ -static json_t *parse_subscribe(stratum_instance_t *client, int64_t client_id, json_t *params_val) +static json_t *parse_subscribe(int64_t client_id, json_t *params_val) { + stratum_instance_t *client = NULL; bool old_match = false; int arr_size; json_t *ret; @@ -1255,6 +1256,15 @@ static json_t *parse_subscribe(stratum_instance_t *client, int64_t client_id, js if (unlikely(!json_is_array(params_val))) return json_string("params not an array"); + ck_rlock(&instance_lock); + client = __instance_by_id(client_id); + ck_runlock(&instance_lock); + + if (unlikely(!client)) { + LOGERR("Failed to find client id %d in hashtable!", client_id); + return NULL; + } + if (unlikely(!current_workbase)) return json_string("Initialising"); @@ -1299,8 +1309,6 @@ static json_t *parse_subscribe(stratum_instance_t *client, int64_t client_id, js n2len); ck_runlock(&workbase_lock); - client->subscribed = true; - return ret; } @@ -2124,20 +2132,25 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method * the json item for id_val as is for the response. */ method = json_string_value(method_val); if (cmdmatch(method, "mining.subscribe")) { - json_t *val, *result_val = parse_subscribe(client, client_id, params_val); + json_t *val, *result_val = parse_subscribe(client_id, params_val); + if (unlikely(!result_val)) + return; val = json_object(); json_object_set_new_nocheck(val, "result", result_val); json_object_set_nocheck(val, "id", id_val); json_object_set_new_nocheck(val, "error", json_null()); stratum_add_send(val, client_id); - if (likely(client->subscribed)) - update_client(client, client_id); + if (unlikely(!json_is_true(result_val))) { + client->invalid = true; + return; + } + update_client(client, client_id); return; } - if (unlikely(!client->subscribed)) { - LOGINFO("Dropping unsubscribed client %d", client->id); + if (unlikely(client->invalid)) { + LOGINFO("Dropping invalidated client %d", client->id); snprintf(buf, 255, "dropclient=%ld", client->id); send_proc(client->ckp->connector, buf); drop_client(client->id);