From b742ced4ebc243410bf6d8a75a852cdb25212be6 Mon Sep 17 00:00:00 2001 From: elbandi Date: Thu, 24 Apr 2014 14:18:38 +0200 Subject: [PATCH] subscribe for mining.extranonce --- sgminer.c | 11 ++++++++++- util.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sgminer.c b/sgminer.c index 980b4e39..3bdfb030 100644 --- a/sgminer.c +++ b/sgminer.c @@ -5204,6 +5204,15 @@ static bool parse_stratum_response(struct pool *pool, char *s) id = json_integer_value(id_val); + if (err_val && !json_is_null(err_val)) { + char *ss; + ss = (char *)json_string_value(json_array_get(err_val, 1)); + if (strcmp(ss, "Method 'subscribe' not found for service 'mining.extranonce'") == 0) { + applog(LOG_INFO, "Cannot subscribe to mining.extranonce on %s", get_pool_name(pool)); + goto out; + } + } + mutex_lock(&sshare_lock); HASH_FIND_INT(stratum_shares, &id, sshare); if (sshare) { @@ -5673,7 +5682,7 @@ retry_stratum: bool init = pool_tset(pool, &pool->stratum_init); if (!init) { - bool ret = initiate_stratum(pool) && auth_stratum(pool); + bool ret = initiate_stratum(pool) && auth_stratum(pool) && subscribe_extranonce(pool); if (ret) init_stratum_threads(pool); diff --git a/util.c b/util.c index 36866e5c..0d08b585 100644 --- a/util.c +++ b/util.c @@ -1876,6 +1876,22 @@ bool parse_method(struct pool *pool, char *s) return ret; } +bool subscribe_extranonce(struct pool *pool) +{ + char s[RBUFSIZE]; + bool ret = false; + + sprintf(s, "{\"id\": %d, \"method\": \"mining.extranonce.subscribe\", \"params\": []}", + swork_id++); + + if (!stratum_send(pool, s, strlen(s))) + return ret; + + ret = true; + applog(LOG_INFO, "Stratum extranonce subscribe for %s", get_pool_name(pool)); + return ret; +} + bool auth_stratum(struct pool *pool) { json_t *val = NULL, *res_val, *err_val; @@ -2506,6 +2522,8 @@ bool restart_stratum(struct pool *pool) return false; if (!auth_stratum(pool)) return false; + if (!subscribe_extranonce(pool)) + return false; return true; }