|
@@ -42,12 +42,8 @@ static notifier_t _ssm_update_notifier;
|
|
|
struct stratumsrv_job {
|
|
struct stratumsrv_job {
|
|
|
char *my_job_id;
|
|
char *my_job_id;
|
|
|
|
|
|
|
|
- struct pool *pool;
|
|
|
|
|
- uint8_t work_restart_id;
|
|
|
|
|
- uint8_t n2size;
|
|
|
|
|
struct timeval tv_prepared;
|
|
struct timeval tv_prepared;
|
|
|
struct stratum_work swork;
|
|
struct stratum_work swork;
|
|
|
- char *nonce1;
|
|
|
|
|
|
|
|
|
|
UT_hash_handle hh;
|
|
UT_hash_handle hh;
|
|
|
};
|
|
};
|
|
@@ -71,31 +67,7 @@ struct stratumsrv_conn {
|
|
|
|
|
|
|
|
static struct stratumsrv_conn *_ssm_connections;
|
|
static struct stratumsrv_conn *_ssm_connections;
|
|
|
|
|
|
|
|
-static
|
|
|
|
|
-void _ssm_gen_dummy_work(struct work *work, struct stratumsrv_job *ssj, const char * const extranonce2, uint32_t xnonce1)
|
|
|
|
|
-{
|
|
|
|
|
- uint8_t *p, *s;
|
|
|
|
|
-
|
|
|
|
|
- *work = (struct work){
|
|
|
|
|
- .pool = ssj->pool,
|
|
|
|
|
- .work_restart_id = ssj->work_restart_id,
|
|
|
|
|
- .tv_staged = ssj->tv_prepared,
|
|
|
|
|
- };
|
|
|
|
|
- bytes_resize(&work->nonce2, ssj->n2size);
|
|
|
|
|
- s = bytes_buf(&work->nonce2);
|
|
|
|
|
- p = &s[ssj->n2size - _ssm_client_xnonce2sz];
|
|
|
|
|
- if (extranonce2)
|
|
|
|
|
- hex2bin(p, extranonce2, _ssm_client_xnonce2sz);
|
|
|
|
|
-#ifndef __OPTIMIZE__
|
|
|
|
|
- else
|
|
|
|
|
- memset(p, '\0', _ssm_client_xnonce2sz);
|
|
|
|
|
-#endif
|
|
|
|
|
- p -= _ssm_client_octets;
|
|
|
|
|
- memcpy(p, &xnonce1, _ssm_client_octets);
|
|
|
|
|
- if (p != s)
|
|
|
|
|
- memset(s, '\xbb', p - s);
|
|
|
|
|
- gen_stratum_work2(work, &ssj->swork, ssj->nonce1);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+#define _ssm_gen_dummy_work work2d_gen_dummy_work
|
|
|
|
|
|
|
|
static
|
|
static
|
|
|
bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
@@ -104,11 +76,11 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
|
|
|
|
|
|
struct stratumsrv_conn *conn;
|
|
struct stratumsrv_conn *conn;
|
|
|
const struct stratum_work * const swork = &pool->swork;
|
|
const struct stratum_work * const swork = &pool->swork;
|
|
|
- const int n2size = pool->n2size;
|
|
|
|
|
|
|
+ const int n2size = pool->swork.n2size;
|
|
|
char my_job_id[33];
|
|
char my_job_id[33];
|
|
|
int i;
|
|
int i;
|
|
|
struct stratumsrv_job *ssj;
|
|
struct stratumsrv_job *ssj;
|
|
|
- ssize_t n2pad = n2size - _ssm_client_octets - _ssm_client_xnonce2sz;
|
|
|
|
|
|
|
+ ssize_t n2pad = work2d_pad_xnonce_size(swork);
|
|
|
if (n2pad < 0)
|
|
if (n2pad < 0)
|
|
|
return false;
|
|
return false;
|
|
|
size_t coinb1in_lenx = swork->nonce2_offset * 2;
|
|
size_t coinb1in_lenx = swork->nonce2_offset * 2;
|
|
@@ -124,7 +96,7 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
|
uint32_t ntime_n;
|
|
uint32_t ntime_n;
|
|
|
bin2hex(prevhash, &swork->header1[4], 32);
|
|
bin2hex(prevhash, &swork->header1[4], 32);
|
|
|
bin2hex(coinb1, bytes_buf(&swork->coinbase), swork->nonce2_offset);
|
|
bin2hex(coinb1, bytes_buf(&swork->coinbase), swork->nonce2_offset);
|
|
|
- memset(&coinb1[coinb1in_lenx], 'B', n2padx);
|
|
|
|
|
|
|
+ work2d_pad_xnonce(&coinb1[coinb1in_lenx], swork, true);
|
|
|
coinb1[coinb1_lenx] = '\0';
|
|
coinb1[coinb1_lenx] = '\0';
|
|
|
bin2hex(coinb2, &bytes_buf(&swork->coinbase)[swork->nonce2_offset + n2size], coinb2_len);
|
|
bin2hex(coinb2, &bytes_buf(&swork->coinbase)[swork->nonce2_offset + n2size], coinb2_len);
|
|
|
p += sprintf(p, "{\"params\":[\"%s\",\"%s\",\"%s\",\"%s\",[", my_job_id, prevhash, coinb1, coinb2);
|
|
p += sprintf(p, "{\"params\":[\"%s\",\"%s\",\"%s\",\"%s\",[", my_job_id, prevhash, coinb1, coinb2);
|
|
@@ -146,11 +118,6 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
|
ssj = malloc(sizeof(*ssj));
|
|
ssj = malloc(sizeof(*ssj));
|
|
|
*ssj = (struct stratumsrv_job){
|
|
*ssj = (struct stratumsrv_job){
|
|
|
.my_job_id = strdup(my_job_id),
|
|
.my_job_id = strdup(my_job_id),
|
|
|
-
|
|
|
|
|
- .pool = pool,
|
|
|
|
|
- .work_restart_id = pool->work_restart_id,
|
|
|
|
|
- .n2size = n2size,
|
|
|
|
|
- .nonce1 = maybe_strdup(pool->nonce1),
|
|
|
|
|
};
|
|
};
|
|
|
timer_set_now(&ssj->tv_prepared);
|
|
timer_set_now(&ssj->tv_prepared);
|
|
|
stratum_work_cpy(&ssj->swork, swork);
|
|
stratum_work_cpy(&ssj->swork, swork);
|
|
@@ -162,7 +129,7 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
|
|
|
|
|
|
|
|
if (likely(_ssm_cur_job_work.pool))
|
|
if (likely(_ssm_cur_job_work.pool))
|
|
|
clean_work(&_ssm_cur_job_work);
|
|
clean_work(&_ssm_cur_job_work);
|
|
|
- _ssm_gen_dummy_work(&_ssm_cur_job_work, ssj, NULL, 0);
|
|
|
|
|
|
|
+ _ssm_gen_dummy_work(&_ssm_cur_job_work, &ssj->swork, &ssj->tv_prepared, NULL, 0);
|
|
|
|
|
|
|
|
_ssm_notify_sz = p - buf;
|
|
_ssm_notify_sz = p - buf;
|
|
|
assert(_ssm_notify_sz <= bufsz);
|
|
assert(_ssm_notify_sz <= bufsz);
|
|
@@ -184,7 +151,6 @@ void _ssj_free(struct stratumsrv_job * const ssj)
|
|
|
{
|
|
{
|
|
|
free(ssj->my_job_id);
|
|
free(ssj->my_job_id);
|
|
|
stratum_work_clean(&ssj->swork);
|
|
stratum_work_clean(&ssj->swork);
|
|
|
- free(ssj->nonce1);
|
|
|
|
|
free(ssj);
|
|
free(ssj);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -392,7 +358,6 @@ static
|
|
|
void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const char *idstr, struct stratumsrv_conn * const conn)
|
|
void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const char *idstr, struct stratumsrv_conn * const conn)
|
|
|
{
|
|
{
|
|
|
uint32_t * const xnonce1_p = &conn->xnonce1_le;
|
|
uint32_t * const xnonce1_p = &conn->xnonce1_le;
|
|
|
- struct work _work, *work;
|
|
|
|
|
struct stratumsrv_job *ssj;
|
|
struct stratumsrv_job *ssj;
|
|
|
struct proxy_client *client = stratumsrv_find_or_create_client(__json_array_string(params, 0));
|
|
struct proxy_client *client = stratumsrv_find_or_create_client(__json_array_string(params, 0));
|
|
|
struct cgpu_info *cgpu;
|
|
struct cgpu_info *cgpu;
|
|
@@ -401,7 +366,10 @@ void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const cha
|
|
|
const char * const extranonce2 = __json_array_string(params, 2);
|
|
const char * const extranonce2 = __json_array_string(params, 2);
|
|
|
const char * const ntime = __json_array_string(params, 3);
|
|
const char * const ntime = __json_array_string(params, 3);
|
|
|
const char * const nonce = __json_array_string(params, 4);
|
|
const char * const nonce = __json_array_string(params, 4);
|
|
|
- uint32_t nonce_n;
|
|
|
|
|
|
|
+ uint8_t xnonce2[work2d_xnonce2sz];
|
|
|
|
|
+ uint32_t ntime_n, nonce_n;
|
|
|
|
|
+ const float nonce_diff = 1;
|
|
|
|
|
+ bool is_stale;
|
|
|
|
|
|
|
|
if (unlikely(!client))
|
|
if (unlikely(!client))
|
|
|
return_stratumsrv_failure(20, "Failed creating new cgpu");
|
|
return_stratumsrv_failure(20, "Failed creating new cgpu");
|
|
@@ -422,24 +390,21 @@ void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const cha
|
|
|
if (!ssj)
|
|
if (!ssj)
|
|
|
return_stratumsrv_failure(21, "Job not found");
|
|
return_stratumsrv_failure(21, "Job not found");
|
|
|
|
|
|
|
|
- // Generate dummy work
|
|
|
|
|
- work = &_work;
|
|
|
|
|
- _ssm_gen_dummy_work(work, ssj, extranonce2, *xnonce1_p);
|
|
|
|
|
|
|
+ hex2bin(xnonce2, extranonce2, work2d_xnonce2sz);
|
|
|
|
|
|
|
|
// Submit nonce
|
|
// Submit nonce
|
|
|
- hex2bin(&work->data[68], ntime, 4);
|
|
|
|
|
|
|
+ hex2bin((void*)&ntime_n, ntime, 4);
|
|
|
|
|
+ ntime_n = be32toh(ntime_n);
|
|
|
hex2bin((void*)&nonce_n, nonce, 4);
|
|
hex2bin((void*)&nonce_n, nonce, 4);
|
|
|
nonce_n = le32toh(nonce_n);
|
|
nonce_n = le32toh(nonce_n);
|
|
|
- if (!submit_nonce(thr, work, nonce_n))
|
|
|
|
|
|
|
+ if (!work2d_submit_nonce(thr, &ssj->swork, &ssj->tv_prepared, xnonce2, *xnonce1_p, nonce_n, ntime_n, &is_stale, nonce_diff))
|
|
|
_stratumsrv_failure(bev, idstr, 23, "H-not-zero");
|
|
_stratumsrv_failure(bev, idstr, 23, "H-not-zero");
|
|
|
else
|
|
else
|
|
|
- if (stale_work(work, true))
|
|
|
|
|
|
|
+ if (is_stale)
|
|
|
_stratumsrv_failure(bev, idstr, 21, "stale");
|
|
_stratumsrv_failure(bev, idstr, 21, "stale");
|
|
|
else
|
|
else
|
|
|
_stratumsrv_success(bev, idstr);
|
|
_stratumsrv_success(bev, idstr);
|
|
|
|
|
|
|
|
- clean_work(work);
|
|
|
|
|
-
|
|
|
|
|
if (!conn->hashes_done_ext)
|
|
if (!conn->hashes_done_ext)
|
|
|
{
|
|
{
|
|
|
struct timeval tv_now, tv_delta;
|
|
struct timeval tv_now, tv_delta;
|