From 632cae501e7d15e14c20d29c6b9341b3e297c779 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 12 Apr 2016 14:19:15 +1000 Subject: [PATCH] Respect nonce2length request in proxy mode as upper limit, giving a warning if we're unable to meet it --- src/ckpool.c | 8 +++++--- src/stratifier.c | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 5fd69206..055c7af2 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -1791,9 +1791,11 @@ int main(int argc, char **argv) ckp.nonce1length = 4; else if (ckp.nonce1length < 2 || ckp.nonce1length > 8) quit(0, "Invalid nonce1length %d specified, must be 2~8", ckp.nonce1length); - if (!ckp.nonce2length) - ckp.nonce2length = 8; - else if (ckp.nonce2length < 2 || ckp.nonce2length > 8) + if (!ckp.nonce2length) { + /* nonce2length is zero by default in proxy mode */ + if (!ckp.proxy) + ckp.nonce2length = 8; + } else if (ckp.nonce2length < 2 || ckp.nonce2length > 8) quit(0, "Invalid nonce2length %d specified, must be 2~8", ckp.nonce2length); if (!ckp.update_interval) ckp.update_interval = 30; diff --git a/src/stratifier.c b/src/stratifier.c index dbb4bf11..40d922f4 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2397,7 +2397,11 @@ static void update_subscribe(ckpool_t *ckp, const char *cmd) proxy->enonce1constlen = strlen(proxy->enonce1) / 2; hex2bin(proxy->enonce1bin, proxy->enonce1, proxy->enonce1constlen); proxy->nonce2len = json_integer_value(json_object_get(val, "nonce2len")); - if (proxy->nonce2len > 7) + if (ckp->nonce2length) { + proxy->enonce1varlen = proxy->nonce2len - ckp->nonce2length; + if (proxy->enonce1varlen < 0) + proxy->enonce1varlen = 0; + } else if (proxy->nonce2len > 7) proxy->enonce1varlen = 4; else if (proxy->nonce2len > 5) proxy->enonce1varlen = 2; @@ -2417,6 +2421,9 @@ static void update_subscribe(ckpool_t *ckp, const char *cmd) LOGNOTICE("Upstream pool %s %d extranonce2 length %d, max proxy clients %"PRId64, proxy->url, id, proxy->nonce2len, proxy->max_clients); } + if (ckp->nonce2length && proxy->enonce2varlen != ckp->nonce2length) + LOGWARNING("Only able to set nonce2len %d of requested %d on proxy %d:%d", + proxy->enonce2varlen, ckp->nonce2length, id, subid); json_decref(val); }