From ab91682e22cdb4b1914f82e19bdb03799c33b3ca Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 15 Nov 2014 15:32:01 +1100 Subject: [PATCH] Add support for custom extranonce1 lengths --- README | 3 +++ ckpool.conf | 1 + src/ckpool.c | 5 +++++ src/ckpool.h | 1 + src/stratifier.c | 10 +++++++--- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README b/README index 3d8c90ea..735bcbb0 100644 --- a/README +++ b/README @@ -240,6 +240,9 @@ new network blocks and is 100 by default. It is intended to be a backup only for when the notifier is not set up and only polls if the "notify" field is not set on a btcd. +'noncelength" : This is optional allowing the extranonce1 length to be chosen +from 2 to 8. Default 8 + "update_interval" : This is the frequency that stratum updates are sent out to miners and is set to 30 seconds by default to help perpetuate transactions for the health of the bitcoin network. diff --git a/ckpool.conf b/ckpool.conf index 340556bd..f9f767da 100644 --- a/ckpool.conf +++ b/ckpool.conf @@ -16,6 +16,7 @@ "btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e", "btcsig" : "/mined by ck/", "blockpoll" : 100, +"noncelength" : 8, "update_interval" : 30, "serverurl" : "ckpool.org:3333", "mindiff" : 1, diff --git a/src/ckpool.c b/src/ckpool.c index e1d1186b..ee528880 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -1017,6 +1017,7 @@ static void parse_config(ckpool_t *ckp) ckp->btcsig[38] = '\0'; } json_get_int(&ckp->blockpoll, json_conf, "blockpoll"); + json_get_int(&ckp->noncelength, json_conf, "noncelength"); json_get_int(&ckp->update_interval, json_conf, "update_interval"); json_get_string(&ckp->serverurl, json_conf, "serverurl"); json_get_int64(&ckp->mindiff, json_conf, "mindiff"); @@ -1311,6 +1312,10 @@ int main(int argc, char **argv) ckp.btcaddress = ckp.donaddress; if (!ckp.blockpoll) ckp.blockpoll = 100; + if (!ckp.noncelength) + ckp.noncelength = 8; + else if (ckp.noncelength < 2 || ckp.noncelength > 8) + quit(0, "Invalid noncelength %d specified, must be 2~8", ckp.noncelength); if (!ckp.update_interval) ckp.update_interval = 30; if (!ckp.mindiff) diff --git a/src/ckpool.h b/src/ckpool.h index 768dcaf4..5d5f48a1 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -148,6 +148,7 @@ struct ckpool_instance { char **btcdpass; bool *btcdnotify; int blockpoll; // How frequently in ms to poll bitcoind for block updates + int noncelength; // Extranonce1 length /* Difficulty settings */ int64_t mindiff; // Default 1 diff --git a/src/stratifier.c b/src/stratifier.c index be5b316c..f20db9d8 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -410,9 +410,7 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) len = ser_number(wb->coinb1bin + ofs, now.tv_nsec); ofs += len; - /* Leave enonce1/2varlen constant at 8 bytes for bitcoind sources */ - wb->enonce1varlen = 8; - wb->enonce2varlen = 8; + wb->enonce1varlen = wb->enonce2varlen = ckp->noncelength; wb->coinb1bin[ofs++] = wb->enonce1varlen + wb->enonce2varlen; wb->coinb1len = ofs; @@ -1568,10 +1566,14 @@ static bool new_enonce1(stratum_instance_t *client) sdata->enonce1u.u64++; ret = true; break; + case 7: + case 6: + case 5: case 4: sdata->enonce1u.u32++; ret = true; break; + case 3: case 2: for (i = 0; i < 65536; i++) { sdata->enonce1u.u16++; @@ -1588,6 +1590,8 @@ static bool new_enonce1(stratum_instance_t *client) break; } break; + default: + quit(0, "Invalid enonce1varlen %d", wb->enonce1varlen); } if (ret) client->enonce1_64 = sdata->enonce1u.u64;