kanoi 10 years ago
parent
commit
1a23e26876
  1. 19
      src/ckpool.c
  2. 4
      src/ckpool.h
  3. 43
      src/stratifier.c

19
src/ckpool.c

@ -854,6 +854,21 @@ static void json_get_string(char **store, json_t *val, const char *res)
*store = strdup(buf); *store = strdup(buf);
} }
static void json_get_int64(int64_t *store, json_t *val, const char *res)
{
json_t *entry = json_object_get(val, res);
if (!entry) {
LOGDEBUG("Json did not find entry %s", res);
return;
}
if (!json_is_integer(entry)) {
LOGWARNING("Json entry %s is not an integer", res);
return;
}
*store = json_integer_value(entry);
}
static void json_get_int(int *store, json_t *val, const char *res) static void json_get_int(int *store, json_t *val, const char *res)
{ {
json_t *entry = json_object_get(val, res); json_t *entry = json_object_get(val, res);
@ -930,8 +945,8 @@ static void parse_config(ckpool_t *ckp)
json_get_int(&ckp->blockpoll, json_conf, "blockpoll"); json_get_int(&ckp->blockpoll, json_conf, "blockpoll");
json_get_int(&ckp->update_interval, json_conf, "update_interval"); json_get_int(&ckp->update_interval, json_conf, "update_interval");
json_get_string(&ckp->serverurl, json_conf, "serverurl"); json_get_string(&ckp->serverurl, json_conf, "serverurl");
json_get_int(&ckp->mindiff, json_conf, "mindiff"); json_get_int64(&ckp->mindiff, json_conf, "mindiff");
json_get_int(&ckp->startdiff, json_conf, "startdiff"); json_get_int64(&ckp->startdiff, json_conf, "startdiff");
json_get_string(&ckp->logdir, json_conf, "logdir"); json_get_string(&ckp->logdir, json_conf, "logdir");
arr_val = json_object_get(json_conf, "proxy"); arr_val = json_object_get(json_conf, "proxy");
if (arr_val && json_is_array(arr_val)) { if (arr_val && json_is_array(arr_val)) {

4
src/ckpool.h

@ -146,8 +146,8 @@ struct ckpool_instance {
int blockpoll; // How frequently in ms to poll bitcoind for block updates int blockpoll; // How frequently in ms to poll bitcoind for block updates
/* Difficulty settings */ /* Difficulty settings */
int mindiff; // Default 1 int64_t mindiff; // Default 1
int startdiff; // Default 42 int64_t startdiff; // Default 42
/* Coinbase data */ /* Coinbase data */
char *btcaddress; // Address to mine to char *btcaddress; // Address to mine to

43
src/stratifier.c

@ -522,7 +522,6 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
wb->logdir = ckalloc(len); wb->logdir = ckalloc(len);
ck_wlock(&workbase_lock); ck_wlock(&workbase_lock);
if (!ckp->proxy)
wb->id = workbase_id++; wb->id = workbase_id++;
if (strncmp(wb->prevhash, lasthash, 64)) { if (strncmp(wb->prevhash, lasthash, 64)) {
@ -1408,7 +1407,7 @@ static double sane_tdiff(tv_t *end, tv_t *start)
return tdiff; return tdiff;
} }
static void add_submit(stratum_instance_t *client, int diff, bool valid) static void add_submit(ckpool_t *ckp, stratum_instance_t *client, int diff, bool valid)
{ {
double tdiff, bdiff, dsps, drr, network_diff, bias; double tdiff, bdiff, dsps, drr, network_diff, bias;
int64_t next_blockid, optimal; int64_t next_blockid, optimal;
@ -1418,6 +1417,9 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
ck_rlock(&workbase_lock); ck_rlock(&workbase_lock);
next_blockid = workbase_id + 1; next_blockid = workbase_id + 1;
if (ckp->proxy)
network_diff = current_workbase->diff;
else
network_diff = current_workbase->network_diff; network_diff = current_workbase->network_diff;
ck_runlock(&workbase_lock); ck_runlock(&workbase_lock);
@ -1451,12 +1453,10 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
if (client->ssdc < 72 && tdiff < 240) if (client->ssdc < 72 && tdiff < 240)
return; return;
if (diff != client->diff) if (diff != client->diff) {
return; client->ssdc = 0;
/* We have the effect of a change pending */
if (client->diff_change_job_id >= next_blockid)
return; return;
}
/* Diff rate ratio */ /* Diff rate ratio */
dsps = client->dsps5 / bias; dsps = client->dsps5 / bias;
@ -1467,23 +1467,18 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
return; return;
optimal = round(dsps * 3.33); optimal = round(dsps * 3.33);
if (optimal <= client->ckp->mindiff) {
if (client->diff == client->ckp->mindiff)
return;
optimal = client->ckp->mindiff;
}
if (optimal > network_diff) {
/* Intentionally round down here */
optimal = network_diff;
if (client->diff == optimal)
return;
}
/* Don't drop diff to rapidly in case the client simply switched away /* Don't drop diff to rapidly in case the client simply switched away
* and has just returned */ * and has just returned */
if (optimal < client->diff / 2) if (optimal < client->diff / 2)
optimal = client->diff / 2; optimal = client->diff / 2;
/* Clamp to mindiff ~ network_diff */
if (optimal < ckp->mindiff)
optimal = ckp->mindiff;
if (optimal > network_diff)
optimal = network_diff;
if (client->diff == optimal)
return;
client->ssdc = 0; client->ssdc = 0;
LOGINFO("Client %d biased dsps %.2f dsps %.2f drr %.2f adjust diff from %ld to: %ld ", LOGINFO("Client %d biased dsps %.2f dsps %.2f drr %.2f adjust diff from %ld to: %ld ",
@ -1510,8 +1505,8 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c
ckpool_t *ckp; ckpool_t *ckp;
ts_t ts_now; ts_t ts_now;
/* Submit anything over 95% of the diff in case of rounding errors */ /* Submit anything over 99% of the diff in case of rounding errors */
if (diff < current_workbase->network_diff * 0.95) if (diff < current_workbase->network_diff * 0.99)
return; return;
LOGWARNING("Possible block solve diff %f !", diff); LOGWARNING("Possible block solve diff %f !", diff);
@ -1778,7 +1773,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg,
goto out_unlock; goto out_unlock;
} }
invalid = false; invalid = false;
if (wb->proxy && sdiff > wdiff) if (wb->proxy && sdiff >= wdiff)
submit = true; submit = true;
out_unlock: out_unlock:
ck_runlock(&workbase_lock); ck_runlock(&workbase_lock);
@ -1812,7 +1807,7 @@ out_unlock:
} }
} else } else
LOGINFO("Rejected client %d invalid share", client->id); LOGINFO("Rejected client %d invalid share", client->id);
add_submit(client, diff, result); add_submit(ckp, client, diff, result);
/* Now write to the pool's sharelog. */ /* Now write to the pool's sharelog. */
val = json_object(); val = json_object();

Loading…
Cancel
Save