From 8db53026cb05c1de456c93f4a3f460b2a96da6e1 Mon Sep 17 00:00:00 2001 From: troky Date: Tue, 25 Mar 2014 20:37:45 +0100 Subject: [PATCH 1/3] Added --pool-priority --- sgminer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sgminer.c b/sgminer.c index 5cc1f842..c53ff29c 100644 --- a/sgminer.c +++ b/sgminer.c @@ -931,6 +931,19 @@ static char *set_userpass(const char *arg) return NULL; } +static char *set_pool_priority(char *arg) +{ + struct pool *pool; + + while ((json_array_index + 1) > total_pools) + add_pool(); + pool = pools[json_array_index]; + applog(LOG_DEBUG, "Setting pool %i priority to %s", pool->pool_no, arg); + opt_set_intval(arg, &pool->prio); + + return NULL; +} + static char *enable_debug(bool *flag) { *flag = true; @@ -1400,6 +1413,9 @@ static struct opt_table opt_config_table[] = { OPT_WITH_ARG("--userpass|-O", set_userpass, NULL, NULL, "Username:Password pair for bitcoin JSON-RPC server"), + OPT_WITH_ARG("--pool-priority", + set_pool_priority, NULL, NULL, + "Pool priority"), OPT_WITHOUT_ARG("--worktime", opt_set_bool, &opt_worktime, "Display extra work time debug information"), From 17f5e296a9cfd01eb15a6a7e162f022e972d114e Mon Sep 17 00:00:00 2001 From: troky Date: Wed, 26 Mar 2014 10:46:17 +0100 Subject: [PATCH 2/3] Fixed configuration/command line parsing. --- sgminer.c | 68 ++++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/sgminer.c b/sgminer.c index c53ff29c..b9fd4ce9 100644 --- a/sgminer.c +++ b/sgminer.c @@ -230,7 +230,7 @@ int total_pools, enabled_pools; enum pool_strategy pool_strategy = POOL_FAILOVER; int opt_rotate_period; static int total_urls, total_users, total_passes, total_userpasses; -static int json_array_index; +static int json_array_index = -1; static #ifndef HAVE_CURSES @@ -557,6 +557,20 @@ struct pool *add_pool(void) return pool; } +static struct pool* get_current_pool() +{ + while ((json_array_index + 1) > total_pools) + add_pool(); + + if (json_array_index < 0) { + if (!total_pools) + add_pool(); + return pools[total_pools - 1]; + } + + return pools[json_array_index]; +} + /* Pool variant of test and set */ static bool pool_tset(struct pool *pool, bool *var) { @@ -755,12 +769,8 @@ static char *set_url(char *arg) static char *set_poolname(char *arg) { - struct pool *pool; - - while ((json_array_index + 1) > total_pools) - add_pool(); - pool = pools[json_array_index]; - + struct pool *pool = get_current_pool(); + applog(LOG_DEBUG, "Setting pool %i name to %s", pool->pool_no, arg); opt_set_charp(arg, &pool->name); @@ -823,12 +833,7 @@ void remove_pool(struct pool *pool) static char *set_pool_state(char *arg) { - struct pool *pool; - - /* TODO: consider using j_a_i everywhere */ - while ((json_array_index + 1) > total_pools) - add_pool(); - pool = pools[json_array_index]; + struct pool *pool = get_current_pool(); applog(LOG_INFO, "Setting pool %s state to %s", get_pool_name(pool), arg); if (strcmp(arg, "disabled") == 0) { @@ -877,15 +882,8 @@ static char *set_quota(char *arg) static char *set_user(const char *arg) { - struct pool *pool; + struct pool *pool = get_current_pool(); - if (total_userpasses) - return "Use only user + pass or userpass, but not both"; - total_users++; - if (total_users > total_pools) - add_pool(); - - pool = pools[total_users - 1]; opt_set_charp(arg, &pool->rpc_user); return NULL; @@ -893,15 +891,8 @@ static char *set_user(const char *arg) static char *set_pass(const char *arg) { - struct pool *pool; + struct pool *pool = get_current_pool(); - if (total_userpasses) - return "Use only user + pass or userpass, but not both"; - total_passes++; - if (total_passes > total_pools) - add_pool(); - - pool = pools[total_passes - 1]; opt_set_charp(arg, &pool->rpc_pass); return NULL; @@ -909,16 +900,9 @@ static char *set_pass(const char *arg) static char *set_userpass(const char *arg) { - struct pool *pool; + struct pool *pool = get_current_pool(); char *updup; - if (total_users || total_passes) - return "Use only user + pass or userpass, but not both"; - total_userpasses++; - if (total_userpasses > total_pools) - add_pool(); - - pool = pools[total_userpasses - 1]; updup = strdup(arg); opt_set_charp(arg, &pool->rpc_userpass); pool->rpc_user = strtok(updup, ":"); @@ -926,18 +910,15 @@ static char *set_userpass(const char *arg) return "Failed to find : delimited user info"; pool->rpc_pass = strtok(NULL, ":"); if (!pool->rpc_pass) - return "Failed to find : delimited pass info"; + pool->rpc_pass = ""; return NULL; } static char *set_pool_priority(char *arg) { - struct pool *pool; + struct pool *pool = get_current_pool(); - while ((json_array_index + 1) > total_pools) - add_pool(); - pool = pools[json_array_index]; applog(LOG_DEBUG, "Setting pool %i priority to %s", pool->pool_no, arg); opt_set_intval(arg, &pool->prio); @@ -1474,7 +1455,6 @@ static char *parse_config(json_t *config, bool fileconf, int parent_iteration) else if (json_is_object(json_array_get(val, n))) { err = parse_config(json_array_get(val, n), false, n); - json_array_index = parent_iteration; } } } else if ((opt->type & OPT_NOARG) && json_is_boolean(val)) { @@ -1541,7 +1521,7 @@ static char *load_config(const char *arg, void __maybe_unused *unused) /* Parse the config now, so we can override it. That can keep pointers * so don't free config object. */ - return parse_config(config, true, 0); + return parse_config(config, true, -1); } static char *set_default_config(const char *arg) From bcb78ed91bf4b49f7e04b761e9fe8210a0d6cfe7 Mon Sep 17 00:00:00 2001 From: troky Date: Wed, 26 Mar 2014 11:10:41 +0100 Subject: [PATCH 3/3] Added --coin pool parameter. --- api.c | 1 + miner.h | 1 + sgminer.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/api.c b/api.c index c175fe1c..4caf65c4 100644 --- a/api.c +++ b/api.c @@ -1819,6 +1819,7 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m root = api_add_int(root, "POOL", &i, false); root = api_add_string(root, "Name", pool->name, false); + root = api_add_string(root, "Coin", pool->coin, false); root = api_add_escape(root, "URL", pool->rpc_url, false); root = api_add_string(root, "Status", status, false); root = api_add_int(root, "Priority", &(pool->prio), false); diff --git a/miner.h b/miner.h index 8878219e..9761ff23 100644 --- a/miner.h +++ b/miner.h @@ -1172,6 +1172,7 @@ struct stratum_work { struct pool { int pool_no; char *name; + char *coin; int prio; int accepted, rejected; int seq_rejects; diff --git a/sgminer.c b/sgminer.c index b9fd4ce9..59f86582 100644 --- a/sgminer.c +++ b/sgminer.c @@ -554,6 +554,8 @@ struct pool *add_pool(void) pool->quota = 1; adjust_quota_gcd(); + pool->coin = ""; + return pool; } @@ -925,6 +927,16 @@ static char *set_pool_priority(char *arg) return NULL; } +static char *set_pool_coin(char *arg) +{ + struct pool *pool = get_current_pool(); + + applog(LOG_DEBUG, "Setting pool %i coin to %s", pool->pool_no, arg); + opt_set_charp(arg, &pool->coin); + + return NULL; +} + static char *enable_debug(bool *flag) { *flag = true; @@ -1397,6 +1409,9 @@ static struct opt_table opt_config_table[] = { OPT_WITH_ARG("--pool-priority", set_pool_priority, NULL, NULL, "Pool priority"), + OPT_WITH_ARG("--coin", + set_pool_coin, NULL, NULL, + "Pool coin"), OPT_WITHOUT_ARG("--worktime", opt_set_bool, &opt_worktime, "Display extra work time debug information"),