From f5e77452f0e28100ccdc0e88aae86e3bd7c04e0b Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 17 Nov 2014 00:59:14 +0100 Subject: [PATCH] stratum: prevent a booo when receiving a new block seems to works in solo mode too... note: anime wallet to check, different problem without reject-reason --- ccminer.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ccminer.cpp b/ccminer.cpp index 68c6973..0f1d64b 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -554,14 +554,23 @@ static bool submit_upstream_work(CURL *curl, struct work *work) json_t *val, *res, *reason; char s[345]; int i; + bool stale_work; bool rc = false; - /* pass if the previous hash is not the current previous hash */ pthread_mutex_lock(&g_work_lock); - if (memcmp(work->data + 1, g_work.data + 1, 32)) { + if (strlen(work->job_id + 8)) { + /* stale if not the current job id */ + stale_work = strcmp(work->job_id + 8, g_work.job_id + 8); + } else { + applog_hash((uchar*)&work->data); + /* fallback if not job id (compare hash) */ + stale_work = memcmp(&work->data[1], &g_work.data[1], 32); + } + + if (stale_work) { pthread_mutex_unlock(&g_work_lock); if (opt_debug) - applog(LOG_DEBUG, "stale work detected, discarding"); + applog(LOG_WARNING, "stale work detected, discarding"); return true; } calc_diff(work, 0); @@ -1465,7 +1474,7 @@ start: if (work_decode(json_object_get(val, "result"), &g_work)) { if (opt_debug) applog(LOG_BLUE, "LONGPOLL pushed new work"); - time(&g_work_time); + g_work_time = time(NULL); restart_threads(); } pthread_mutex_unlock(&g_work_lock); @@ -1474,11 +1483,9 @@ start: pthread_mutex_lock(&g_work_lock); g_work_time -= LP_SCANTIME; pthread_mutex_unlock(&g_work_lock); - if (err == CURLE_OPERATION_TIMEDOUT) { - restart_threads(); - } else { + restart_threads(); + if (err != CURLE_OPERATION_TIMEDOUT) { have_longpoll = false; - restart_threads(); free(hdr_path); free(lp_url); lp_url = NULL; @@ -1572,7 +1579,7 @@ static void *stratum_thread(void *userdata) (!g_work_time || strncmp(stratum.job.job_id, g_work.job_id + 8, 120))) { pthread_mutex_lock(&g_work_lock); stratum_gen_work(&stratum, &g_work); - time(&g_work_time); + g_work_time = time(NULL); if (stratum.job.clean) { if (!opt_quiet) applog(LOG_BLUE, "%s %s block %d", short_url, algo_names[opt_algo],