mirror of
https://git.wownero.com/wownero/wownero-puddle.git
synced 2024-08-15 01:03:20 +00:00
use bstack for jobs
This commit is contained in:
parent
bb011fa9cc
commit
4bc1589781
3 changed files with 57 additions and 70 deletions
|
@ -113,6 +113,13 @@ bstack_drop(bstack_t *q)
|
||||||
q->rf(pb);
|
q->rf(pb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
bstack_top(bstack_t *q)
|
||||||
|
{
|
||||||
|
bstack_reset(q);
|
||||||
|
return bstack_peek(q);
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
bstack_peek(bstack_t *q)
|
bstack_peek(bstack_t *q)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,7 @@ void bstack_new(bstack_t **out, size_t count, size_t size, recycle_fun recycle);
|
||||||
void bstack_free(bstack_t *q);
|
void bstack_free(bstack_t *q);
|
||||||
void * bstack_push(bstack_t *q, void *item);
|
void * bstack_push(bstack_t *q, void *item);
|
||||||
void bstack_drop(bstack_t *q);
|
void bstack_drop(bstack_t *q);
|
||||||
|
void * bstack_top(bstack_t *q);
|
||||||
void * bstack_peek(bstack_t *q);
|
void * bstack_peek(bstack_t *q);
|
||||||
size_t bstack_count(bstack_t *q);
|
size_t bstack_count(bstack_t *q);
|
||||||
void * bstack_next(bstack_t *q);
|
void * bstack_next(bstack_t *q);
|
||||||
|
|
119
src/pool.c
119
src/pool.c
|
@ -199,7 +199,7 @@ typedef struct client_t
|
||||||
char worker_id[64];
|
char worker_id[64];
|
||||||
char client_id[32];
|
char client_id[32];
|
||||||
char agent[256];
|
char agent[256];
|
||||||
job_t active_jobs[CLIENT_JOBS_MAX];
|
bstack_t *active_jobs;
|
||||||
uint64_t hashes;
|
uint64_t hashes;
|
||||||
time_t connected_since;
|
time_t connected_since;
|
||||||
bool is_xnp;
|
bool is_xnp;
|
||||||
|
@ -937,6 +937,35 @@ update_pool_hr(void)
|
||||||
pool_stats.pool_hashrate = hr;
|
pool_stats.pool_hashrate = hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
job_recycle(void *item)
|
||||||
|
{
|
||||||
|
job_t *job = (job_t*) item;
|
||||||
|
log_trace("Recycle job with extra_nonce: %u", job->extra_nonce);
|
||||||
|
if (job->blob)
|
||||||
|
{
|
||||||
|
free(job->blob);
|
||||||
|
job->blob = NULL;
|
||||||
|
}
|
||||||
|
if (job->submissions)
|
||||||
|
{
|
||||||
|
free(job->submissions);
|
||||||
|
job->submissions = NULL;
|
||||||
|
}
|
||||||
|
if (job->miner_template)
|
||||||
|
{
|
||||||
|
block_template_t *bt = job->miner_template;
|
||||||
|
if (bt->blocktemplate_blob)
|
||||||
|
{
|
||||||
|
free(bt->blocktemplate_blob);
|
||||||
|
bt->blocktemplate_blob = NULL;
|
||||||
|
}
|
||||||
|
free(job->miner_template);
|
||||||
|
job->miner_template = NULL;
|
||||||
|
}
|
||||||
|
memset(job, 0, sizeof(job_t));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
template_recycle(void *item)
|
template_recycle(void *item)
|
||||||
{
|
{
|
||||||
|
@ -1014,7 +1043,7 @@ stratum_get_proxy_job_body(char *body, const client_t *client,
|
||||||
{
|
{
|
||||||
int json_id = client->json_id;
|
int json_id = client->json_id;
|
||||||
const char *client_id = client->client_id;
|
const char *client_id = client->client_id;
|
||||||
const job_t *job = &client->active_jobs[0];
|
const job_t *job = bstack_top(client->active_jobs);
|
||||||
char job_id[33] = {0};
|
char job_id[33] = {0};
|
||||||
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
||||||
uint64_t target = job->target;
|
uint64_t target = job->target;
|
||||||
|
@ -1065,7 +1094,7 @@ stratum_get_job_body_ss(char *body, const client_t *client, bool response)
|
||||||
/* job_id, target, pool_wallet, extra_nonce */
|
/* job_id, target, pool_wallet, extra_nonce */
|
||||||
int json_id = client->json_id;
|
int json_id = client->json_id;
|
||||||
const char *client_id = client->client_id;
|
const char *client_id = client->client_id;
|
||||||
const job_t *job = &client->active_jobs[0];
|
const job_t *job = bstack_top(client->active_jobs);
|
||||||
char job_id[33] = {0};
|
char job_id[33] = {0};
|
||||||
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
||||||
uint64_t target = job->target;
|
uint64_t target = job->target;
|
||||||
|
@ -1115,7 +1144,7 @@ stratum_get_job_body(char *body, const client_t *client, bool response)
|
||||||
{
|
{
|
||||||
int json_id = client->json_id;
|
int json_id = client->json_id;
|
||||||
const char *client_id = client->client_id;
|
const char *client_id = client->client_id;
|
||||||
const job_t *job = &client->active_jobs[0];
|
const job_t *job = bstack_top(client->active_jobs);
|
||||||
char job_id[33] = {0};
|
char job_id[33] = {0};
|
||||||
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
bin_to_hex((const unsigned char*)job->id, sizeof(uuid_t), job_id, 32);
|
||||||
const char *blob = job->blob;
|
const char *blob = job->blob;
|
||||||
|
@ -1180,85 +1209,32 @@ send_validation_error(const client_t *client, const char *message)
|
||||||
static void
|
static void
|
||||||
client_clear_jobs(client_t *client)
|
client_clear_jobs(client_t *client)
|
||||||
{
|
{
|
||||||
for (size_t i=0; i<CLIENT_JOBS_MAX; i++)
|
if (!client->active_jobs)
|
||||||
{
|
return;
|
||||||
job_t *job = &client->active_jobs[i];
|
bstack_free(client->active_jobs);
|
||||||
if (job->blob)
|
client->active_jobs = NULL;
|
||||||
{
|
|
||||||
free(job->blob);
|
|
||||||
job->blob = NULL;
|
|
||||||
}
|
|
||||||
if (job->submissions)
|
|
||||||
{
|
|
||||||
free(job->submissions);
|
|
||||||
job->submissions = NULL;
|
|
||||||
job->submissions_count = 0;
|
|
||||||
}
|
|
||||||
if (job->miner_template)
|
|
||||||
{
|
|
||||||
block_template_t *bt = job->miner_template;
|
|
||||||
if (bt->blocktemplate_blob)
|
|
||||||
{
|
|
||||||
free(bt->blocktemplate_blob);
|
|
||||||
bt->blocktemplate_blob = NULL;
|
|
||||||
}
|
|
||||||
free(job->miner_template);
|
|
||||||
job->miner_template = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static job_t *
|
static job_t *
|
||||||
client_find_job(client_t *client, const char *job_id)
|
client_find_job(client_t *client, const char *job_id)
|
||||||
{
|
{
|
||||||
uuid_t jid;
|
uuid_t jid;
|
||||||
|
job_t *job = NULL;
|
||||||
hex_to_bin(job_id, strlen(job_id), (unsigned char*)&jid, sizeof(uuid_t));
|
hex_to_bin(job_id, strlen(job_id), (unsigned char*)&jid, sizeof(uuid_t));
|
||||||
for (size_t i=0; i<CLIENT_JOBS_MAX; i++)
|
bstack_reset(client->active_jobs);
|
||||||
|
while ((job = bstack_next(client->active_jobs)))
|
||||||
{
|
{
|
||||||
job_t *job = &client->active_jobs[i];
|
|
||||||
if (memcmp(job->id, jid, sizeof(uuid_t)) == 0)
|
if (memcmp(job->id, jid, sizeof(uuid_t)) == 0)
|
||||||
return job;
|
break;
|
||||||
}
|
}
|
||||||
return NULL;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
miner_send_job(client_t *client, bool response)
|
miner_send_job(client_t *client, bool response)
|
||||||
{
|
{
|
||||||
/* First cycle jobs */
|
job_t *job = bstack_push(client->active_jobs, NULL);
|
||||||
job_t *last = &client->active_jobs[CLIENT_JOBS_MAX-1];
|
block_template_t *bt = bstack_top(bst);
|
||||||
if (last->blob)
|
|
||||||
{
|
|
||||||
free(last->blob);
|
|
||||||
last->blob = NULL;
|
|
||||||
}
|
|
||||||
if (last->submissions)
|
|
||||||
{
|
|
||||||
free(last->submissions);
|
|
||||||
last->submissions = NULL;
|
|
||||||
last->submissions_count = 0;
|
|
||||||
}
|
|
||||||
if (last->miner_template)
|
|
||||||
{
|
|
||||||
block_template_t *bt = last->miner_template;
|
|
||||||
if (bt->blocktemplate_blob)
|
|
||||||
{
|
|
||||||
free(bt->blocktemplate_blob);
|
|
||||||
bt->blocktemplate_blob = NULL;
|
|
||||||
}
|
|
||||||
free(last->miner_template);
|
|
||||||
last->miner_template = NULL;
|
|
||||||
}
|
|
||||||
for (size_t i=CLIENT_JOBS_MAX-1; i>0; i--)
|
|
||||||
{
|
|
||||||
job_t *current = &client->active_jobs[i];
|
|
||||||
job_t *prev = &client->active_jobs[i-1];
|
|
||||||
memcpy(current, prev, sizeof(job_t));
|
|
||||||
}
|
|
||||||
job_t *job = &client->active_jobs[0];
|
|
||||||
memset(job, 0, sizeof(job_t));
|
|
||||||
|
|
||||||
block_template_t *bt = bstack_peek(bst);
|
|
||||||
job->block_template = bt;
|
job->block_template = bt;
|
||||||
|
|
||||||
if (client->mode == MODE_SELF_SELECT)
|
if (client->mode == MODE_SELF_SELECT)
|
||||||
|
@ -1375,6 +1351,8 @@ pool_clients_free(void)
|
||||||
client_t *c = pool_clients.clients;
|
client_t *c = pool_clients.clients;
|
||||||
for (size_t i = 0; i < pool_clients.count; i++, c++)
|
for (size_t i = 0; i < pool_clients.count; i++, c++)
|
||||||
{
|
{
|
||||||
|
if (!c->active_jobs)
|
||||||
|
continue;
|
||||||
client_clear_jobs(c);
|
client_clear_jobs(c);
|
||||||
}
|
}
|
||||||
free(pool_clients.clients);
|
free(pool_clients.clients);
|
||||||
|
@ -1834,7 +1812,7 @@ rpc_on_last_block_header(const char* data, rpc_callback_t *callback)
|
||||||
JSON_GET_OR_WARN(height, block_header, json_type_int);
|
JSON_GET_OR_WARN(height, block_header, json_type_int);
|
||||||
uint64_t bh = json_object_get_int64(height);
|
uint64_t bh = json_object_get_int64(height);
|
||||||
bool need_new_template = false;
|
bool need_new_template = false;
|
||||||
block_t *front = bstack_peek(bsh);
|
block_t *front = bstack_top(bsh);
|
||||||
if (front && bh > front->height)
|
if (front && bh > front->height)
|
||||||
{
|
{
|
||||||
need_new_template = true;
|
need_new_template = true;
|
||||||
|
@ -1850,7 +1828,7 @@ rpc_on_last_block_header(const char* data, rpc_callback_t *callback)
|
||||||
need_new_template = true;
|
need_new_template = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
front = bstack_peek(bsh);
|
front = bstack_top(bsh);
|
||||||
pool_stats.network_difficulty = front->difficulty;
|
pool_stats.network_difficulty = front->difficulty;
|
||||||
pool_stats.network_hashrate = front->difficulty / BLOCK_TIME;
|
pool_stats.network_hashrate = front->difficulty / BLOCK_TIME;
|
||||||
pool_stats.network_height = front->height;
|
pool_stats.network_height = front->height;
|
||||||
|
@ -2700,6 +2678,7 @@ client_add(int fd, struct bufferevent *bev, bool downstream)
|
||||||
c->bev = bev;
|
c->bev = bev;
|
||||||
c->connected_since = time(NULL);
|
c->connected_since = time(NULL);
|
||||||
c->downstream = downstream;
|
c->downstream = downstream;
|
||||||
|
bstack_new(&c->active_jobs, CLIENT_JOBS_MAX, sizeof(job_t), job_recycle);
|
||||||
if (!downstream)
|
if (!downstream)
|
||||||
pool_stats.connected_miners++;
|
pool_stats.connected_miners++;
|
||||||
if (upstream_event)
|
if (upstream_event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue