Browse Source

Try to reconnect on pool duplicates

reduce log announces and define uchar in miner.h
master
Tanguy Pruvot 10 years ago
parent
commit
12fafd5687
  1. 6
      README.txt
  2. 2
      blake32.cu
  3. 86
      cpu-miner.c
  4. 2
      miner.h
  5. 46
      util.c

6
README.txt

@ -1,5 +1,5 @@
ccMiner release 1.4.6-tpruvot (Oct 26th 2014) - "S3" ccMiner release 1.4.7-tpruvot (Nov 2014) - "Blake update"
--------------------------------------------------------------- ---------------------------------------------------------------
*************************************************************** ***************************************************************
@ -153,6 +153,10 @@ features.
>>> RELEASE HISTORY <<< >>> RELEASE HISTORY <<<
Nov 2014 v1.4.7
Rewrite blake algo
Update windows prebuilt curl to 7.38.0
Oct. 26th 2014 v1.4.6 Oct. 26th 2014 v1.4.6
Add S3 algo reusing existing code (onecoin) Add S3 algo reusing existing code (onecoin)
Small X11 (simd512) enhancement Small X11 (simd512) enhancement

2
blake32.cu

@ -8,8 +8,6 @@
#include "miner.h" #include "miner.h"
typedef unsigned char uchar;
extern "C" { extern "C" {
#include "sph/sph_blake.h" #include "sph/sph_blake.h"
#include <stdint.h> #include <stdint.h>

86
cpu-miner.c

@ -225,6 +225,7 @@ struct thr_info *thr_info;
static int work_thr_id; static int work_thr_id;
int longpoll_thr_id = -1; int longpoll_thr_id = -1;
int stratum_thr_id = -1; int stratum_thr_id = -1;
bool stratum_need_reset = false;
struct work_restart *work_restart = NULL; struct work_restart *work_restart = NULL;
static struct stratum_ctx stratum; static struct stratum_ctx stratum;
@ -370,7 +371,7 @@ struct work {
char job_id[128]; char job_id[128];
size_t xnonce2_len; size_t xnonce2_len;
unsigned char xnonce2[32]; uchar xnonce2[32];
union { union {
uint32_t u32[2]; uint32_t u32[2];
@ -411,7 +412,7 @@ static bool jobj_binary(const json_t *obj, const char *key,
applog(LOG_ERR, "JSON key '%s' is not a string", key); applog(LOG_ERR, "JSON key '%s' is not a string", key);
return false; return false;
} }
if (!hex2bin((unsigned char*)buf, hexstr, buflen)) if (!hex2bin((uchar*)buf, hexstr, buflen))
return false; return false;
return true; return true;
@ -445,7 +446,7 @@ static bool work_decode(const json_t *val, struct work *work)
const char * hexstr = json_string_value(jr); const char * hexstr = json_string_value(jr);
if (likely(hexstr)) { if (likely(hexstr)) {
// never seen yet... // never seen yet...
hex2bin((unsigned char*)work->noncerange.u64, hexstr, 8); hex2bin((uchar*)work->noncerange.u64, hexstr, 8);
applog(LOG_DEBUG, "received noncerange: %08x-%08x", work->noncerange.u32[0], work->noncerange.u32[1]); applog(LOG_DEBUG, "received noncerange: %08x-%08x", work->noncerange.u32[0], work->noncerange.u32[1]);
} }
} }
@ -517,7 +518,6 @@ static int share_result(int result, const char *reason)
static bool submit_upstream_work(CURL *curl, struct work *work) static bool submit_upstream_work(CURL *curl, struct work *work)
{ {
char *str = NULL;
json_t *val, *res, *reason; json_t *val, *res, *reason;
char s[345]; char s[345];
int i; int i;
@ -528,7 +528,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
if (memcmp(work->data + 1, g_work.data + 1, 32)) { if (memcmp(work->data + 1, g_work.data + 1, 32)) {
pthread_mutex_unlock(&g_work_lock); pthread_mutex_unlock(&g_work_lock);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "DEBUG: stale work detected, discarding"); applog(LOG_DEBUG, "stale work detected, discarding");
return true; return true;
} }
calc_diff(work, 0); calc_diff(work, 0);
@ -544,39 +544,44 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
le32enc(&nonce, work->data[19]); le32enc(&nonce, work->data[19]);
be16enc(&nvote, *((uint16_t*)&work->data[20])); be16enc(&nvote, *((uint16_t*)&work->data[20]));
ntimestr = bin2hex((const unsigned char *)(&ntime), 4); noncestr = bin2hex((const uchar*)(&nonce), 4);
noncestr = bin2hex((const unsigned char *)(&nonce), 4);
xnonce2str = bin2hex(work->xnonce2, work->xnonce2_len);
nvotestr = bin2hex((const unsigned char *)(&nvote), 2);
sent = hashlog_already_submittted(work->job_id, nonce); sent = hashlog_already_submittted(work->job_id, nonce);
if (sent > 0) { if (sent > 0) {
sent = (uint32_t) time(NULL) - sent; sent = (uint32_t) time(NULL) - sent;
if (!opt_quiet) { if (!opt_quiet) {
applog(LOG_WARNING, "skip submit, nonce %s was already sent %u seconds ago", noncestr, sent); applog(LOG_WARNING, "nonce %s was already sent %u seconds ago", noncestr, sent);
hashlog_dump_job(work->job_id); hashlog_dump_job(work->job_id);
} }
rc = true; free(noncestr);
goto out; // prevent useless computing on some pools
stratum_need_reset = true;
for (int i = 0; i < opt_n_threads; i++)
work_restart[i].restart = 1;
return true;
} }
ntimestr = bin2hex((const uchar*)(&ntime), 4);
xnonce2str = bin2hex(work->xnonce2, work->xnonce2_len);
if (opt_algo == ALGO_HEAVY) { if (opt_algo == ALGO_HEAVY) {
nvotestr = bin2hex((const uchar*)(&nvote), 2);
sprintf(s, sprintf(s,
"{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}", "{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}",
rpc_user, work->job_id + 8, xnonce2str, ntimestr, noncestr, nvotestr); rpc_user, work->job_id + 8, xnonce2str, ntimestr, noncestr, nvotestr);
free(nvotestr);
} else { } else {
sprintf(s, sprintf(s,
"{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}", "{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}",
rpc_user, work->job_id + 8, xnonce2str, ntimestr, noncestr); rpc_user, work->job_id + 8, xnonce2str, ntimestr, noncestr);
} }
free(xnonce2str);
free(ntimestr); free(ntimestr);
free(noncestr); free(noncestr);
free(xnonce2str);
free(nvotestr);
if (unlikely(!stratum_send_line(&stratum, s))) { if (unlikely(!stratum_send_line(&stratum, s))) {
applog(LOG_ERR, "submit_upstream_work stratum_send_line failed"); applog(LOG_ERR, "submit_upstream_work stratum_send_line failed");
goto out; return false;
} }
hashlog_remember_submit(work->job_id, nonce, work->scanned_from); hashlog_remember_submit(work->job_id, nonce, work->scanned_from);
@ -584,15 +589,16 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
} else { } else {
/* build hex string */ /* build hex string */
char *str = NULL;
if (opt_algo != ALGO_HEAVY && opt_algo != ALGO_MJOLLNIR) { if (opt_algo != ALGO_HEAVY && opt_algo != ALGO_MJOLLNIR) {
for (i = 0; i < ARRAY_SIZE(work->data); i++) for (i = 0; i < ARRAY_SIZE(work->data); i++)
le32enc(work->data + i, work->data[i]); le32enc(work->data + i, work->data[i]);
} }
str = bin2hex((unsigned char *)work->data, sizeof(work->data)); str = bin2hex((uchar*)work->data, sizeof(work->data));
if (unlikely(!str)) { if (unlikely(!str)) {
applog(LOG_ERR, "submit_upstream_work OOM"); applog(LOG_ERR, "submit_upstream_work OOM");
goto out; return false;
} }
/* build JSON-RPC request */ /* build JSON-RPC request */
@ -604,7 +610,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL); val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL);
if (unlikely(!val)) { if (unlikely(!val)) {
applog(LOG_ERR, "submit_upstream_work json_rpc_call failed"); applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
goto out; return false;
} }
res = json_object_get(val, "result"); res = json_object_get(val, "result");
@ -613,13 +619,11 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
hashlog_purge_job(work->job_id); hashlog_purge_job(work->job_id);
json_decref(val); json_decref(val);
}
rc = true; free(str);
}
out: return true;
free(str);
return rc;
} }
static const char *rpc_req = static const char *rpc_req =
@ -842,7 +846,7 @@ err_out:
static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work) static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
{ {
unsigned char merkle_root[64]; uchar merkle_root[64];
int i; int i;
if (!sctx->job.job_id) { if (!sctx->job.job_id) {
@ -1475,6 +1479,12 @@ static void *stratum_thread(void *userdata)
while (1) { while (1) {
int failures = 0; int failures = 0;
if (stratum_need_reset) {
stratum_need_reset = false;
stratum_disconnect(&stratum);
applog(LOG_DEBUG, "stratum connection reset");
}
while (!stratum.curl) { while (!stratum.curl) {
pthread_mutex_lock(&g_work_lock); pthread_mutex_lock(&g_work_lock);
g_work_time = 0; g_work_time = 0;
@ -1503,11 +1513,11 @@ static void *stratum_thread(void *userdata)
time(&g_work_time); time(&g_work_time);
if (stratum.job.clean) { if (stratum.job.clean) {
if (!opt_quiet) if (!opt_quiet)
applog(LOG_BLUE, "%s sent %s block %d", short_url, algo_names[opt_algo], applog(LOG_BLUE, "%s %s block %d", short_url, algo_names[opt_algo],
stratum.bloc_height); stratum.bloc_height);
restart_threads(); restart_threads();
hashlog_purge_old(); hashlog_purge_old();
} else if (!opt_quiet) { } else if (opt_debug && !opt_quiet) {
applog(LOG_BLUE, "%s asks job %d for block %d", short_url, applog(LOG_BLUE, "%s asks job %d for block %d", short_url,
strtoul(stratum.job.job_id, NULL, 16), stratum.bloc_height); strtoul(stratum.job.job_id, NULL, 16), stratum.bloc_height);
} }
@ -1902,18 +1912,17 @@ int main(int argc, char *argv[])
long flags; long flags;
int i; int i;
printf("*** ccMiner for nVidia GPUs by Christian Buchner and Christian H. ***\n"); printf("*** ccminer " PROGRAM_VERSION " for nVidia GPUs by tpruvot@github ***\n");
printf("\t This is the forked version "PROGRAM_VERSION" (tpruvot@github)\n");
#ifdef WIN32 #ifdef WIN32
printf("\t Built with VC++ 2013 and nVidia CUDA SDK 6.5\n\n"); printf("\tBuilt with VC++ 2013 and nVidia CUDA SDK 6.5\n\n");
#else #else
printf("\t Built with the nVidia CUDA SDK 6.5\n\n"); printf("\tBuilt with the nVidia CUDA SDK 6.5\n\n");
#endif #endif
printf("\t based on pooler-cpuminer 2.3.2 (c) 2010 Jeff Garzik, 2012 pooler\n"); printf(" Based on pooler cpuminer 2.3.2\n");
printf("\t and HVC extension from http://hvc.1gh.com/" "\n\n"); printf(" CUDA support by Christian Buchner and Christian H.\n");
printf("\tCuda additions Copyright 2014 Christian Buchner, Christian H.\n\n"); printf(" Include some of djm34 additions\n\n");
printf("\tInclude some of djm34 additions, cleaned by Tanguy Pruvot\n");
printf("\t BTC donation address: 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo\n\n"); printf("BTC donation address: 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo\n\n");
rpc_user = strdup(""); rpc_user = strdup("");
rpc_pass = strdup(""); rpc_pass = strdup("");
@ -2028,6 +2037,7 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
} }
if (want_stratum) { if (want_stratum) {
/* init stratum thread info */ /* init stratum thread info */
stratum_thr_id = opt_n_threads + 2; stratum_thr_id = opt_n_threads + 2;

2
miner.h

@ -74,6 +74,8 @@ enum {
}; };
#endif #endif
typedef unsigned char uchar;
#undef unlikely #undef unlikely
#undef likely #undef likely
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)

46
util.c

@ -163,7 +163,7 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb,
size_t len = size * nmemb; size_t len = size * nmemb;
size_t oldlen, newlen; size_t oldlen, newlen;
void *newmem; void *newmem;
static const unsigned char zero = 0; static const uchar zero = 0;
oldlen = db->len; oldlen = db->len;
newlen = oldlen + len; newlen = oldlen + len;
@ -517,7 +517,7 @@ void cbin2hex(char *out, const char *in, size_t len)
} }
} }
char *bin2hex(const unsigned char *in, size_t len) char *bin2hex(const uchar *in, size_t len)
{ {
char *s = (char*)malloc((len * 2) + 1); char *s = (char*)malloc((len * 2) + 1);
if (!s) if (!s)
@ -528,7 +528,7 @@ char *bin2hex(const unsigned char *in, size_t len)
return s; return s;
} }
bool hex2bin(unsigned char *p, const char *hexstr, size_t len) bool hex2bin(uchar *p, const char *hexstr, size_t len)
{ {
char hex_byte[3]; char hex_byte[3];
char *ep; char *ep;
@ -542,7 +542,7 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
} }
hex_byte[0] = hexstr[0]; hex_byte[0] = hexstr[0];
hex_byte[1] = hexstr[1]; hex_byte[1] = hexstr[1];
*p = (unsigned char) strtol(hex_byte, &ep, 16); *p = (uchar) strtol(hex_byte, &ep, 16);
if (*ep) { if (*ep) {
applog(LOG_ERR, "hex2bin failed on '%s'", hex_byte); applog(LOG_ERR, "hex2bin failed on '%s'", hex_byte);
return false; return false;
@ -609,8 +609,8 @@ bool fulltest(const uint32_t *hash, const uint32_t *target)
be32enc(hash_be + i, hash[7 - i]); be32enc(hash_be + i, hash[7 - i]);
be32enc(target_be + i, target[7 - i]); be32enc(target_be + i, target[7 - i]);
} }
hash_str = bin2hex((unsigned char *)hash_be, 32); hash_str = bin2hex((uchar *)hash_be, 32);
target_str = bin2hex((unsigned char *)target_be, 32); target_str = bin2hex((uchar *)target_be, 32);
applog(LOG_DEBUG, "DEBUG: %s\nHash: %s\nTarget: %s", applog(LOG_DEBUG, "DEBUG: %s\nHash: %s\nTarget: %s",
rc ? "hash <= target" rc ? "hash <= target"
@ -976,7 +976,7 @@ start:
free(sctx->xnonce1); free(sctx->xnonce1);
sctx->session_id = sid ? strdup(sid) : NULL; sctx->session_id = sid ? strdup(sid) : NULL;
sctx->xnonce1_size = strlen(xnonce1) / 2; sctx->xnonce1_size = strlen(xnonce1) / 2;
sctx->xnonce1 = (unsigned char*)malloc(sctx->xnonce1_size); sctx->xnonce1 = (uchar*) malloc(sctx->xnonce1_size);
hex2bin(sctx->xnonce1, xnonce1, sctx->xnonce1_size); hex2bin(sctx->xnonce1, xnonce1, sctx->xnonce1_size);
sctx->xnonce2_size = xn2_size; sctx->xnonce2_size = xn2_size;
sctx->next_diff = 1.0; sctx->next_diff = 1.0;
@ -1088,7 +1088,7 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
bool clean, ret = false; bool clean, ret = false;
int merkle_count, i; int merkle_count, i;
json_t *merkle_arr; json_t *merkle_arr;
unsigned char **merkle; uchar **merkle;
int ntime; int ntime;
job_id = json_string_value(json_array_get(params, 0)); job_id = json_string_value(json_array_get(params, 0));
@ -1113,15 +1113,15 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
} }
/* store stratum server time diff */ /* store stratum server time diff */
hex2bin((unsigned char *)&ntime, stime, 4); hex2bin((uchar *)&ntime, stime, 4);
ntime = swab32(ntime) - (uint32_t) time(0); ntime = swab32(ntime) - (uint32_t) time(0);
if (ntime > sctx->srvtime_diff) { if (ntime > sctx->srvtime_diff) {
sctx->srvtime_diff = ntime; sctx->srvtime_diff = ntime;
if (!opt_quiet) if (!opt_quiet && ntime > 20)
applog(LOG_DEBUG, "stratum time is at least %ds in the future", ntime); applog(LOG_DEBUG, "stratum time is at least %ds in the future", ntime);
} }
merkle = (unsigned char**)malloc(merkle_count * sizeof(char *)); merkle = (uchar**) malloc(merkle_count * sizeof(char *));
for (i = 0; i < merkle_count; i++) { for (i = 0; i < merkle_count; i++) {
const char *s = json_string_value(json_array_get(merkle_arr, i)); const char *s = json_string_value(json_array_get(merkle_arr, i));
if (!s || strlen(s) != 64) { if (!s || strlen(s) != 64) {
@ -1131,7 +1131,7 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
applog(LOG_ERR, "Stratum notify: invalid Merkle branch"); applog(LOG_ERR, "Stratum notify: invalid Merkle branch");
goto out; goto out;
} }
merkle[i] = (unsigned char*)malloc(32); merkle[i] = (uchar*) malloc(32);
hex2bin(merkle[i], s, 32); hex2bin(merkle[i], s, 32);
} }
@ -1142,7 +1142,7 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
sctx->job.coinbase_size = coinb1_size + sctx->xnonce1_size + sctx->job.coinbase_size = coinb1_size + sctx->xnonce1_size +
sctx->xnonce2_size + coinb2_size; sctx->xnonce2_size + coinb2_size;
sctx->job.coinbase = (unsigned char*)realloc(sctx->job.coinbase, sctx->job.coinbase_size); sctx->job.coinbase = (uchar*) realloc(sctx->job.coinbase, sctx->job.coinbase_size);
sctx->job.xnonce2 = sctx->job.coinbase + coinb1_size + sctx->xnonce1_size; sctx->job.xnonce2 = sctx->job.coinbase + coinb1_size + sctx->xnonce1_size;
hex2bin(sctx->job.coinbase, coinb1, coinb1_size); hex2bin(sctx->job.coinbase, coinb1, coinb1_size);
memcpy(sctx->job.coinbase + coinb1_size, sctx->xnonce1, sctx->xnonce1_size); memcpy(sctx->job.coinbase + coinb1_size, sctx->xnonce1, sctx->xnonce1_size);
@ -1456,7 +1456,7 @@ char* atime2str(time_t timer)
} }
/* sprintf can be used in applog */ /* sprintf can be used in applog */
static char* format_hash(char* buf, unsigned char *hash) static char* format_hash(char* buf, uchar *hash)
{ {
int len = 0; int len = 0;
for (int i=0; i < 32; i += 4) { for (int i=0; i < 32; i += 4) {
@ -1467,7 +1467,7 @@ static char* format_hash(char* buf, unsigned char *hash)
} }
/* to debug diff in data */ /* to debug diff in data */
extern void applog_compare_hash(unsigned char *hash, unsigned char *hash2) extern void applog_compare_hash(uchar *hash, uchar *hash2)
{ {
char s[256] = ""; char s[256] = "";
int len = 0; int len = 0;
@ -1480,7 +1480,7 @@ extern void applog_compare_hash(unsigned char *hash, unsigned char *hash2)
applog(LOG_DEBUG, "%s", s); applog(LOG_DEBUG, "%s", s);
} }
extern void applog_hash(unsigned char *hash) extern void applog_hash(uchar *hash)
{ {
char s[128] = {'\0'}; char s[128] = {'\0'};
applog(LOG_DEBUG, "%s", format_hash(s, hash)); applog(LOG_DEBUG, "%s", format_hash(s, hash));
@ -1495,15 +1495,19 @@ void do_gpu_tests(void)
#ifdef _DEBUG #ifdef _DEBUG
unsigned long done; unsigned long done;
char s[128] = { '\0' }; char s[128] = { '\0' };
unsigned char buf[128], hash[128]; uchar buf[128], hash[128];
uint32_t tgt[8] = { 0 }; uint32_t tgt[8] = { 0 };
memset(buf, 0, sizeof buf); memset(buf, 0, sizeof buf);
buf[0] = 1; buf[64] = 2; buf[0] = 1; buf[64] = 2;
opt_tracegpu = true; opt_tracegpu = true;
work_restart = (struct work_restart*) malloc(sizeof(struct work_restart)); work_restart = (struct work_restart*) malloc(sizeof(struct work_restart));
work_restart[0].restart = 1; work_restart[0].restart = 1;
tgt[6] = 0xffff; tgt[6] = 0xffff;
scanhash_blake256(0, (uint32_t*)buf, tgt, 1, &done, 14); scanhash_blake256(0, (uint32_t*)buf, tgt, 1, &done, 14);
free(work_restart); free(work_restart);
work_restart = NULL; work_restart = NULL;
opt_tracegpu = false; opt_tracegpu = false;
@ -1513,9 +1517,9 @@ void do_gpu_tests(void)
void print_hash_tests(void) void print_hash_tests(void)
{ {
char s[128] = {'\0'}; char s[128] = {'\0'};
unsigned char buf[128], hash[128]; uchar buf[128], hash[128];
memset(buf, 0, sizeof buf); memset(buf, 0, sizeof buf);
// buf[0] = 1; buf[64] = 2; // buf[0] = 1; buf[64] = 2; // for endian tests
printf(CL_WHT "CPU HASH ON EMPTY BUFFER RESULTS:" CL_N "\n"); printf(CL_WHT "CPU HASH ON EMPTY BUFFER RESULTS:" CL_N "\n");
@ -1531,8 +1535,6 @@ void print_hash_tests(void)
blake256hash(&hash[0], &buf[0], 14); blake256hash(&hash[0], &buf[0], 14);
printpfx("blake", hash); printpfx("blake", hash);
do_gpu_tests();
memset(hash, 0, sizeof hash); memset(hash, 0, sizeof hash);
deephash(&hash[0], &buf[0]); deephash(&hash[0], &buf[0]);
printpfx("deep", hash); printpfx("deep", hash);
@ -1614,4 +1616,6 @@ void print_hash_tests(void)
printpfx("X17", hash); printpfx("X17", hash);
printf("\n"); printf("\n");
do_gpu_tests();
} }

Loading…
Cancel
Save