From 7678db6801977c71a4106e5d8107a4976ab5c8ff Mon Sep 17 00:00:00 2001 From: phm Date: Sat, 5 Apr 2014 20:55:22 +0200 Subject: [PATCH] Fixed problem with stratum support when mining FC, GRS and TWE. Added --difficulty-multiplier parameter for controlling stratum difficulty multiplier. --- sgminer.c | 21 ++++++++++++++++++++- util.c | 5 ++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sgminer.c b/sgminer.c index 8dd0cade..44bec424 100644 --- a/sgminer.c +++ b/sgminer.c @@ -150,6 +150,7 @@ int opt_tcp_keepalive = 30; #else int opt_tcp_keepalive; #endif +double opt_diff_mult = 1.0; char *opt_kernel_path; char *sgminer_path; @@ -1055,6 +1056,18 @@ static char *set_null(const char __maybe_unused *arg) return NULL; } +char *set_difficulty_multiplier(char *arg) +{ + char **endptr = NULL; + if (!(arg && arg[0])) + return "Invalid parameters for set difficulty multiplier"; + opt_diff_mult = strtod(arg, endptr); + if (opt_diff_mult == 0 || endptr == arg) + return "Invalid value passed to set difficulty multiplier"; + + return NULL; +} + /* These options are available from config file or commandline */ static struct opt_table opt_config_table[] = { OPT_WITH_ARG("--api-allow", @@ -1354,6 +1367,9 @@ static struct opt_table opt_config_table[] = { "Display extra work time debug information"), OPT_WITH_ARG("--pools", opt_set_bool, NULL, NULL, opt_hidden), + OPT_WITH_ARG("--difficulty-multiplier", + set_difficulty_multiplier, NULL, NULL, + "Difficulty multiplier for jobs received from stratum pools"), OPT_ENDTABLE }; @@ -5908,7 +5924,10 @@ static void gen_stratum_work(struct pool *pool, struct work *work) cg_dwlock(&pool->data_lock); /* Generate merkle root */ - gen_hash(pool->coinbase, merkle_root, pool->swork.cb_len); + if (gpus[0].kernel == KL_FUGUECOIN || gpus[0].kernel == KL_GROESTLCOIN || gpus[0].kernel == KL_TWECOIN) + sha256(pool->coinbase, pool->swork.cb_len, merkle_root); + else + gen_hash(pool->coinbase, merkle_root, pool->swork.cb_len); memcpy(merkle_sha, merkle_root, 32); for (i = 0; i < pool->swork.merkles; i++) { memcpy(merkle_sha + 32, pool->swork.merkle_bin[i], 32); diff --git a/util.c b/util.c index 2e105d2a..334d534e 100644 --- a/util.c +++ b/util.c @@ -45,8 +45,7 @@ #include "util.h" #define DEFAULT_SOCKWAIT 60 -#define DM_SELECT(x, y, z) (dm_mode == DM_BITCOIN ? x : (dm_mode == DM_QUARKCOIN ? y : z)) -extern enum diff_calc_mode dm_mode; +extern double opt_diff_mult; bool successful_connect = false; static void keep_sockalive(SOCKETTYPE fd) @@ -1644,7 +1643,7 @@ static bool parse_diff(struct pool *pool, json_t *val) { double old_diff, diff; - diff = json_number_value(json_array_get(val, 0)) * DM_SELECT(1, 256, 1); + diff = json_number_value(json_array_get(val, 0)) * opt_diff_mult; if (diff == 0) return false;