mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 09:27:25 +00:00
Merge pull request #26 from LBRYFoundation/Coolguy3289-stratum-debug
Update stratum // Adds debug code for console with regards to job submissions and updates blake2s headers for CPP 11+
This commit is contained in:
commit
a82d2b9372
4 changed files with 675 additions and 670 deletions
467
stratum/job.cpp
467
stratum/job.cpp
|
@ -5,224 +5,224 @@
|
||||||
//debuglog(" returning %x, %s, %s\n", job->id, client->sock->ip, #condition); \
|
//debuglog(" returning %x, %s, %s\n", job->id, client->sock->ip, #condition); \
|
||||||
|
|
||||||
#define RETURN_ON_CONDITION(condition, ret) \
|
#define RETURN_ON_CONDITION(condition, ret) \
|
||||||
if(condition) \
|
if(condition) \
|
||||||
{ \
|
{ \
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool job_assign_client(YAAMP_JOB *job, YAAMP_CLIENT *client, double maxhash)
|
static bool job_assign_client(YAAMP_JOB *job, YAAMP_CLIENT *client, double maxhash)
|
||||||
{
|
{
|
||||||
RETURN_ON_CONDITION(client->deleted, true);
|
RETURN_ON_CONDITION(client->deleted, true);
|
||||||
RETURN_ON_CONDITION(client->jobid_next, true);
|
RETURN_ON_CONDITION(client->jobid_next, true);
|
||||||
RETURN_ON_CONDITION(client->jobid_locked && client->jobid_locked != job->id, true);
|
RETURN_ON_CONDITION(client->jobid_locked && client->jobid_locked != job->id, true);
|
||||||
RETURN_ON_CONDITION(client_find_job_history(client, job->id), true);
|
RETURN_ON_CONDITION(client_find_job_history(client, job->id), true);
|
||||||
RETURN_ON_CONDITION(maxhash > 0 && job->speed + client->speed > maxhash, true);
|
RETURN_ON_CONDITION(maxhash > 0 && job->speed + client->speed > maxhash, true);
|
||||||
|
|
||||||
if(!g_autoexchange && maxhash >= 0. && client->coinid != job->coind->id) {
|
if(!g_autoexchange && maxhash >= 0. && client->coinid != job->coind->id) {
|
||||||
//debuglog("prevent client %c on %s, not the right coin\n",
|
//debuglog("prevent client %c on %s, not the right coin\n",
|
||||||
// client->username[0], job->coind->symbol);
|
// client->username[0], job->coind->symbol);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(job->remote)
|
if(job->remote)
|
||||||
{
|
{
|
||||||
YAAMP_REMOTE *remote = job->remote;
|
YAAMP_REMOTE *remote = job->remote;
|
||||||
|
|
||||||
if(g_stratum_reconnect)
|
if(g_stratum_reconnect)
|
||||||
{RETURN_ON_CONDITION(!client->extranonce_subscribe && !client->reconnectable, true);}
|
{RETURN_ON_CONDITION(!client->extranonce_subscribe && !client->reconnectable, true);}
|
||||||
else
|
else
|
||||||
{RETURN_ON_CONDITION(!client->extranonce_subscribe, true);}
|
{RETURN_ON_CONDITION(!client->extranonce_subscribe, true);}
|
||||||
|
|
||||||
RETURN_ON_CONDITION(client->reconnecting, true);
|
RETURN_ON_CONDITION(client->reconnecting, true);
|
||||||
RETURN_ON_CONDITION(job->count >= YAAMP_JOB_MAXSUBIDS, false);
|
RETURN_ON_CONDITION(job->count >= YAAMP_JOB_MAXSUBIDS, false);
|
||||||
// RETURN_ON_CONDITION(client->difficulty_actual > remote->difficulty_actual, false);
|
// RETURN_ON_CONDITION(client->difficulty_actual > remote->difficulty_actual, false);
|
||||||
|
|
||||||
double difficulty_remote = client->difficulty_remote;
|
double difficulty_remote = client->difficulty_remote;
|
||||||
if(remote->difficulty_actual < client->difficulty_actual)
|
if(remote->difficulty_actual < client->difficulty_actual)
|
||||||
{
|
{
|
||||||
RETURN_ON_CONDITION(client->difficulty_fixed, true);
|
RETURN_ON_CONDITION(client->difficulty_fixed, true);
|
||||||
RETURN_ON_CONDITION(remote->difficulty_actual*4 < client->difficulty_actual, true);
|
RETURN_ON_CONDITION(remote->difficulty_actual*4 < client->difficulty_actual, true);
|
||||||
|
|
||||||
difficulty_remote = remote->difficulty_actual;
|
difficulty_remote = remote->difficulty_actual;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(remote->difficulty_actual > client->difficulty_actual)
|
else if(remote->difficulty_actual > client->difficulty_actual)
|
||||||
difficulty_remote = 0;
|
difficulty_remote = 0;
|
||||||
|
|
||||||
if(remote->nonce2size == 2)
|
if(remote->nonce2size == 2)
|
||||||
{
|
{
|
||||||
RETURN_ON_CONDITION(job->count > 0, false);
|
RETURN_ON_CONDITION(job->count > 0, false);
|
||||||
|
|
||||||
strcpy(client->extranonce1, remote->nonce1);
|
strcpy(client->extranonce1, remote->nonce1);
|
||||||
client->extranonce2size = 2;
|
client->extranonce2size = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(job->id != client->jobid_sent)
|
else if(job->id != client->jobid_sent)
|
||||||
{
|
{
|
||||||
if(!job->remote_subids[client->extranonce1_id])
|
if(!job->remote_subids[client->extranonce1_id])
|
||||||
job->remote_subids[client->extranonce1_id] = true;
|
job->remote_subids[client->extranonce1_id] = true;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
for(; i<YAAMP_JOB_MAXSUBIDS; i++) if(!job->remote_subids[i])
|
for(; i<YAAMP_JOB_MAXSUBIDS; i++) if(!job->remote_subids[i])
|
||||||
{
|
{
|
||||||
job->remote_subids[i] = true;
|
job->remote_subids[i] = true;
|
||||||
client->extranonce1_id = i;
|
client->extranonce1_id = i;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_ON_CONDITION(i == YAAMP_JOB_MAXSUBIDS, false);
|
RETURN_ON_CONDITION(i == YAAMP_JOB_MAXSUBIDS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(client->extranonce1, "%s%02x", remote->nonce1, client->extranonce1_id);
|
sprintf(client->extranonce1, "%s%02x", remote->nonce1, client->extranonce1_id);
|
||||||
client->extranonce2size = remote->nonce2size-1;
|
client->extranonce2size = remote->nonce2size-1;
|
||||||
client->difficulty_remote = difficulty_remote;
|
client->difficulty_remote = difficulty_remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->jobid_locked = job->id;
|
client->jobid_locked = job->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(client->extranonce1, client->extranonce1_default);
|
strcpy(client->extranonce1, client->extranonce1_default);
|
||||||
client->extranonce2size = client->extranonce2size_default;
|
client->extranonce2size = client->extranonce2size_default;
|
||||||
|
|
||||||
// decred uses an extradata field in block header, 2 first uint32 are set by the miner
|
// decred uses an extradata field in block header, 2 first uint32 are set by the miner
|
||||||
if (g_current_algo->name && !strcmp(g_current_algo->name,"decred")) {
|
if (g_current_algo->name && !strcmp(g_current_algo->name,"decred")) {
|
||||||
memset(client->extranonce1, '0', sizeof(client->extranonce1));
|
memset(client->extranonce1, '0', sizeof(client->extranonce1));
|
||||||
memcpy(&client->extranonce1[16], client->extranonce1_default, 8);
|
memcpy(&client->extranonce1[16], client->extranonce1_default, 8);
|
||||||
client->extranonce1[24] = '\0';
|
client->extranonce1[24] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
client->difficulty_remote = 0;
|
client->difficulty_remote = 0;
|
||||||
client->jobid_locked = 0;
|
client->jobid_locked = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->jobid_next = job->id;
|
client->jobid_next = job->id;
|
||||||
|
|
||||||
job->speed += client->speed;
|
job->speed += client->speed;
|
||||||
job->count++;
|
job->count++;
|
||||||
|
|
||||||
// debuglog(" assign %x, %f, %d, %s\n", job->id, client->speed, client->reconnecting, client->sock->ip);
|
// debuglog(" assign %x, %f, %d, %s\n", job->id, client->speed, client->reconnecting, client->sock->ip);
|
||||||
if(strcmp(client->extranonce1, client->extranonce1_last) || client->extranonce2size != client->extranonce2size_last)
|
if(strcmp(client->extranonce1, client->extranonce1_last) || client->extranonce2size != client->extranonce2size_last)
|
||||||
{
|
{
|
||||||
// debuglog("new nonce %x %s %s\n", job->id, client->extranonce1_last, client->extranonce1);
|
// debuglog("new nonce %x %s %s\n", job->id, client->extranonce1_last, client->extranonce1);
|
||||||
if(!client->extranonce_subscribe)
|
if(!client->extranonce_subscribe)
|
||||||
{
|
{
|
||||||
strcpy(client->extranonce1_reconnect, client->extranonce1);
|
strcpy(client->extranonce1_reconnect, client->extranonce1);
|
||||||
client->extranonce2size_reconnect = client->extranonce2size;
|
client->extranonce2size_reconnect = client->extranonce2size;
|
||||||
|
|
||||||
strcpy(client->extranonce1, client->extranonce1_default);
|
strcpy(client->extranonce1, client->extranonce1_default);
|
||||||
client->extranonce2size = client->extranonce2size_default;
|
client->extranonce2size = client->extranonce2size_default;
|
||||||
|
|
||||||
client->reconnecting = true;
|
client->reconnecting = true;
|
||||||
client->lock_count++;
|
client->lock_count++;
|
||||||
client->unlock = true;
|
client->unlock = true;
|
||||||
client->jobid_sent = client->jobid_next;
|
client->jobid_sent = client->jobid_next;
|
||||||
|
|
||||||
socket_send(client->sock, "{\"id\":null,\"method\":\"client.reconnect\",\"params\":[\"%s\",%d,0]}\n", g_tcp_server, g_tcp_port);
|
socket_send(client->sock, "{\"id\":null,\"method\":\"client.reconnect\",\"params\":[\"%s\",%d,0]}\n", g_tcp_server, g_tcp_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(client->extranonce1_last, client->extranonce1);
|
strcpy(client->extranonce1_last, client->extranonce1);
|
||||||
client->extranonce2size_last = client->extranonce2size;
|
client->extranonce2size_last = client->extranonce2size;
|
||||||
|
|
||||||
socket_send(client->sock, "{\"id\":null,\"method\":\"mining.set_extranonce\",\"params\":[\"%s\",%d]}\n",
|
socket_send(client->sock, "{\"id\":null,\"method\":\"mining.set_extranonce\",\"params\":[\"%s\",%d]}\n",
|
||||||
client->extranonce1, client->extranonce2size);
|
client->extranonce1, client->extranonce2size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_assign_clients(YAAMP_JOB *job, double maxhash)
|
void job_assign_clients(YAAMP_JOB *job, double maxhash)
|
||||||
{
|
{
|
||||||
if (!job) return;
|
if (!job) return;
|
||||||
|
|
||||||
job->speed = 0;
|
job->speed = 0;
|
||||||
job->count = 0;
|
job->count = 0;
|
||||||
|
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
|
|
||||||
// pass0 locked
|
// pass0 locked
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->jobid_locked && client->jobid_locked != job->id) continue;
|
if(client->jobid_locked && client->jobid_locked != job->id) continue;
|
||||||
|
|
||||||
bool b = job_assign_client(job, client, maxhash);
|
bool b = job_assign_client(job, client, maxhash);
|
||||||
if(!b) break;
|
if(!b) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass1 sent
|
// pass1 sent
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->jobid_sent != job->id) continue;
|
if(client->jobid_sent != job->id) continue;
|
||||||
|
|
||||||
bool b = job_assign_client(job, client, maxhash);
|
bool b = job_assign_client(job, client, maxhash);
|
||||||
if(!b) break;
|
if(!b) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass2 extranonce_subscribe
|
// pass2 extranonce_subscribe
|
||||||
if(job->remote) for(CLI li = g_list_client.first; li; li = li->next)
|
if(job->remote) for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(!client->extranonce_subscribe) continue;
|
if(!client->extranonce_subscribe) continue;
|
||||||
|
|
||||||
bool b = job_assign_client(job, client, maxhash);
|
bool b = job_assign_client(job, client, maxhash);
|
||||||
if(!b) break;
|
if(!b) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass3 the rest
|
// pass3 the rest
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
|
|
||||||
bool b = job_assign_client(job, client, maxhash);
|
bool b = job_assign_client(job, client, maxhash);
|
||||||
if(!b) break;
|
if(!b) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_assign_clients_left(double factor)
|
void job_assign_clients_left(double factor)
|
||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
for(CLI li = g_list_coind.first; li; li = li->next)
|
for(CLI li = g_list_coind.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
if(!job_has_free_client()) return;
|
if(!job_has_free_client()) return;
|
||||||
|
|
||||||
YAAMP_COIND *coind = (YAAMP_COIND *)li->data;
|
YAAMP_COIND *coind = (YAAMP_COIND *)li->data;
|
||||||
if(!coind_can_mine(coind)) continue;
|
if(!coind_can_mine(coind)) continue;
|
||||||
if(!coind->job) continue;
|
if(!coind->job) continue;
|
||||||
|
|
||||||
double nethash = coind_nethash(coind);
|
double nethash = coind_nethash(coind);
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
|
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if (!g_autoexchange) {
|
if (!g_autoexchange) {
|
||||||
if (client->coinid == coind->id)
|
if (client->coinid == coind->id)
|
||||||
factor = 100.;
|
factor = 100.;
|
||||||
else
|
else
|
||||||
factor = 0.;
|
factor = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//debuglog("%s %s factor %f nethash %.3f\n", coind->symbol, client->username, factor, nethash);
|
//debuglog("%s %s factor %f nethash %.3f\n", coind->symbol, client->username, factor, nethash);
|
||||||
|
|
||||||
if (factor > 0.) {
|
if (factor > 0.) {
|
||||||
b = job_assign_client(coind->job, client, nethash*factor);
|
b = job_assign_client(coind->job, client, nethash*factor);
|
||||||
if(!b) break;
|
if(!b) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -232,112 +232,114 @@ pthread_cond_t g_job_cond;
|
||||||
|
|
||||||
void *job_thread(void *p)
|
void *job_thread(void *p)
|
||||||
{
|
{
|
||||||
CommonLock(&g_job_mutex);
|
CommonLock(&g_job_mutex);
|
||||||
while(!g_exiting)
|
while(!g_exiting)
|
||||||
{
|
{
|
||||||
job_update();
|
job_update();
|
||||||
pthread_cond_wait(&g_job_cond, &g_job_mutex);
|
pthread_cond_wait(&g_job_cond, &g_job_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_init()
|
void job_init()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&g_job_mutex, 0);
|
pthread_mutex_init(&g_job_mutex, 0);
|
||||||
pthread_cond_init(&g_job_cond, 0);
|
pthread_cond_init(&g_job_cond, 0);
|
||||||
|
|
||||||
pthread_t thread3;
|
pthread_t thread3;
|
||||||
pthread_create(&thread3, NULL, job_thread, NULL);
|
pthread_create(&thread3, NULL, job_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_signal()
|
void job_signal()
|
||||||
{
|
{
|
||||||
CommonLock(&g_job_mutex);
|
CommonLock(&g_job_mutex);
|
||||||
pthread_cond_signal(&g_job_cond);
|
pthread_cond_signal(&g_job_cond);
|
||||||
CommonUnlock(&g_job_mutex);
|
CommonUnlock(&g_job_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_update()
|
void job_update()
|
||||||
{
|
{
|
||||||
// debuglog("job_update()\n");
|
// debuglog("job_update()\n");
|
||||||
job_reset_clients();
|
job_reset_clients();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
g_list_job.Enter();
|
g_list_job.Enter();
|
||||||
job_sort();
|
job_sort();
|
||||||
|
|
||||||
for(CLI li = g_list_job.first; li; li = li->next)
|
for(CLI li = g_list_job.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_JOB *job = (YAAMP_JOB *)li->data;
|
YAAMP_JOB *job = (YAAMP_JOB *)li->data;
|
||||||
if(!job_can_mine(job)) continue;
|
if(!job_can_mine(job)) continue;
|
||||||
|
|
||||||
job_assign_clients(job, job->maxspeed);
|
job_assign_clients(job, job->maxspeed);
|
||||||
job_unlock_clients(job);
|
job_unlock_clients(job);
|
||||||
|
|
||||||
if(!job_has_free_client()) break;
|
if(!job_has_free_client()) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
job_unlock_clients();
|
job_unlock_clients();
|
||||||
g_list_job.Leave();
|
g_list_job.Leave();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
g_list_coind.Enter();
|
g_list_coind.Enter();
|
||||||
coind_sort();
|
coind_sort();
|
||||||
|
|
||||||
job_assign_clients_left(1);
|
job_assign_clients_left(1);
|
||||||
job_assign_clients_left(1);
|
job_assign_clients_left(1);
|
||||||
job_assign_clients_left(-1);
|
job_assign_clients_left(-1);
|
||||||
|
|
||||||
g_list_coind.Leave();
|
g_list_coind.Leave();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->deleted) continue;
|
if(client->deleted) continue;
|
||||||
if(client->jobid_next) continue;
|
if(client->jobid_next) continue;
|
||||||
|
|
||||||
debuglog("clients with no job\n");
|
debuglog("clients with no job\n");
|
||||||
g_current_algo->overflow = true;
|
g_current_algo->overflow = true;
|
||||||
|
|
||||||
if(!g_list_coind.first) break;
|
if(!g_list_coind.first) break;
|
||||||
|
|
||||||
// here: todo: choose first can mine
|
// here: todo: choose first can mine
|
||||||
|
|
||||||
YAAMP_COIND *coind = (YAAMP_COIND *)g_list_coind.first->data;
|
YAAMP_COIND *coind = (YAAMP_COIND *)g_list_coind.first->data;
|
||||||
if(!coind) break;
|
if(!coind) break;
|
||||||
|
|
||||||
job_reset_clients(coind->job);
|
job_reset_clients(coind->job);
|
||||||
coind_create_job(coind, true);
|
coind_create_job(coind, true);
|
||||||
job_assign_clients(coind->job, -1);
|
job_assign_clients(coind->job, -1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// usleep(100*YAAMP_MS);
|
// usleep(100*YAAMP_MS);
|
||||||
|
|
||||||
// int ready = 0;
|
int ready = 0;
|
||||||
// debuglog("job_update\n");
|
debuglog("job_update\n");
|
||||||
|
|
||||||
g_list_job.Enter();
|
g_list_job.Enter();
|
||||||
for(CLI li = g_list_job.first; li; li = li->next)
|
for(CLI li = g_list_job.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_JOB *job = (YAAMP_JOB *)li->data;
|
debuglog("entered job CLI for loop\n");
|
||||||
if(!job_can_mine(job)) continue;
|
YAAMP_JOB *job = (YAAMP_JOB *)li->data;
|
||||||
|
debuglog("Printing YAAMP_JOB *job value: ",job,"\n");
|
||||||
|
if(!job_can_mine(job)) continue;
|
||||||
|
debuglog("ready to broadcast job\n");
|
||||||
|
job_broadcast(job);
|
||||||
|
ready++;
|
||||||
|
}
|
||||||
|
|
||||||
job_broadcast(job);
|
debuglog("job_update %d / %d jobs\n", ready, g_list_job.count);
|
||||||
// ready++;
|
g_list_job.Leave();
|
||||||
}
|
|
||||||
|
|
||||||
// debuglog("job_update %d / %d jobs\n", ready, g_list_job.count);
|
|
||||||
g_list_job.Leave();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,4 +349,3 @@ void job_update()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,130 +3,135 @@
|
||||||
|
|
||||||
void job_sort()
|
void job_sort()
|
||||||
{
|
{
|
||||||
for(CLI li = g_list_job.first; li && li->next; li = li->next)
|
for(CLI li = g_list_job.first; li && li->next; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_JOB *job1 = (YAAMP_JOB *)li->data;
|
YAAMP_JOB *job1 = (YAAMP_JOB *)li->data;
|
||||||
YAAMP_JOB *job2 = (YAAMP_JOB *)li->next->data;
|
YAAMP_JOB *job2 = (YAAMP_JOB *)li->next->data;
|
||||||
|
|
||||||
if(job1->profit < job2->profit)
|
if(job1->profit < job2->profit)
|
||||||
{
|
{
|
||||||
g_list_job.Swap(li, li->next);
|
g_list_job.Swap(li, li->next);
|
||||||
job_sort();
|
job_sort();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool job_has_free_client()
|
bool job_has_free_client()
|
||||||
{
|
{
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->deleted) continue;
|
if(client->deleted) continue;
|
||||||
|
|
||||||
if(!client->jobid_next)
|
if(!client->jobid_next)
|
||||||
{
|
{
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_reset_clients(YAAMP_JOB *job)
|
void job_reset_clients(YAAMP_JOB *job)
|
||||||
{
|
{
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->deleted) continue;
|
if(client->deleted) continue;
|
||||||
|
|
||||||
if(!job || job->id == client->jobid_next)
|
if(!job || job->id == client->jobid_next)
|
||||||
client->jobid_next = 0;
|
client->jobid_next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_relock_clients(int jobid_old, int jobid_new)
|
void job_relock_clients(int jobid_old, int jobid_new)
|
||||||
{
|
{
|
||||||
if(!jobid_old || !jobid_new) return;
|
if(!jobid_old || !jobid_new) return;
|
||||||
|
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->jobid_locked != jobid_old) continue;
|
if(client->jobid_locked != jobid_old) continue;
|
||||||
|
|
||||||
// debuglog("relock job %x to %x\n", client->jobid_locked, jobid_new);
|
// debuglog("relock job %x to %x\n", client->jobid_locked, jobid_new);
|
||||||
client->jobid_locked = jobid_new;
|
client->jobid_locked = jobid_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_assign_locked_clients(YAAMP_JOB *job)
|
void job_assign_locked_clients(YAAMP_JOB *job)
|
||||||
{
|
{
|
||||||
if(!job) return;
|
if(!job) return;
|
||||||
|
|
||||||
job->speed = 0;
|
job->speed = 0;
|
||||||
job->count = 0;
|
job->count = 0;
|
||||||
|
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->jobid_locked != job->id) continue;
|
if(client->jobid_locked != job->id) continue;
|
||||||
|
|
||||||
// debuglog("assign job %x %x\n", client->jobid_locked, job->id);
|
// debuglog("assign job %x %x\n", client->jobid_locked, job->id);
|
||||||
|
|
||||||
client->jobid_next = job->id;
|
client->jobid_next = job->id;
|
||||||
job->remote_subids[client->extranonce1_id] = true;
|
job->remote_subids[client->extranonce1_id] = true;
|
||||||
|
|
||||||
job->speed += client->speed;
|
job->speed += client->speed;
|
||||||
job->count++;
|
job->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_unlock_clients(YAAMP_JOB *job)
|
void job_unlock_clients(YAAMP_JOB *job)
|
||||||
{
|
{
|
||||||
g_list_client.Enter();
|
g_list_client.Enter();
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
if(client->deleted) continue;
|
if(client->deleted) continue;
|
||||||
if(!client->jobid_locked) continue;
|
if(!client->jobid_locked) continue;
|
||||||
if(client->jobid_locked == client->jobid_next) continue;
|
if(client->jobid_locked == client->jobid_next) continue;
|
||||||
if(job && client->jobid_locked != job->id) continue;
|
if(job && client->jobid_locked != job->id) continue;
|
||||||
|
|
||||||
// debuglog("unlock job %x %x\n", client->jobid_locked, job->id);
|
// debuglog("unlock job %x %x\n", client->jobid_locked, job->id);
|
||||||
client->jobid_locked = 0;
|
client->jobid_locked = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool job_can_mine(YAAMP_JOB *job)
|
bool job_can_mine(YAAMP_JOB *job)
|
||||||
{
|
{
|
||||||
if(job->deleted) return false;
|
if(job->deleted) {
|
||||||
|
debuglog("Job was deleted\n");
|
||||||
if(job->remote)
|
return false;
|
||||||
return remote_can_mine(job->remote);
|
}
|
||||||
|
if(job->remote) {
|
||||||
else if(job->coind)
|
debuglog("job is remote?\n");
|
||||||
return coind_can_mine(job->coind);
|
return remote_can_mine(job->remote);
|
||||||
|
}
|
||||||
return false;
|
else if(job->coind) {
|
||||||
|
debuglog("job is coind\n");
|
||||||
|
return coind_can_mine(job->coind);
|
||||||
|
} else {
|
||||||
|
debuglog("returning false for job_can_mine\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,96 +34,96 @@
|
||||||
static inline uint32_t load32(const void *src)
|
static inline uint32_t load32(const void *src)
|
||||||
{
|
{
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
return *(uint32_t *)(src);
|
return *(uint32_t *)(src);
|
||||||
#else
|
#else
|
||||||
const uint8_t *p = (uint8_t *)src;
|
const uint8_t *p = (uint8_t *)src;
|
||||||
uint32_t w = *p++;
|
uint32_t w = *p++;
|
||||||
w |= (uint32_t)(*p++) << 8;
|
w |= (uint32_t)(*p++) << 8;
|
||||||
w |= (uint32_t)(*p++) << 16;
|
w |= (uint32_t)(*p++) << 16;
|
||||||
w |= (uint32_t)(*p++) << 24;
|
w |= (uint32_t)(*p++) << 24;
|
||||||
return w;
|
return w;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void store32(void *dst, uint32_t w)
|
static inline void store32(void *dst, uint32_t w)
|
||||||
{
|
{
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
*(uint32_t *)(dst) = w;
|
*(uint32_t *)(dst) = w;
|
||||||
#else
|
#else
|
||||||
uint8_t *p = (uint8_t *)dst;
|
uint8_t *p = (uint8_t *)dst;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w;
|
*p++ = (uint8_t)w;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t load48(const void *src)
|
static inline uint64_t load48(const void *src)
|
||||||
{
|
{
|
||||||
const uint8_t *p = (const uint8_t *)src;
|
const uint8_t *p = (const uint8_t *)src;
|
||||||
uint64_t w = *p++;
|
uint64_t w = *p++;
|
||||||
w |= (uint64_t)(*p++) << 8;
|
w |= (uint64_t)(*p++) << 8;
|
||||||
w |= (uint64_t)(*p++) << 16;
|
w |= (uint64_t)(*p++) << 16;
|
||||||
w |= (uint64_t)(*p++) << 24;
|
w |= (uint64_t)(*p++) << 24;
|
||||||
w |= (uint64_t)(*p++) << 32;
|
w |= (uint64_t)(*p++) << 32;
|
||||||
w |= (uint64_t)(*p++) << 40;
|
w |= (uint64_t)(*p++) << 40;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void store48(void *dst, uint64_t w)
|
static inline void store48(void *dst, uint64_t w)
|
||||||
{
|
{
|
||||||
uint8_t *p = (uint8_t *)dst;
|
uint8_t *p = (uint8_t *)dst;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w; w >>= 8;
|
*p++ = (uint8_t)w; w >>= 8;
|
||||||
*p++ = (uint8_t)w;
|
*p++ = (uint8_t)w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prevents compiler optimizing out memset() */
|
/* prevents compiler optimizing out memset() */
|
||||||
static inline void secure_zero_memory(void *v, size_t n)
|
static inline void secure_zero_memory(void *v, size_t n)
|
||||||
{
|
{
|
||||||
volatile uint8_t *p = ( volatile uint8_t * )v;
|
volatile uint8_t *p = ( volatile uint8_t * )v;
|
||||||
|
|
||||||
while( n-- ) *p++ = 0;
|
while( n-- ) *p++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* blake2.h */
|
/* blake2.h */
|
||||||
|
|
||||||
enum blake2s_constant
|
enum blake2s_constant
|
||||||
{
|
{
|
||||||
BLAKE2S_BLOCKBYTES = 64,
|
BLAKE2S_BLOCKBYTES = 64,
|
||||||
BLAKE2S_OUTBYTES = 32,
|
BLAKE2S_OUTBYTES = 32,
|
||||||
BLAKE2S_KEYBYTES = 32,
|
BLAKE2S_KEYBYTES = 32,
|
||||||
BLAKE2S_SALTBYTES = 8,
|
BLAKE2S_SALTBYTES = 8,
|
||||||
BLAKE2S_PERSONALBYTES = 8
|
BLAKE2S_PERSONALBYTES = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct __blake2s_param
|
typedef struct __blake2s_param
|
||||||
{
|
{
|
||||||
uint8_t digest_length; // 1
|
uint8_t digest_length; // 1
|
||||||
uint8_t key_length; // 2
|
uint8_t key_length; // 2
|
||||||
uint8_t fanout; // 3
|
uint8_t fanout; // 3
|
||||||
uint8_t depth; // 4
|
uint8_t depth; // 4
|
||||||
uint32_t leaf_length; // 8
|
uint32_t leaf_length; // 8
|
||||||
uint8_t node_offset[6];// 14
|
uint8_t node_offset[6];// 14
|
||||||
uint8_t node_depth; // 15
|
uint8_t node_depth; // 15
|
||||||
uint8_t inner_length; // 16
|
uint8_t inner_length; // 16
|
||||||
// uint8_t reserved[0];
|
// uint8_t reserved[0];
|
||||||
uint8_t salt[BLAKE2S_SALTBYTES]; // 24
|
uint8_t salt[BLAKE2S_SALTBYTES]; // 24
|
||||||
uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32
|
uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32
|
||||||
} blake2s_param;
|
} blake2s_param;
|
||||||
|
|
||||||
ALIGN( 64 ) typedef struct __blake2s_state
|
typedef struct ALIGN( 64 ) __blake2s_state
|
||||||
{
|
{
|
||||||
uint32_t h[8];
|
uint32_t h[8];
|
||||||
uint32_t t[2];
|
uint32_t t[2];
|
||||||
uint32_t f[2];
|
uint32_t f[2];
|
||||||
uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
|
uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
|
||||||
size_t buflen;
|
size_t buflen;
|
||||||
uint8_t last_node;
|
uint8_t last_node;
|
||||||
} blake2s_state;
|
} blake2s_state;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
@ -131,21 +131,21 @@ ALIGN( 64 ) typedef struct __blake2s_state
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] );
|
int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] );
|
||||||
|
|
||||||
// Streaming API
|
// Streaming API
|
||||||
int blake2s_init( blake2s_state *S, const uint8_t outlen );
|
int blake2s_init( blake2s_state *S, const uint8_t outlen );
|
||||||
int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
|
int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
|
||||||
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
|
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
|
||||||
int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
|
int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
|
||||||
int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
|
int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
|
||||||
|
|
||||||
// Simple API
|
// Simple API
|
||||||
int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
|
int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
|
||||||
|
|
||||||
// Direct Hash Mining Helpers
|
// Direct Hash Mining Helpers
|
||||||
#define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */
|
#define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */
|
||||||
#define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0)
|
#define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0)
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,407 +76,406 @@ void *monitor_thread(void *p);
|
||||||
|
|
||||||
static void scrypt_hash(const char* input, char* output, uint32_t len)
|
static void scrypt_hash(const char* input, char* output, uint32_t len)
|
||||||
{
|
{
|
||||||
scrypt_1024_1_1_256((unsigned char *)input, (unsigned char *)output);
|
scrypt_1024_1_1_256((unsigned char *)input, (unsigned char *)output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scryptn_hash(const char* input, char* output, uint32_t len)
|
static void scryptn_hash(const char* input, char* output, uint32_t len)
|
||||||
{
|
{
|
||||||
time_t time_table[][2] =
|
time_t time_table[][2] =
|
||||||
{
|
{
|
||||||
{2048, 1389306217},
|
{2048, 1389306217},
|
||||||
{4096, 1456415081},
|
{4096, 1456415081},
|
||||||
{8192, 1506746729},
|
{8192, 1506746729},
|
||||||
{16384, 1557078377},
|
{16384, 1557078377},
|
||||||
{32768, 1657741673},
|
{32768, 1657741673},
|
||||||
{65536, 1859068265},
|
{65536, 1859068265},
|
||||||
{131072, 2060394857},
|
{131072, 2060394857},
|
||||||
{262144, 1722307603},
|
{262144, 1722307603},
|
||||||
{524288, 1769642992},
|
{524288, 1769642992},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i=0; time_table[i][0]; i++)
|
for(int i=0; time_table[i][0]; i++)
|
||||||
if(time(NULL) < time_table[i+1][1])
|
if(time(NULL) < time_table[i+1][1])
|
||||||
{
|
{
|
||||||
scrypt_N_R_1_256(input, output, time_table[i][0], 1, len);
|
scrypt_N_R_1_256(input, output, time_table[i][0], 1, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void neoscrypt_hash(const char* input, char* output, uint32_t len)
|
static void neoscrypt_hash(const char* input, char* output, uint32_t len)
|
||||||
{
|
{
|
||||||
neoscrypt((unsigned char *)input, (unsigned char *)output, 0x80000620);
|
neoscrypt((unsigned char *)input, (unsigned char *)output, 0x80000620);
|
||||||
}
|
}
|
||||||
|
|
||||||
YAAMP_ALGO g_algos[] =
|
YAAMP_ALGO g_algos[] =
|
||||||
{
|
{
|
||||||
{"sha256", sha256_double_hash, 1, 0, 0},
|
{"sha256", sha256_double_hash, 1, 0, 0},
|
||||||
{"scrypt", scrypt_hash, 0x10000, 0, 0},
|
{"scrypt", scrypt_hash, 0x10000, 0, 0},
|
||||||
{"scryptn", scryptn_hash, 0x10000, 0, 0},
|
{"scryptn", scryptn_hash, 0x10000, 0, 0},
|
||||||
{"neoscrypt", neoscrypt_hash, 0x10000, 0, 0},
|
{"neoscrypt", neoscrypt_hash, 0x10000, 0, 0},
|
||||||
|
|
||||||
{"c11", c11_hash, 1, 0, 0},
|
{"c11", c11_hash, 1, 0, 0},
|
||||||
{"x11", x11_hash, 1, 0, 0},
|
{"x11", x11_hash, 1, 0, 0},
|
||||||
{"x12", x12_hash, 1, 0, 0},
|
{"x12", x12_hash, 1, 0, 0},
|
||||||
{"x13", x13_hash, 1, 0, 0},
|
{"x13", x13_hash, 1, 0, 0},
|
||||||
{"x14", x14_hash, 1, 0, 0},
|
{"x14", x14_hash, 1, 0, 0},
|
||||||
{"x15", x15_hash, 1, 0, 0},
|
{"x15", x15_hash, 1, 0, 0},
|
||||||
{"x17", x17_hash, 1, 0, 0},
|
{"x17", x17_hash, 1, 0, 0},
|
||||||
{"x22i", x22i_hash, 1, 0, 0},
|
{"x22i", x22i_hash, 1, 0, 0},
|
||||||
|
|
||||||
{"x11evo", x11evo_hash, 1, 0, 0},
|
{"x11evo", x11evo_hash, 1, 0, 0},
|
||||||
{"xevan", xevan_hash, 0x100, 0, 0},
|
{"xevan", xevan_hash, 0x100, 0, 0},
|
||||||
|
|
||||||
{"x16r", x16r_hash, 0x100, 0, 0},
|
{"x16r", x16r_hash, 0x100, 0, 0},
|
||||||
{"x16rv2", x16rv2_hash, 0x100, 0, 0},
|
{"x16rv2", x16rv2_hash, 0x100, 0, 0},
|
||||||
{"x16s", x16s_hash, 0x100, 0, 0},
|
{"x16s", x16s_hash, 0x100, 0, 0},
|
||||||
{"timetravel", timetravel_hash, 0x100, 0, 0},
|
{"timetravel", timetravel_hash, 0x100, 0, 0},
|
||||||
{"bitcore", timetravel10_hash, 0x100, 0, 0},
|
{"bitcore", timetravel10_hash, 0x100, 0, 0},
|
||||||
{"exosis", exosis_hash, 0x100, 0, 0},
|
{"exosis", exosis_hash, 0x100, 0, 0},
|
||||||
{"hsr", hsr_hash, 1, 0, 0},
|
{"hsr", hsr_hash, 1, 0, 0},
|
||||||
{"hmq1725", hmq17_hash, 0x10000, 0, 0},
|
{"hmq1725", hmq17_hash, 0x10000, 0, 0},
|
||||||
|
|
||||||
{"jha", jha_hash, 0x10000, 0},
|
{"jha", jha_hash, 0x10000, 0},
|
||||||
|
|
||||||
{"allium", allium_hash, 0x100, 0, 0},
|
{"allium", allium_hash, 0x100, 0, 0},
|
||||||
{"lyra2", lyra2re_hash, 0x80, 0, 0},
|
{"lyra2", lyra2re_hash, 0x80, 0, 0},
|
||||||
{"lyra2v2", lyra2v2_hash, 0x100, 0, 0},
|
{"lyra2v2", lyra2v2_hash, 0x100, 0, 0},
|
||||||
{"lyra2v3", lyra2v3_hash, 0x100, 0, 0},
|
{"lyra2v3", lyra2v3_hash, 0x100, 0, 0},
|
||||||
{"lyra2z", lyra2z_hash, 0x100, 0, 0},
|
{"lyra2z", lyra2z_hash, 0x100, 0, 0},
|
||||||
{"lyra2zz", lyra2zz_hash, 0x100, 0, 0},
|
{"lyra2zz", lyra2zz_hash, 0x100, 0, 0},
|
||||||
|
|
||||||
{"bastion", bastion_hash, 1, 0 },
|
{"bastion", bastion_hash, 1, 0 },
|
||||||
{"blake", blake_hash, 1, 0 },
|
{"blake", blake_hash, 1, 0 },
|
||||||
{"blakecoin", blakecoin_hash, 1 /*0x100*/, 0, sha256_hash_hex },
|
{"blakecoin", blakecoin_hash, 1 /*0x100*/, 0, sha256_hash_hex },
|
||||||
{"blake2b", blake2b_hash, 1, 0 },
|
{"blake2b", blake2b_hash, 1, 0 },
|
||||||
{"blake2s", blake2s_hash, 1, 0 },
|
{"blake2s", blake2s_hash, 1, 0 },
|
||||||
{"vanilla", blakecoin_hash, 1, 0 },
|
{"vanilla", blakecoin_hash, 1, 0 },
|
||||||
{"decred", decred_hash, 1, 0 },
|
{"decred", decred_hash, 1, 0 },
|
||||||
|
|
||||||
{"deep", deep_hash, 1, 0, 0},
|
{"deep", deep_hash, 1, 0, 0},
|
||||||
{"fresh", fresh_hash, 0x100, 0, 0},
|
{"fresh", fresh_hash, 0x100, 0, 0},
|
||||||
{"quark", quark_hash, 1, 0, 0},
|
{"quark", quark_hash, 1, 0, 0},
|
||||||
{"nist5", nist5_hash, 1, 0, 0},
|
{"nist5", nist5_hash, 1, 0, 0},
|
||||||
{"qubit", qubit_hash, 1, 0, 0},
|
{"qubit", qubit_hash, 1, 0, 0},
|
||||||
{"groestl", groestl_hash, 0x100, 0, sha256_hash_hex }, /* groestlcoin */
|
{"groestl", groestl_hash, 0x100, 0, sha256_hash_hex }, /* groestlcoin */
|
||||||
{"dmd-gr", groestl_hash, 0x100, 0, 0}, /* diamond (double groestl) */
|
{"dmd-gr", groestl_hash, 0x100, 0, 0}, /* diamond (double groestl) */
|
||||||
{"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */
|
{"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */
|
||||||
{"skein", skein_hash, 1, 0, 0},
|
{"skein", skein_hash, 1, 0, 0},
|
||||||
{"sonoa", sonoa_hash, 1, 0, 0},
|
{"sonoa", sonoa_hash, 1, 0, 0},
|
||||||
{"tribus", tribus_hash, 1, 0, 0},
|
{"tribus", tribus_hash, 1, 0, 0},
|
||||||
{"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex },
|
{"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex },
|
||||||
{"keccakc", keccak256_hash, 0x100, 0, 0},
|
{"keccakc", keccak256_hash, 0x100, 0, 0},
|
||||||
{"hex", hex_hash, 0x100, 0, sha256_hash_hex },
|
{"hex", hex_hash, 0x100, 0, sha256_hash_hex },
|
||||||
|
|
||||||
{"phi", phi_hash, 1, 0, 0},
|
|
||||||
{"phi2", phi2_hash, 0x100, 0, 0},
|
|
||||||
|
|
||||||
{"polytimos", polytimos_hash, 1, 0, 0},
|
{"phi", phi_hash, 1, 0, 0},
|
||||||
{"skunk", skunk_hash, 1, 0, 0},
|
{"phi2", phi2_hash, 0x100, 0, 0},
|
||||||
|
|
||||||
{"bmw", bmw_hash, 1, 0, 0},
|
{"polytimos", polytimos_hash, 1, 0, 0},
|
||||||
{"lbk3", lbk3_hash, 0x100, 0, 0},
|
{"skunk", skunk_hash, 1, 0, 0},
|
||||||
{"lbry", lbry_hash, 0x100, 0, 0},
|
|
||||||
{"luffa", luffa_hash, 1, 0, 0},
|
|
||||||
{"penta", penta_hash, 1, 0, 0},
|
|
||||||
{"rainforest", rainforest_hash, 0x100, 0, 0},
|
|
||||||
{"skein2", skein2_hash, 1, 0, 0},
|
|
||||||
{"yescrypt", yescrypt_hash, 0x10000, 0, 0},
|
|
||||||
{"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 },
|
|
||||||
{"yescryptR32", yescryptR32_hash, 0x10000, 0, 0 },
|
|
||||||
{"zr5", zr5_hash, 1, 0, 0},
|
|
||||||
|
|
||||||
{"a5a", a5a_hash, 0x10000, 0, 0},
|
{"bmw", bmw_hash, 1, 0, 0},
|
||||||
{"hive", hive_hash, 0x10000, 0, 0},
|
{"lbk3", lbk3_hash, 0x100, 0, 0},
|
||||||
{"m7m", m7m_hash, 0x10000, 0, 0},
|
{"lbry", lbry_hash, 0x100, 0, 0},
|
||||||
{"veltor", veltor_hash, 1, 0, 0},
|
{"luffa", luffa_hash, 1, 0, 0},
|
||||||
{"velvet", velvet_hash, 0x10000, 0, 0},
|
{"penta", penta_hash, 1, 0, 0},
|
||||||
{"argon2", argon2a_hash, 0x10000, 0, sha256_hash_hex },
|
{"rainforest", rainforest_hash, 0x100, 0, 0},
|
||||||
{"argon2d-dyn", argon2d_dyn_hash, 0x10000, 0, 0 }, // Dynamic Argon2d Implementation
|
{"skein2", skein2_hash, 1, 0, 0},
|
||||||
{"vitalium", vitalium_hash, 1, 0, 0},
|
{"yescrypt", yescrypt_hash, 0x10000, 0, 0},
|
||||||
{"aergo", aergo_hash, 1, 0, 0},
|
{"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 },
|
||||||
|
{"yescryptR32", yescryptR32_hash, 0x10000, 0, 0 },
|
||||||
|
{"zr5", zr5_hash, 1, 0, 0},
|
||||||
|
|
||||||
{"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x
|
{"a5a", a5a_hash, 0x10000, 0, 0},
|
||||||
|
{"hive", hive_hash, 0x10000, 0, 0},
|
||||||
|
{"m7m", m7m_hash, 0x10000, 0, 0},
|
||||||
|
{"veltor", veltor_hash, 1, 0, 0},
|
||||||
|
{"velvet", velvet_hash, 0x10000, 0, 0},
|
||||||
|
{"argon2", argon2a_hash, 0x10000, 0, sha256_hash_hex },
|
||||||
|
{"argon2d-dyn", argon2d_dyn_hash, 0x10000, 0, 0 }, // Dynamic Argon2d Implementation
|
||||||
|
{"vitalium", vitalium_hash, 1, 0, 0},
|
||||||
|
{"aergo", aergo_hash, 1, 0, 0},
|
||||||
|
|
||||||
{"sha256q", sha256q_hash, 1, 0, 0}, // sha256 4x
|
{"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x
|
||||||
|
|
||||||
{"sib", sib_hash, 1, 0, 0},
|
{"sha256q", sha256q_hash, 1, 0, 0}, // sha256 4x
|
||||||
|
|
||||||
{"whirlcoin", whirlpool_hash, 1, 0, sha256_hash_hex }, /* old sha merkleroot */
|
{"sib", sib_hash, 1, 0, 0},
|
||||||
{"whirlpool", whirlpool_hash, 1, 0 }, /* sha256d merkleroot */
|
|
||||||
{"whirlpoolx", whirlpoolx_hash, 1, 0, 0},
|
|
||||||
|
|
||||||
{"", NULL, 0, 0},
|
{"whirlcoin", whirlpool_hash, 1, 0, sha256_hash_hex }, /* old sha merkleroot */
|
||||||
|
{"whirlpool", whirlpool_hash, 1, 0 }, /* sha256d merkleroot */
|
||||||
|
{"whirlpoolx", whirlpoolx_hash, 1, 0, 0},
|
||||||
|
|
||||||
|
{"", NULL, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
YAAMP_ALGO *g_current_algo = NULL;
|
YAAMP_ALGO *g_current_algo = NULL;
|
||||||
|
|
||||||
YAAMP_ALGO *stratum_find_algo(const char *name)
|
YAAMP_ALGO *stratum_find_algo(const char *name)
|
||||||
{
|
{
|
||||||
for(int i=0; g_algos[i].name[0]; i++)
|
for(int i=0; g_algos[i].name[0]; i++)
|
||||||
if(!strcmp(name, g_algos[i].name))
|
if(!strcmp(name, g_algos[i].name))
|
||||||
return &g_algos[i];
|
return &g_algos[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
{
|
{
|
||||||
printf("usage: %s <algo>\n", argv[0]);
|
printf("usage: %s <algo>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
getifaddrs(&g_ifaddr);
|
getifaddrs(&g_ifaddr);
|
||||||
|
|
||||||
initlog(argv[1]);
|
initlog(argv[1]);
|
||||||
|
|
||||||
#ifdef NO_EXCHANGE
|
#ifdef NO_EXCHANGE
|
||||||
// todo: init with a db setting or a yiimp shell command
|
// todo: init with a db setting or a yiimp shell command
|
||||||
g_autoexchange = false;
|
g_autoexchange = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char configfile[1024];
|
char configfile[1024];
|
||||||
sprintf(configfile, "%s.conf", argv[1]);
|
sprintf(configfile, "%s.conf", argv[1]);
|
||||||
|
|
||||||
dictionary *ini = iniparser_load(configfile);
|
dictionary *ini = iniparser_load(configfile);
|
||||||
if(!ini)
|
if(!ini)
|
||||||
{
|
{
|
||||||
debuglog("cant load config file %s\n", configfile);
|
debuglog("cant load config file %s\n", configfile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_tcp_port = iniparser_getint(ini, "TCP:port", 3333);
|
g_tcp_port = iniparser_getint(ini, "TCP:port", 3333);
|
||||||
strcpy(g_tcp_server, iniparser_getstring(ini, "TCP:server", NULL));
|
strcpy(g_tcp_server, iniparser_getstring(ini, "TCP:server", NULL));
|
||||||
strcpy(g_tcp_password, iniparser_getstring(ini, "TCP:password", NULL));
|
strcpy(g_tcp_password, iniparser_getstring(ini, "TCP:password", NULL));
|
||||||
|
|
||||||
strcpy(g_sql_host, iniparser_getstring(ini, "SQL:host", NULL));
|
strcpy(g_sql_host, iniparser_getstring(ini, "SQL:host", NULL));
|
||||||
strcpy(g_sql_database, iniparser_getstring(ini, "SQL:database", NULL));
|
strcpy(g_sql_database, iniparser_getstring(ini, "SQL:database", NULL));
|
||||||
strcpy(g_sql_username, iniparser_getstring(ini, "SQL:username", NULL));
|
strcpy(g_sql_username, iniparser_getstring(ini, "SQL:username", NULL));
|
||||||
strcpy(g_sql_password, iniparser_getstring(ini, "SQL:password", NULL));
|
strcpy(g_sql_password, iniparser_getstring(ini, "SQL:password", NULL));
|
||||||
g_sql_port = iniparser_getint(ini, "SQL:port", 3306);
|
g_sql_port = iniparser_getint(ini, "SQL:port", 3306);
|
||||||
|
|
||||||
// optional coin filters (to mine only one on a special port or a test instance)
|
// optional coin filters (to mine only one on a special port or a test instance)
|
||||||
char *coin_filter = iniparser_getstring(ini, "WALLETS:include", NULL);
|
char *coin_filter = iniparser_getstring(ini, "WALLETS:include", NULL);
|
||||||
strcpy(g_stratum_coin_include, coin_filter ? coin_filter : "");
|
strcpy(g_stratum_coin_include, coin_filter ? coin_filter : "");
|
||||||
coin_filter = iniparser_getstring(ini, "WALLETS:exclude", NULL);
|
coin_filter = iniparser_getstring(ini, "WALLETS:exclude", NULL);
|
||||||
strcpy(g_stratum_coin_exclude, coin_filter ? coin_filter : "");
|
strcpy(g_stratum_coin_exclude, coin_filter ? coin_filter : "");
|
||||||
|
|
||||||
strcpy(g_stratum_algo, iniparser_getstring(ini, "STRATUM:algo", NULL));
|
strcpy(g_stratum_algo, iniparser_getstring(ini, "STRATUM:algo", NULL));
|
||||||
g_stratum_difficulty = iniparser_getdouble(ini, "STRATUM:difficulty", 16);
|
g_stratum_difficulty = iniparser_getdouble(ini, "STRATUM:difficulty", 16);
|
||||||
g_stratum_min_diff = iniparser_getdouble(ini, "STRATUM:diff_min", g_stratum_difficulty/2);
|
g_stratum_min_diff = iniparser_getdouble(ini, "STRATUM:diff_min", g_stratum_difficulty/2);
|
||||||
g_stratum_max_diff = iniparser_getdouble(ini, "STRATUM:diff_max", g_stratum_difficulty*8192);
|
g_stratum_max_diff = iniparser_getdouble(ini, "STRATUM:diff_max", g_stratum_difficulty*8192);
|
||||||
|
|
||||||
g_stratum_max_cons = iniparser_getint(ini, "STRATUM:max_cons", 5000);
|
g_stratum_max_cons = iniparser_getint(ini, "STRATUM:max_cons", 5000);
|
||||||
g_stratum_max_ttf = iniparser_getint(ini, "STRATUM:max_ttf", 0x70000000);
|
g_stratum_max_ttf = iniparser_getint(ini, "STRATUM:max_ttf", 0x70000000);
|
||||||
g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true);
|
g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true);
|
||||||
g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true);
|
g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true);
|
||||||
g_handle_haproxy_ips = iniparser_getint(ini, "STRATUM:haproxy_ips", g_handle_haproxy_ips);
|
g_handle_haproxy_ips = iniparser_getint(ini, "STRATUM:haproxy_ips", g_handle_haproxy_ips);
|
||||||
g_socket_recv_timeout = iniparser_getint(ini, "STRATUM:recv_timeout", 600);
|
g_socket_recv_timeout = iniparser_getint(ini, "STRATUM:recv_timeout", 600);
|
||||||
|
|
||||||
g_max_shares = iniparser_getint(ini, "STRATUM:max_shares", g_max_shares);
|
g_max_shares = iniparser_getint(ini, "STRATUM:max_shares", g_max_shares);
|
||||||
g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0);
|
g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0);
|
||||||
|
|
||||||
g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false);
|
g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false);
|
||||||
g_debuglog_hash = iniparser_getint(ini, "DEBUGLOG:hash", false);
|
g_debuglog_hash = iniparser_getint(ini, "DEBUGLOG:hash", false);
|
||||||
g_debuglog_socket = iniparser_getint(ini, "DEBUGLOG:socket", false);
|
g_debuglog_socket = iniparser_getint(ini, "DEBUGLOG:socket", false);
|
||||||
g_debuglog_rpc = iniparser_getint(ini, "DEBUGLOG:rpc", false);
|
g_debuglog_rpc = iniparser_getint(ini, "DEBUGLOG:rpc", false);
|
||||||
g_debuglog_list = iniparser_getint(ini, "DEBUGLOG:list", false);
|
g_debuglog_list = iniparser_getint(ini, "DEBUGLOG:list", false);
|
||||||
g_debuglog_remote = iniparser_getint(ini, "DEBUGLOG:remote", false);
|
g_debuglog_remote = iniparser_getint(ini, "DEBUGLOG:remote", false);
|
||||||
|
|
||||||
iniparser_freedict(ini);
|
iniparser_freedict(ini);
|
||||||
|
|
||||||
g_current_algo = stratum_find_algo(g_stratum_algo);
|
g_current_algo = stratum_find_algo(g_stratum_algo);
|
||||||
|
|
||||||
if(!g_current_algo) yaamp_error("invalid algo");
|
if(!g_current_algo) yaamp_error("invalid algo");
|
||||||
if(!g_current_algo->hash_function) yaamp_error("no hash function");
|
if(!g_current_algo->hash_function) yaamp_error("no hash function");
|
||||||
|
|
||||||
// struct rlimit rlim_files = {0x10000, 0x10000};
|
// struct rlimit rlim_files = {0x10000, 0x10000};
|
||||||
// setrlimit(RLIMIT_NOFILE, &rlim_files);
|
// setrlimit(RLIMIT_NOFILE, &rlim_files);
|
||||||
|
|
||||||
struct rlimit rlim_threads = {0x8000, 0x8000};
|
struct rlimit rlim_threads = {0x8000, 0x8000};
|
||||||
setrlimit(RLIMIT_NPROC, &rlim_threads);
|
setrlimit(RLIMIT_NPROC, &rlim_threads);
|
||||||
|
|
||||||
stratumlogdate("starting stratum for %s on %s:%d\n",
|
stratumlogdate("starting stratum for %s on %s:%d\n",
|
||||||
g_current_algo->name, g_tcp_server, g_tcp_port);
|
g_current_algo->name, g_tcp_server, g_tcp_port);
|
||||||
|
|
||||||
// ntime should not be changed by miners for these algos
|
// ntime should not be changed by miners for these algos
|
||||||
g_allow_rolltime = strcmp(g_stratum_algo,"x11evo");
|
g_allow_rolltime = strcmp(g_stratum_algo,"x11evo");
|
||||||
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"timetravel");
|
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"timetravel");
|
||||||
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"bitcore");
|
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"bitcore");
|
||||||
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"exosis");
|
g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"exosis");
|
||||||
if (!g_allow_rolltime)
|
if (!g_allow_rolltime)
|
||||||
stratumlog("note: time roll disallowed for %s algo\n", g_current_algo->name);
|
stratumlog("note: time roll disallowed for %s algo\n", g_current_algo->name);
|
||||||
|
|
||||||
g_db = db_connect();
|
g_db = db_connect();
|
||||||
if(!g_db) yaamp_error("Cant connect database");
|
if(!g_db) yaamp_error("Cant connect database");
|
||||||
|
|
||||||
// db_query(g_db, "update mining set stratumids='loading'");
|
// db_query(g_db, "update mining set stratumids='loading'");
|
||||||
|
|
||||||
yaamp_create_mutex(&g_db_mutex);
|
yaamp_create_mutex(&g_db_mutex);
|
||||||
yaamp_create_mutex(&g_nonce1_mutex);
|
yaamp_create_mutex(&g_nonce1_mutex);
|
||||||
yaamp_create_mutex(&g_job_create_mutex);
|
yaamp_create_mutex(&g_job_create_mutex);
|
||||||
|
|
||||||
YAAMP_DB *db = db_connect();
|
YAAMP_DB *db = db_connect();
|
||||||
if(!db) yaamp_error("Cant connect database");
|
if(!db) yaamp_error("Cant connect database");
|
||||||
|
|
||||||
db_register_stratum(db);
|
db_register_stratum(db);
|
||||||
db_update_algos(db);
|
db_update_algos(db);
|
||||||
db_update_coinds(db);
|
db_update_coinds(db);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
job_init();
|
job_init();
|
||||||
|
|
||||||
// job_signal();
|
// job_signal();
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
pthread_t thread1;
|
pthread_t thread1;
|
||||||
pthread_create(&thread1, NULL, monitor_thread, NULL);
|
pthread_create(&thread1, NULL, monitor_thread, NULL);
|
||||||
|
|
||||||
pthread_t thread2;
|
pthread_t thread2;
|
||||||
pthread_create(&thread2, NULL, stratum_thread, NULL);
|
pthread_create(&thread2, NULL, stratum_thread, NULL);
|
||||||
|
|
||||||
sleep(20);
|
sleep(20);
|
||||||
|
|
||||||
while(!g_exiting)
|
while(!g_exiting)
|
||||||
{
|
{
|
||||||
db_register_stratum(db);
|
db_register_stratum(db);
|
||||||
db_update_workers(db);
|
db_update_workers(db);
|
||||||
db_update_algos(db);
|
db_update_algos(db);
|
||||||
db_update_coinds(db);
|
db_update_coinds(db);
|
||||||
|
|
||||||
if(g_stratum_renting)
|
if(g_stratum_renting)
|
||||||
{
|
{
|
||||||
db_update_renters(db);
|
db_update_renters(db);
|
||||||
db_update_remotes(db);
|
db_update_remotes(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
share_write(db);
|
share_write(db);
|
||||||
share_prune(db);
|
share_prune(db);
|
||||||
|
|
||||||
block_prune(db);
|
block_prune(db);
|
||||||
submit_prune(db);
|
submit_prune(db);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
job_signal();
|
job_signal();
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
// source_prune();
|
// source_prune();
|
||||||
|
|
||||||
object_prune(&g_list_coind, coind_delete);
|
object_prune(&g_list_coind, coind_delete);
|
||||||
object_prune(&g_list_remote, remote_delete);
|
object_prune(&g_list_remote, remote_delete);
|
||||||
object_prune(&g_list_job, job_delete);
|
object_prune(&g_list_job, job_delete);
|
||||||
object_prune(&g_list_client, client_delete);
|
object_prune(&g_list_client, client_delete);
|
||||||
object_prune(&g_list_block, block_delete);
|
object_prune(&g_list_block, block_delete);
|
||||||
object_prune(&g_list_worker, worker_delete);
|
object_prune(&g_list_worker, worker_delete);
|
||||||
object_prune(&g_list_share, share_delete);
|
object_prune(&g_list_share, share_delete);
|
||||||
object_prune(&g_list_submit, submit_delete);
|
object_prune(&g_list_submit, submit_delete);
|
||||||
|
|
||||||
if (!g_exiting) sleep(20);
|
if (!g_exiting) sleep(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
stratumlog("closing database...\n");
|
stratumlog("closing database...\n");
|
||||||
db_close(db);
|
db_close(db);
|
||||||
|
|
||||||
pthread_join(thread2, NULL);
|
pthread_join(thread2, NULL);
|
||||||
db_close(g_db); // client threads (called by stratum one)
|
db_close(g_db); // client threads (called by stratum one)
|
||||||
|
|
||||||
closelogs();
|
closelogs();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void *monitor_thread(void *p)
|
void *monitor_thread(void *p)
|
||||||
{
|
{
|
||||||
while(!g_exiting)
|
while(!g_exiting)
|
||||||
{
|
{
|
||||||
sleep(120);
|
sleep(120);
|
||||||
|
|
||||||
if(g_last_broadcasted + YAAMP_MAXJOBDELAY < time(NULL))
|
if(g_last_broadcasted + YAAMP_MAXJOBDELAY < time(NULL))
|
||||||
{
|
{
|
||||||
g_exiting = true;
|
g_exiting = true;
|
||||||
stratumlogdate("%s dead lock, exiting...\n", g_stratum_algo);
|
stratumlogdate("%s dead lock, exiting...\n", g_stratum_algo);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(g_max_shares && g_shares_counter) {
|
if(g_max_shares && g_shares_counter) {
|
||||||
|
|
||||||
if((g_shares_counter - g_shares_log) > 10000) {
|
if((g_shares_counter - g_shares_log) > 10000) {
|
||||||
stratumlogdate("%s %luK shares...\n", g_stratum_algo, (g_shares_counter/1000u));
|
stratumlogdate("%s %luK shares...\n", g_stratum_algo, (g_shares_counter/1000u));
|
||||||
g_shares_log = g_shares_counter;
|
g_shares_log = g_shares_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(g_shares_counter > g_max_shares) {
|
if(g_shares_counter > g_max_shares) {
|
||||||
g_exiting = true;
|
g_exiting = true;
|
||||||
stratumlogdate("%s need a restart (%lu shares), exiting...\n", g_stratum_algo, (unsigned long) g_max_shares);
|
stratumlogdate("%s need a restart (%lu shares), exiting...\n", g_stratum_algo, (unsigned long) g_max_shares);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void *stratum_thread(void *p)
|
void *stratum_thread(void *p)
|
||||||
{
|
{
|
||||||
int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
|
int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(listen_sock <= 0) yaamp_error("socket");
|
if(listen_sock <= 0) yaamp_error("socket");
|
||||||
|
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
|
setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
|
||||||
|
|
||||||
struct sockaddr_in serv;
|
struct sockaddr_in serv;
|
||||||
|
|
||||||
serv.sin_family = AF_INET;
|
serv.sin_family = AF_INET;
|
||||||
serv.sin_addr.s_addr = htonl(INADDR_ANY);
|
serv.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
serv.sin_port = htons(g_tcp_port);
|
serv.sin_port = htons(g_tcp_port);
|
||||||
|
|
||||||
int res = bind(listen_sock, (struct sockaddr*)&serv, sizeof(serv));
|
int res = bind(listen_sock, (struct sockaddr*)&serv, sizeof(serv));
|
||||||
if(res < 0) yaamp_error("bind");
|
if(res < 0) yaamp_error("bind");
|
||||||
|
|
||||||
res = listen(listen_sock, 4096);
|
res = listen(listen_sock, 4096);
|
||||||
if(res < 0) yaamp_error("listen");
|
if(res < 0) yaamp_error("listen");
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int failcount = 0;
|
int failcount = 0;
|
||||||
while(!g_exiting)
|
while(!g_exiting)
|
||||||
{
|
{
|
||||||
int sock = accept(listen_sock, NULL, NULL);
|
int sock = accept(listen_sock, NULL, NULL);
|
||||||
if(sock <= 0)
|
if(sock <= 0)
|
||||||
{
|
{
|
||||||
int error = errno;
|
int error = errno;
|
||||||
stratumlog("%s socket accept() error %d\n", g_stratum_algo, error);
|
stratumlog("%s socket accept() error %d\n", g_stratum_algo, error);
|
||||||
failcount++;
|
failcount++;
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
if (error == 24 && failcount > 5) {
|
if (error == 24 && failcount > 5) {
|
||||||
g_exiting = true; // happen when max open files is reached (see ulimit)
|
g_exiting = true; // happen when max open files is reached (see ulimit)
|
||||||
stratumlogdate("%s too much socket failure, exiting...\n", g_stratum_algo);
|
stratumlogdate("%s too much socket failure, exiting...\n", g_stratum_algo);
|
||||||
exit(error);
|
exit(error);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
failcount = 0;
|
failcount = 0;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
int res = pthread_create(&thread, NULL, client_thread, (void *)(long)sock);
|
int res = pthread_create(&thread, NULL, client_thread, (void *)(long)sock);
|
||||||
if(res != 0)
|
if(res != 0)
|
||||||
{
|
{
|
||||||
int error = errno;
|
int error = errno;
|
||||||
close(sock);
|
close(sock);
|
||||||
g_exiting = true;
|
g_exiting = true;
|
||||||
stratumlog("%s pthread_create error %d %d\n", g_stratum_algo, res, error);
|
stratumlog("%s pthread_create error %d %d\n", g_stratum_algo, res, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_detach(thread);
|
pthread_detach(thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue