void coind_sort() { for(CLI li = g_list_coind.first; li && li->next; li = li->next) { YAAMP_COIND *coind1 = (YAAMP_COIND *)li->data; if(coind1->deleted) continue; YAAMP_COIND *coind2 = (YAAMP_COIND *)li->next->data; if(coind2->deleted) continue; double p1 = coind_profitability(coind1); double p2 = coind_profitability(coind2); if(p2 > p1) { g_list_coind.Swap(li, li->next); coind_sort(); return; } } }
double coind_profitability(YAAMP_COIND *coind) { if(!coind->difficulty) return 0; if(coind->pool_ttf > g_stratum_max_ttf) return 0; // double prof = 24*60*60*1000 / (coind->difficulty / 1000000 * 0x100000000) * reward * coind->price; // double prof = 24*60*60*1000 / coind->difficulty / 4294.967296 * reward * coind->price; double prof = 20116.56761169 / coind->difficulty * coind->reward * coind->price; if(!strcmp(g_current_algo->name, "sha256")) prof *= 1000; if(!coind->isaux && !coind->pos) { for(CLI li = g_list_coind.first; li; li = li->next) { YAAMP_COIND *aux = (YAAMP_COIND *)li->data; if(!coind_can_mine(aux, true)) continue; prof += coind_profitability(aux); } } return prof; }
void coind_create_job(YAAMP_COIND *coind, bool force) { // debuglog("create job %s\n", coind->symbol); bool b = rpc_connected(&coind->rpc); if(!b) return; CommonLock(&coind->mutex); YAAMP_JOB_TEMPLATE *templ = coind_create_template(coind); if(!templ) { CommonUnlock(&coind->mutex); return; } YAAMP_JOB *job_last = coind->job; if( !force && job_last && job_last->templ && job_last->templ->created + 45 > time(NULL) && templ->height == job_last->templ->height && templ->txcount == job_last->templ->txcount && strcmp(templ->coinb2, job_last->templ->coinb2) == 0) { // debuglog("coind_create_job %s %d same template %x \n", coind->name, coind->height, coind->job->id); delete templ; CommonUnlock(&coind->mutex); return; } //////////////////////////////////////////////////////////////////////////////////////// int height = coind->height; coind->height = templ->height-1; if(height > coind->height) { stratumlog("%s went from %d to %d\n", coind->name, height, coind->height); // coind->auto_ready = false; } if(height < coind->height && !coind->newblock) { if(coind->auto_ready && coind->notreportingcounter++ > 5) stratumlog("%s %d not reporting\n", coind->name, coind->height); } uint64_t coin_target = decode_compact(templ->nbits); coind->difficulty = target_to_diff(coin_target); coind->newblock = false; //////////////////////////////////////////////////////////////////////////////////////// object_delete(coind->job); coind->job = new YAAMP_JOB; memset(coind->job, 0, sizeof(YAAMP_JOB)); sprintf(coind->job->name, "%s", coind->symbol); coind->job->id = job_get_jobid(); coind->job->templ = templ; coind->job->profit = coind_profitability(coind); coind->job->maxspeed = coind_nethash(coind) * (g_current_algo->profit? min(1.0, coind_profitability(coind)/g_current_algo->profit): 1); coind->job->coind = coind; coind->job->remote = NULL; g_list_job.AddTail(coind->job); CommonUnlock(&coind->mutex); // debuglog("coind_create_job %s %d new job %x\n", coind->name, coind->height, coind->job->id); }