restored default segwit on, worked on stratum support of lbry

This commit is contained in:
Brannon King 2019-10-14 09:40:05 -06:00
parent 897f30df0f
commit b8ffcc1d4b
4 changed files with 131 additions and 128 deletions

View file

@ -1,17 +1,16 @@
#
# Dockerfile for cpuminer
# usage: docker run creack/cpuminer --url xxxx --user xxxx --pass xxxx
# ex: docker run creack/cpuminer --url stratum+tcp://ltc.pool.com:80 --user creack.worker1 --pass abcdef
# usage: docker run lbry/cpuminer --url xxxx --user xxxx --pass xxxx
# ex: docker run lbry/cpuminer --url stratum+tcp://lbc.pool.com:80 --user worker1 --pass abcdef
#
#
FROM ubuntu:16.04
MAINTAINER Guillaume J. Charmes <guillaume@charmes.net>
FROM ubuntu:18.04
RUN apt-get update -qq && \
apt-get install -qqy automake libcurl4-openssl-dev git make gcc
RUN git clone https://github.com/pooler/cpuminer
RUN git clone https://github.com/lbryio/cpuminer
RUN cd cpuminer && \
./autogen.sh && \

View file

@ -122,7 +122,6 @@ bool have_gbt = true;
bool allow_getwork = false;
bool want_stratum = false;
bool have_stratum = false;
bool want_segwit = false;
bool use_syslog = false;
static bool opt_background = false;
static bool opt_quiet = false;
@ -186,7 +185,7 @@ Options:\n\
-r, --retries=N number of times to retry if a network call fails\n\
(default: retry indefinitely)\n\
-R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\
-T, --timeout=N timeout for long polling, in seconds (default: none)\n\
-T, --timeout=N timeout for long polling, in seconds (default: 70sec)\n\
-s, --scantime=N upper bound on time spent scanning current work when\n\
long polling is unavailable, in seconds (default: 5)\n\
--coinbase-addr=ADDR payout address for solo mining\n\
@ -198,8 +197,7 @@ Options:\n\
--no-redirect ignore requests to change the URL of the mining server\n\
-q, --quiet disable per-thread hashmeter output\n\
-D, --debug enable debug output\n\
-P, --protocol-dump verbose dump of protocol-level activities\n\
--segwit include Segwit transactions in the mined data\n"
-P, --protocol-dump verbose dump of protocol-level activities\n"
#ifdef HAVE_SYSLOG_H
"\
-S, --syslog use system log for output messages\n"
@ -248,7 +246,6 @@ static struct option const options[] = {
{ "retries", 1, NULL, 'r' },
{ "retry-pause", 1, NULL, 'R' },
{ "scantime", 1, NULL, 's' },
{ "segwit", 0, NULL, 1016 },
#ifdef HAVE_SYSLOG_H
{ "syslog", 0, NULL, 'S' },
#endif
@ -345,7 +342,7 @@ static bool work_decode(const json_t *val, struct work *work)
return true;
err_out:
err_out:
return false;
}
@ -450,7 +447,6 @@ static bool gbt_work_decode(const json_t *val, struct work *work)
/* build coinbase transaction */
tmp = json_object_get(val, "coinbasetxn");
if (tmp) {
const char *cbtx_hex = json_string_value(json_object_get(tmp, "data"));
cbtx_size = cbtx_hex ? strlen(cbtx_hex) / 2 : 0;
@ -762,8 +758,9 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
uint32_t ntime, nonce;
char ntimestr[9], noncestr[9], *xnonce2str, *req;
le32enc(&ntime, work->data[17]);
le32enc(&nonce, work->data[19]);
int offset = opt_algo == ALGO_LBRY ? 8 : 0;
le32enc(&ntime, work->data[17 + offset]);
le32enc(&nonce, work->data[19 + offset]);
bin2hex(ntimestr, (const unsigned char *)(&ntime), 4);
bin2hex(noncestr, (const unsigned char *)(&nonce), 4);
xnonce2str = abin2hex(work->xnonce2, work->xnonce2_len);
@ -865,14 +862,13 @@ static const char *getwork_req =
#define GBT_CAPABILITIES "[\"coinbasetxn\", \"coinbasevalue\", \"longpoll\", \"workid\"]"
#define GBT_RULES "[\"segwit\"]"
#define GBT_NO_RULES "[]"
static const char *gbt_req =
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
GBT_CAPABILITIES ", \"rules\": " GBT_NO_RULES "}], \"id\":0}\r\n";
GBT_CAPABILITIES ", \"rules\": " GBT_RULES "}], \"id\":0}\r\n";
static const char *gbt_lp_req =
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
GBT_CAPABILITIES ", \"rules\": %s, \"longpollid\": \"%s\"}], \"id\":0}\r\n";
GBT_CAPABILITIES ", \"rules\": " GBT_RULES ", \"longpollid\": \"%s\"}], \"id\":0}\r\n";
static bool get_upstream_work(CURL *curl, struct work *work)
{
@ -1115,7 +1111,7 @@ err_out:
static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
{
unsigned char merkle_root[64];
int i;
int i, offset = 0;
pthread_mutex_lock(&sctx->work_lock);
@ -1136,23 +1132,29 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
for (i = 0; i < sctx->xnonce2_size && !++sctx->job.xnonce2[i]; i++);
/* Assemble block header */
memset(work->data, 0, 128);
memset(work->data, 0, sizeof(work->data));
work->data[0] = le32dec(sctx->job.version);
for (i = 0; i < 8; i++)
work->data[1 + i] = le32dec((uint32_t *)sctx->job.prevhash + i);
for (i = 0; i < 8; i++)
work->data[9 + i] = be32dec((uint32_t *)merkle_root + i);
work->data[17] = le32dec(sctx->job.ntime);
work->data[18] = le32dec(sctx->job.nbits);
work->data[20] = 0x80000000;
work->data[31] = 0x00000280;
if (sctx->job.needs_claimhash) {
offset = 8;
for (i = 0; i < 8; i++)
work->data[24 - i] = le32dec((uint32_t *)sctx->job.claimhash + i);
}
work->data[17 + offset] = le32dec(sctx->job.ntime);
work->data[18 + offset] = le32dec(sctx->job.nbits);
work->data[20 + offset] = 0x80000000;
work->data[31 + offset] = 0x00000280;
pthread_mutex_unlock(&sctx->work_lock);
if (opt_debug) {
char *xnonce2str = abin2hex(work->xnonce2, work->xnonce2_len);
applog(LOG_DEBUG, "DEBUG: job_id='%s' extranonce2=%s ntime=%08x",
work->job_id, xnonce2str, swab32(work->data[17]));
work->job_id, xnonce2str, swab32(work->data[17 + offset]));
free(xnonce2str);
}
@ -1255,21 +1257,19 @@ static void *miner_thread(void *userdata)
max64 *= thr_hashrates[thr_id];
if (max64 <= 0) {
switch (opt_algo) {
case ALGO_LBRY:
max64 = 0x1fffff;
break;
case ALGO_SCRYPT:
max64 = opt_scrypt_n < 16 ? 0x3ffff : 0x3fffff / opt_scrypt_n;
break;
case ALGO_LBRY:
case ALGO_SHA256D:
max64 = 0x1fffff;
break;
}
}
if (work.data[19] + max64 > end_nonce)
if (work.data[19 + offset] + max64 > end_nonce)
max_nonce = end_nonce;
else
max_nonce = work.data[19] + max64;
max_nonce = work.data[19 + offset] + max64;
hashes_done = 0;
gettimeofday(&tv_start, NULL);
@ -1383,8 +1383,8 @@ start:
int err;
if (have_gbt) {
req = malloc(strlen(gbt_lp_req) + strlen(lp_id) + 1 + strlen(GBT_RULES));
sprintf(req, gbt_lp_req, want_segwit ? GBT_RULES : GBT_NO_RULES, lp_id);
req = malloc(strlen(gbt_lp_req) + strlen(lp_id) + 1);
sprintf(req, gbt_lp_req, lp_id);
}
val = json_rpc_call(curl, lp_url, rpc_userpass,
req ? req : getwork_req, &err,
@ -1826,9 +1826,6 @@ static void parse_arg(int key, char *arg, char *pname)
}
strcpy(coinbase_sig, arg);
break;
case 1016:
want_segwit = true;
break;
case 'S':
use_syslog = true;
break;
@ -2039,6 +2036,7 @@ int main(int argc, char *argv[])
}
if (want_stratum) {
/* init stratum thread info */
stratum.job.needs_claimhash = opt_algo == ALGO_LBRY;
stratum_thr_id = opt_n_threads + 2;
thr = &thr_info[stratum_thr_id];
thr->id = stratum_thr_id;

View file

@ -228,6 +228,8 @@ struct stratum_job {
unsigned char ntime[4];
bool clean;
double diff;
unsigned char claimhash[32];
bool needs_claimhash;
};
struct stratum_ctx {

30
util.c
View file

@ -346,7 +346,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
json_error_t err;
struct curl_slist *headers = NULL;
char curl_err_str[CURL_ERROR_SIZE];
long timeout = (flags & JSON_RPC_LONGPOLL) ? opt_timeout : 30;
long timeout = (flags & JSON_RPC_LONGPOLL) ? opt_timeout : 70;
struct header_info hi = {0};
all_data.headers = &hi;
@ -787,7 +787,7 @@ size_t address_to_script(unsigned char *out, size_t outsz, const char *addr)
if (addrver < 0)
return 0;
switch (addrver) {
case 5: /* Bitcoin script hash */
case 0x7a: /* LBRY mainnet script hash */
case 196: /* Testnet script hash */
if (outsz < (rv = 23))
return rv;
@ -1321,25 +1321,27 @@ out:
static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
{
const char *job_id, *prevhash, *coinb1, *coinb2, *version, *nbits, *ntime;
const char *job_id, *prevhash, *coinb1, *coinb2, *version, *nbits, *ntime, *claimhash;
size_t coinb1_size, coinb2_size;
bool clean, ret = false;
int merkle_count, i;
int merkle_count, i, idx = 0;
json_t *merkle_arr;
unsigned char **merkle;
job_id = json_string_value(json_array_get(params, 0));
prevhash = json_string_value(json_array_get(params, 1));
coinb1 = json_string_value(json_array_get(params, 2));
coinb2 = json_string_value(json_array_get(params, 3));
merkle_arr = json_array_get(params, 4);
job_id = json_string_value(json_array_get(params, idx++));
prevhash = json_string_value(json_array_get(params, idx++));
if (sctx->job.needs_claimhash)
claimhash = json_string_value(json_array_get(params, idx++));
coinb1 = json_string_value(json_array_get(params, idx++));
coinb2 = json_string_value(json_array_get(params, idx++));
merkle_arr = json_array_get(params, idx++);
if (!merkle_arr || !json_is_array(merkle_arr))
goto out;
merkle_count = json_array_size(merkle_arr);
version = json_string_value(json_array_get(params, 5));
nbits = json_string_value(json_array_get(params, 6));
ntime = json_string_value(json_array_get(params, 7));
clean = json_is_true(json_array_get(params, 8));
version = json_string_value(json_array_get(params, idx++));
nbits = json_string_value(json_array_get(params, idx++));
ntime = json_string_value(json_array_get(params, idx++));
clean = json_is_true(json_array_get(params, idx++));
if (!job_id || !prevhash || !coinb1 || !coinb2 || !version || !nbits || !ntime ||
strlen(prevhash) != 64 || strlen(version) != 8 ||
@ -1378,6 +1380,8 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
free(sctx->job.job_id);
sctx->job.job_id = strdup(job_id);
hex2bin(sctx->job.prevhash, prevhash, 32);
if (sctx->job.needs_claimhash)
hex2bin(sctx->job.claimhash, claimhash, 32);
for (i = 0; i < sctx->job.merkle_count; i++)
free(sctx->job.merkle[i]);