hashlog: use work objects, put struct in miner.h
This commit is contained in:
parent
bdfce54c3b
commit
6a9b8a5ab2
35
ccminer.cpp
35
ccminer.cpp
@ -238,7 +238,7 @@ int opt_statsavg = 30;
|
||||
int opt_intensity = 0;
|
||||
uint32_t opt_work_size = 0; /* default */
|
||||
|
||||
char *opt_api_allow = "127.0.0.1"; /* 0.0.0.0 for all ips */
|
||||
char *opt_api_allow = (char*) "127.0.0.1"; /* 0.0.0.0 for all ips */
|
||||
int opt_api_listen = 4068; /* 0 to disable */
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
@ -376,26 +376,6 @@ static struct option const options[] = {
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
struct work {
|
||||
uint32_t data[32];
|
||||
uint32_t target[8];
|
||||
uint32_t maxvote;
|
||||
|
||||
char job_id[128];
|
||||
size_t xnonce2_len;
|
||||
uchar xnonce2[32];
|
||||
|
||||
union {
|
||||
uint32_t u32[2];
|
||||
uint64_t u64[1];
|
||||
} noncerange;
|
||||
|
||||
double difficulty;
|
||||
|
||||
uint32_t scanned_from;
|
||||
uint32_t scanned_to;
|
||||
};
|
||||
|
||||
static struct work _ALIGN(64) g_work;
|
||||
static time_t g_work_time;
|
||||
static pthread_mutex_t g_work_lock;
|
||||
@ -626,7 +606,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||
return false;
|
||||
}
|
||||
|
||||
hashlog_remember_submit(work->job_id, nonce, work->scanned_from);
|
||||
hashlog_remember_submit(work, nonce);
|
||||
|
||||
} else {
|
||||
|
||||
@ -904,6 +884,9 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
||||
work->xnonce2_len = sctx->xnonce2_size;
|
||||
memcpy(work->xnonce2, sctx->job.xnonce2, sctx->xnonce2_size);
|
||||
|
||||
// also store the bloc number
|
||||
work->height = sctx->job.height;
|
||||
|
||||
/* Generate merkle root */
|
||||
switch (opt_algo) {
|
||||
case ALGO_HEAVY:
|
||||
@ -1369,7 +1352,7 @@ continue_scan:
|
||||
}
|
||||
}
|
||||
|
||||
hashlog_remember_scan_range(work.job_id, work.scanned_from, work.scanned_to);
|
||||
hashlog_remember_scan_range(&work);
|
||||
|
||||
/* output */
|
||||
if (!opt_quiet && loopcnt) {
|
||||
@ -1583,13 +1566,13 @@ static void *stratum_thread(void *userdata)
|
||||
if (stratum.job.clean) {
|
||||
if (!opt_quiet)
|
||||
applog(LOG_BLUE, "%s %s block %d", short_url, algo_names[opt_algo],
|
||||
stratum.bloc_height);
|
||||
stratum.job.height);
|
||||
restart_threads();
|
||||
hashlog_purge_old();
|
||||
stats_purge_old();
|
||||
} 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);
|
||||
strtoul(stratum.job.job_id, NULL, 16), stratum.job.height);
|
||||
}
|
||||
pthread_mutex_unlock(&g_work_lock);
|
||||
}
|
||||
@ -1935,7 +1918,7 @@ static void parse_config(void)
|
||||
}
|
||||
else if (!options[i].has_arg) {
|
||||
if (json_is_true(val))
|
||||
parse_arg(options[i].val, "");
|
||||
parse_arg(options[i].val, (char*) "");
|
||||
}
|
||||
else
|
||||
applog(LOG_ERR, "JSON option %s invalid",
|
||||
|
32
hashlog.cpp
32
hashlog.cpp
@ -18,6 +18,7 @@
|
||||
|
||||
struct hashlog_data {
|
||||
uint32_t tm_sent;
|
||||
uint32_t height;
|
||||
uint32_t scanned_from;
|
||||
uint32_t scanned_to;
|
||||
uint32_t last_from;
|
||||
@ -60,15 +61,16 @@ extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce)
|
||||
/**
|
||||
* Store submitted nonces of a job
|
||||
*/
|
||||
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint32_t scanned_from)
|
||||
extern "C" void hashlog_remember_submit(struct work* work, uint32_t nonce)
|
||||
{
|
||||
uint64_t njobid = hextouint(jobid);
|
||||
uint64_t njobid = hextouint(work->job_id);
|
||||
uint64_t key = (njobid << 32) + nonce;
|
||||
hashlog_data data;
|
||||
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.scanned_from = scanned_from;
|
||||
data.scanned_from = work->scanned_from;
|
||||
data.scanned_to = nonce;
|
||||
data.height = work->height;
|
||||
data.tm_add = data.tm_upd = data.tm_sent = (uint32_t) time(NULL);
|
||||
tlastshares[key] = data;
|
||||
}
|
||||
@ -76,11 +78,11 @@ extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint32_t sc
|
||||
/**
|
||||
* Update job scanned range
|
||||
*/
|
||||
extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from, uint32_t scanned_to)
|
||||
extern "C" void hashlog_remember_scan_range(struct work* work)
|
||||
{
|
||||
uint64_t njobid = hextouint(jobid);
|
||||
uint64_t njobid = hextouint(work->job_id);
|
||||
uint64_t key = (njobid << 32);
|
||||
uint64_t range = hashlog_get_scan_range(jobid);
|
||||
uint64_t range = hashlog_get_scan_range(work->job_id);
|
||||
hashlog_data data;
|
||||
|
||||
// global scan range of a job
|
||||
@ -96,15 +98,15 @@ extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from,
|
||||
if (data.tm_add == 0)
|
||||
data.tm_add = (uint32_t) time(NULL);
|
||||
|
||||
data.last_from = scanned_from;
|
||||
data.last_from = work->scanned_from;
|
||||
|
||||
if (scanned_from < scanned_to) {
|
||||
if (data.scanned_to == 0 || scanned_from == data.scanned_to + 1)
|
||||
data.scanned_to = scanned_to;
|
||||
if (work->scanned_from < work->scanned_to) {
|
||||
if (data.scanned_to == 0 || work->scanned_from == data.scanned_to + 1)
|
||||
data.scanned_to = work->scanned_to;
|
||||
if (data.scanned_from == 0)
|
||||
data.scanned_from = scanned_from ? scanned_from : 1; // min 1
|
||||
else if (scanned_from < data.scanned_from || scanned_to == (data.scanned_from - 1))
|
||||
data.scanned_from = scanned_from;
|
||||
data.scanned_from = work->scanned_from ? work->scanned_from : 1; // min 1
|
||||
else if (work->scanned_from < data.scanned_from || work->scanned_to == (data.scanned_from - 1))
|
||||
data.scanned_from = work->scanned_from;
|
||||
}
|
||||
|
||||
data.tm_upd = (uint32_t) time(NULL);
|
||||
@ -228,8 +230,8 @@ extern "C" void hashlog_dump_job(char* jobid)
|
||||
if (i->first != keypfx)
|
||||
applog(LOG_DEBUG, CL_YLW "job %s, found %08x ", jobid, LO_DWORD(i->first));
|
||||
else
|
||||
applog(LOG_DEBUG, CL_YLW "job %s scanned range : %08x-%08x", jobid,
|
||||
i->second.scanned_from, i->second.scanned_to);
|
||||
applog(LOG_DEBUG, CL_YLW "job %s(%u) range done: %08x-%08x", jobid,
|
||||
i->second.height, i->second.scanned_from, i->second.scanned_to);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
27
miner.h
27
miner.h
@ -479,6 +479,7 @@ struct stratum_job {
|
||||
unsigned char ntime[4];
|
||||
bool clean;
|
||||
unsigned char nreward[2];
|
||||
uint32_t height;
|
||||
double diff;
|
||||
};
|
||||
|
||||
@ -503,7 +504,27 @@ struct stratum_ctx {
|
||||
pthread_mutex_t work_lock;
|
||||
|
||||
int srvtime_diff;
|
||||
int bloc_height;
|
||||
};
|
||||
|
||||
struct work {
|
||||
uint32_t data[32];
|
||||
uint32_t target[8];
|
||||
uint32_t maxvote;
|
||||
|
||||
char job_id[128];
|
||||
size_t xnonce2_len;
|
||||
uchar xnonce2[32];
|
||||
|
||||
union {
|
||||
uint32_t u32[2];
|
||||
uint64_t u64[1];
|
||||
} noncerange;
|
||||
|
||||
double difficulty;
|
||||
uint32_t height;
|
||||
|
||||
uint32_t scanned_from;
|
||||
uint32_t scanned_to;
|
||||
};
|
||||
|
||||
struct stats_data {
|
||||
@ -526,8 +547,8 @@ bool stratum_subscribe(struct stratum_ctx *sctx);
|
||||
bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass);
|
||||
bool stratum_handle_method(struct stratum_ctx *sctx, const char *s);
|
||||
|
||||
void hashlog_remember_submit(char* jobid, uint32_t nounce, uint32_t scanned_from);
|
||||
void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from, uint32_t scanned_to);
|
||||
void hashlog_remember_submit(struct work* work, uint32_t nonce);
|
||||
void hashlog_remember_scan_range(struct work* work);
|
||||
uint32_t hashlog_already_submittted(char* jobid, uint32_t nounce);
|
||||
uint32_t hashlog_get_last_sent(char* jobid);
|
||||
uint64_t hashlog_get_scan_range(char* jobid);
|
||||
|
2
util.cpp
2
util.cpp
@ -1157,7 +1157,7 @@ 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);
|
||||
sctx->job.height = getblocheight(sctx);
|
||||
|
||||
for (i = 0; i < sctx->job.merkle_count; i++)
|
||||
free(sctx->job.merkle[i]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user