diff --git a/NEWS b/NEWS index a39ceb594..2c3721940 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ Version 1.0.7 (Tanguy Pruvot) - Add NIST5 and QUBIT algos +- Show current stratum bloc height Version 1.0.6 (Tanguy Pruvot) - Fix scrypt algo diff --git a/README.md b/README.md index 7a16d4998..a19f469a3 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Algorithms * ✓ __cryptonight__ (Bytecoin [BCN], Monero) * ✓ __fresh__ (FreshCoin) * ✓ __neoscrypt__ (Feathercoin) - * ✓ __nist5__ + * ✓ __nist5__ (TalkCoin [TAC], [UPM]) * ✓ __pentablake__ (Joincoin) - * ✓ __qubit__ + * ✓ __qubit__ (MyriadCoin [MYR]) * ✓ __s3__ (OneCoin) * ✓ __x11__ (Darkcoin [DRK], Hirocoin, Limecoin) * ✓ __x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..) diff --git a/configure.ac b/configure.ac index 3ac1dc1b8..42d675063 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ AC_CHECK_HEADERS([sys/sysctl.h], [], [], #endif ]) -AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [], +AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc, le16dec, le16enc], [], [], [AC_INCLUDES_DEFAULT #ifdef HAVE_SYS_ENDIAN_H #include diff --git a/cpu-miner.c b/cpu-miner.c index 877b53254..410023bab 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -194,6 +194,7 @@ static int num_processors; static char *rpc_url; static char *rpc_userpass; static char *rpc_user, *rpc_pass; +static char *short_url = NULL; static int pk_script_size; static unsigned char pk_script[25]; static char coinbase_sig[101] = ""; @@ -1555,6 +1556,9 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work) case ALGO_NEOSCRYPT: diff_to_target(work->target, sctx->job.diff / (65536.0 * opt_diff_factor)); break; + case ALGO_QUBIT: + diff_to_target(work->target, sctx->job.diff / (256.0 * opt_diff_factor)); + break; default: diff_to_target(work->target, sctx->job.diff / opt_diff_factor); } @@ -2064,29 +2068,22 @@ static void *stratum_thread(void *userdata) } } - if (jsonrpc_2) { - if (stratum.work.job_id - && (!g_work_time - || strcmp(stratum.work.job_id, g_work.job_id))) { - pthread_mutex_lock(&g_work_lock); - stratum_gen_work(&stratum, &g_work); - time(&g_work_time); - pthread_mutex_unlock(&g_work_lock); - applog(LOG_BLUE, "Stratum requested work restart"); + if (stratum.job.job_id && + (!g_work_time || strcmp(stratum.job.job_id, g_work.job_id)) ) + { + pthread_mutex_lock(&g_work_lock); + stratum_gen_work(&stratum, &g_work); + time(&g_work_time); + pthread_mutex_unlock(&g_work_lock); + + if (stratum.job.clean || jsonrpc_2) { + if (!opt_quiet) + applog(LOG_BLUE, "%s sent %s block %d", short_url, algo_names[opt_algo], + stratum.bloc_height); restart_threads(); - } - } else { - if (stratum.job.job_id - && (!g_work_time - || strcmp(stratum.job.job_id, g_work.job_id))) { - pthread_mutex_lock(&g_work_lock); - stratum_gen_work(&stratum, &g_work); - time(&g_work_time); - pthread_mutex_unlock(&g_work_lock); - if (stratum.job.clean) { - applog(LOG_BLUE, "Stratum requested work restart"); - restart_threads(); - } + } else if (opt_debug && !opt_quiet) { + applog(LOG_BLUE, "%s asks job %d for block %d", short_url, + strtoul(stratum.job.job_id, NULL, 16), stratum.bloc_height); } } @@ -2339,6 +2336,7 @@ static void parse_arg(int key, char *arg, char *pname) free(rpc_url); rpc_url = strdup(arg); strcpy(rpc_url + (ap - arg), hp); + short_url = &rpc_url[(ap - arg) + 3]; } else { if (*hp == '\0' || *hp == '/') { fprintf(stderr, "%s: invalid URL -- '%s'\n", @@ -2348,6 +2346,7 @@ static void parse_arg(int key, char *arg, char *pname) free(rpc_url); rpc_url = (char*) malloc(strlen(hp) + 8); sprintf(rpc_url, "http://%s", hp); + short_url = &rpc_url[sizeof("http://")-1]; } have_stratum = !opt_benchmark && !strncasecmp(rpc_url, "stratum", 7); break; diff --git a/miner.h b/miner.h index 9b51ebefa..68aeda6dd 100644 --- a/miner.h +++ b/miner.h @@ -154,6 +154,23 @@ static inline void le32enc(void *pp, uint32_t x) } #endif +#if !HAVE_DECL_LE16DEC +static inline uint16_t le16dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8)); +} +#endif + +#if !HAVE_DECL_LE16ENC +static inline void le16enc(void *pp, uint16_t x) +{ + uint8_t *p = (uint8_t *)pp; + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; +} +#endif + #if JANSSON_MAJOR_VERSION >= 2 #define JSON_LOADS(str, err_ptr) json_loads(str, 0, err_ptr) #define JSON_LOAD_FILE(path, err_ptr) json_load_file(path, 0, err_ptr) @@ -375,6 +392,8 @@ struct stratum_ctx { struct stratum_job job; struct work work; pthread_mutex_t work_lock; + + int bloc_height; }; bool stratum_socket_full(struct stratum_ctx *sctx, int timeout); diff --git a/util.c b/util.c index 14ca9b9d6..6e3a5db79 100644 --- a/util.c +++ b/util.c @@ -1230,6 +1230,36 @@ static bool stratum_2_job(struct stratum_ctx *sctx, json_t *params) return ret; } +/** + * Extract bloc height L H... here len=3, height=0x1333e8 + * "...0000000000ffffffff2703e83313062f503253482f043d61105408" + */ +static uint32_t getblocheight(struct stratum_ctx *sctx) +{ + uint32_t height = 0; + uint8_t hlen = 0, *p, *m; + + // find 0xffff tag + p = (uint8_t*) sctx->job.coinbase + 32; + m = p + 128; + while (*p != 0xff && p < m) p++; + while (*p == 0xff && p < m) p++; + if (*(p-1) == 0xff && *(p-2) == 0xff) { + p++; hlen = *p; + p++; height = le16dec(p); + p += 2; + switch (hlen) { + case 4: + height += 0x10000UL * le16dec(p); + break; + case 3: + height += 0x10000UL * (*p); + break; + } + } + return height; +} + static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) { const char *job_id, *prevhash, *coinb1, *coinb2, *version, *nbits, *ntime; @@ -1290,6 +1320,8 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params) sctx->job.job_id = strdup(job_id); hex2bin(sctx->job.prevhash, prevhash, 32); + sctx->bloc_height = getblocheight(sctx); + for (i = 0; i < sctx->job.merkle_count; i++) free(sctx->job.merkle[i]); free(sctx->job.merkle);