mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-10 23:08:07 +00:00
Add BLOCK! notification and remove end of line blanks when not needed
This commit is contained in:
parent
3dae209d4e
commit
8ecd15a616
61
main.c
61
main.c
@ -217,7 +217,7 @@ static int opt_n_threads;
|
|||||||
static int mining_threads;
|
static int mining_threads;
|
||||||
static int num_processors;
|
static int num_processors;
|
||||||
static int scan_intensity;
|
static int scan_intensity;
|
||||||
static bool use_curses = true;
|
bool use_curses = true;
|
||||||
static bool opt_submit_stale;
|
static bool opt_submit_stale;
|
||||||
static bool opt_nogpu;
|
static bool opt_nogpu;
|
||||||
static bool opt_usecpu;
|
static bool opt_usecpu;
|
||||||
@ -2005,13 +2005,19 @@ void clear_logwin(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* regenerate the full work->hash value */
|
/* regenerate the full work->hash value and also return true if it's a block */
|
||||||
void regeneratehash(const struct work *work)
|
bool regeneratehash(const struct work *work)
|
||||||
{
|
{
|
||||||
uint32_t *data32 = (uint32_t *)(work->data);
|
uint32_t *data32 = (uint32_t *)(work->data);
|
||||||
unsigned char swap[128];
|
unsigned char swap[128];
|
||||||
uint32_t *swap32 = (uint32_t *)swap;
|
uint32_t *swap32 = (uint32_t *)swap;
|
||||||
unsigned char hash1[SHA256_DIGEST_LENGTH];
|
unsigned char hash1[SHA256_DIGEST_LENGTH];
|
||||||
|
uint32_t *hash32 = (uint32_t *)(work->hash);
|
||||||
|
uint32_t difficulty = 0;
|
||||||
|
uint32_t diffbytes = 0;
|
||||||
|
uint32_t diffvalue = 0;
|
||||||
|
uint32_t diffcmp[8];
|
||||||
|
int diffshift = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 80/4; i++)
|
for (i = 0; i < 80/4; i++)
|
||||||
@ -2019,6 +2025,36 @@ void regeneratehash(const struct work *work)
|
|||||||
|
|
||||||
SHA256(swap, 80, hash1);
|
SHA256(swap, 80, hash1);
|
||||||
SHA256(hash1, SHA256_DIGEST_LENGTH, (unsigned char *)(work->hash));
|
SHA256(hash1, SHA256_DIGEST_LENGTH, (unsigned char *)(work->hash));
|
||||||
|
|
||||||
|
difficulty = swab32(*((uint32_t *)(work->data + 72)));
|
||||||
|
|
||||||
|
diffbytes = ((difficulty >> 24) & 0xff) - 3;
|
||||||
|
diffvalue = difficulty & 0x00ffffff;
|
||||||
|
|
||||||
|
diffshift = (diffbytes % 4) * 8;
|
||||||
|
if (diffshift == 0) {
|
||||||
|
diffshift = 32;
|
||||||
|
diffbytes--;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(diffcmp, 0, 32);
|
||||||
|
diffcmp[(diffbytes >> 2) + 1] = diffvalue >> (32 - diffshift);
|
||||||
|
diffcmp[diffbytes >> 2] = diffvalue << diffshift;
|
||||||
|
|
||||||
|
for (i = 7; i >= 0; i--) {
|
||||||
|
if (hash32[i] > diffcmp[i])
|
||||||
|
return false;
|
||||||
|
if (hash32[i] < diffcmp[i])
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://en.bitcoin.it/wiki/Block says: "numerically below"
|
||||||
|
// https://en.bitcoin.it/wiki/Target says: "lower than or equal to"
|
||||||
|
// code in bitcoind 0.3.24 main.cpp CheckWork() says: if (hash > hashTarget) return false;
|
||||||
|
if (hash32[0] == diffcmp[0])
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool submit_upstream_work(const struct work *work)
|
static bool submit_upstream_work(const struct work *work)
|
||||||
@ -2033,7 +2069,8 @@ static bool submit_upstream_work(const struct work *work)
|
|||||||
struct pool *pool = work->pool;
|
struct pool *pool = work->pool;
|
||||||
bool rolltime;
|
bool rolltime;
|
||||||
uint32_t *hash32;
|
uint32_t *hash32;
|
||||||
char hashshow[32+1] = "";
|
char hashshow[64+1] = "";
|
||||||
|
bool isblock;
|
||||||
|
|
||||||
if (unlikely(!curl)) {
|
if (unlikely(!curl)) {
|
||||||
applog(LOG_ERR, "CURL initialisation failed");
|
applog(LOG_ERR, "CURL initialisation failed");
|
||||||
@ -2074,11 +2111,11 @@ static bool submit_upstream_work(const struct work *work)
|
|||||||
res = json_object_get(val, "result");
|
res = json_object_get(val, "result");
|
||||||
|
|
||||||
if (!QUIET) {
|
if (!QUIET) {
|
||||||
regeneratehash(work);
|
isblock = regeneratehash(work);
|
||||||
hash32 = (uint32_t *)(work->hash);
|
hash32 = (uint32_t *)(work->hash);
|
||||||
sprintf(hashshow, "%08lx%08lx%08lx%08lx",
|
sprintf(hashshow, "%08lx.%08lx.%08lx%s",
|
||||||
(unsigned long)(hash32[7]), (unsigned long)(hash32[6]),
|
(unsigned long)(hash32[7]), (unsigned long)(hash32[6]), (unsigned long)(hash32[5]),
|
||||||
(unsigned long)(hash32[5]), (unsigned long)(hash32[4]));
|
isblock ? " BLOCK!" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Theoretically threads could race when modifying accepted and
|
/* Theoretically threads could race when modifying accepted and
|
||||||
@ -2092,10 +2129,10 @@ static bool submit_upstream_work(const struct work *work)
|
|||||||
applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)");
|
applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)");
|
||||||
if (!QUIET) {
|
if (!QUIET) {
|
||||||
if (total_pools > 1)
|
if (total_pools > 1)
|
||||||
applog(LOG_NOTICE, "Accepted %.32s %sPU %d thread %d pool %d",
|
applog(LOG_NOTICE, "Accepted %s %sPU %d thread %d pool %d",
|
||||||
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
|
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
|
||||||
else
|
else
|
||||||
applog(LOG_NOTICE, "Accepted %.32s %sPU %d thread %d",
|
applog(LOG_NOTICE, "Accepted %s %sPU %d thread %d",
|
||||||
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id);
|
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id);
|
||||||
}
|
}
|
||||||
if (opt_shares && total_accepted >= opt_shares) {
|
if (opt_shares && total_accepted >= opt_shares) {
|
||||||
@ -2111,10 +2148,10 @@ static bool submit_upstream_work(const struct work *work)
|
|||||||
applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
|
applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
|
||||||
if (!QUIET) {
|
if (!QUIET) {
|
||||||
if (total_pools > 1)
|
if (total_pools > 1)
|
||||||
applog(LOG_NOTICE, "Rejected %.32s %sPU %d thread %d pool %d",
|
applog(LOG_NOTICE, "Rejected %s %sPU %d thread %d pool %d",
|
||||||
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
|
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
|
||||||
else
|
else
|
||||||
applog(LOG_NOTICE, "Rejected %.32s %sPU %d thread %d",
|
applog(LOG_NOTICE, "Rejected %s %sPU %d thread %d",
|
||||||
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id);
|
hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
util.c
13
util.c
@ -65,6 +65,8 @@ struct tq_ent {
|
|||||||
|
|
||||||
void vapplog(int prio, const char *fmt, va_list ap)
|
void vapplog(int prio, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
|
extern bool use_curses;
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
#ifdef HAVE_SYSLOG_H
|
||||||
if (use_syslog) {
|
if (use_syslog) {
|
||||||
vsyslog(prio, fmt, ap);
|
vsyslog(prio, fmt, ap);
|
||||||
@ -84,7 +86,7 @@ void vapplog(int prio, const char *fmt, va_list ap)
|
|||||||
|
|
||||||
len = 40 + strlen(fmt) + 22;
|
len = 40 + strlen(fmt) + 22;
|
||||||
f = alloca(len);
|
f = alloca(len);
|
||||||
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s \n",
|
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n",
|
||||||
tm.tm_year + 1900,
|
tm.tm_year + 1900,
|
||||||
tm.tm_mon + 1,
|
tm.tm_mon + 1,
|
||||||
tm.tm_mday,
|
tm.tm_mday,
|
||||||
@ -100,7 +102,16 @@ void vapplog(int prio, const char *fmt, va_list ap)
|
|||||||
vfprintf(stderr, f, apc); /* atomic write to stderr */
|
vfprintf(stderr, f, apc); /* atomic write to stderr */
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (use_curses)
|
||||||
log_curses(prio, f, ap);
|
log_curses(prio, f, ap);
|
||||||
|
else {
|
||||||
|
int len = strlen(f);
|
||||||
|
|
||||||
|
strcpy(f + len - 1, " \n");
|
||||||
|
|
||||||
|
log_curses(prio, f, ap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user