kanoi 11 years ago
parent
commit
1a23e26876
  1. 19
      src/ckpool.c
  2. 4
      src/ckpool.h
  3. 47
      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);
}
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)
{
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->update_interval, json_conf, "update_interval");
json_get_string(&ckp->serverurl, json_conf, "serverurl");
json_get_int(&ckp->mindiff, json_conf, "mindiff");
json_get_int(&ckp->startdiff, json_conf, "startdiff");
json_get_int64(&ckp->mindiff, json_conf, "mindiff");
json_get_int64(&ckp->startdiff, json_conf, "startdiff");
json_get_string(&ckp->logdir, json_conf, "logdir");
arr_val = json_object_get(json_conf, "proxy");
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
/* Difficulty settings */
int mindiff; // Default 1
int startdiff; // Default 42
int64_t mindiff; // Default 1
int64_t startdiff; // Default 42
/* Coinbase data */
char *btcaddress; // Address to mine to

47
src/stratifier.c

@ -522,8 +522,7 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
wb->logdir = ckalloc(len);
ck_wlock(&workbase_lock);
if (!ckp->proxy)
wb->id = workbase_id++;
wb->id = workbase_id++;
if (strncmp(wb->prevhash, lasthash, 64)) {
*new_block = true;
@ -1408,7 +1407,7 @@ static double sane_tdiff(tv_t *end, tv_t *start)
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;
int64_t next_blockid, optimal;
@ -1418,7 +1417,10 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
ck_rlock(&workbase_lock);
next_blockid = workbase_id + 1;
network_diff = current_workbase->network_diff;
if (ckp->proxy)
network_diff = current_workbase->diff;
else
network_diff = current_workbase->network_diff;
ck_runlock(&workbase_lock);
tdiff = sane_tdiff(&now_t, &client->last_share);
@ -1451,12 +1453,10 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
if (client->ssdc < 72 && tdiff < 240)
return;
if (diff != client->diff)
return;
/* We have the effect of a change pending */
if (client->diff_change_job_id >= next_blockid)
if (diff != client->diff) {
client->ssdc = 0;
return;
}
/* Diff rate ratio */
dsps = client->dsps5 / bias;
@ -1467,23 +1467,18 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid)
return;
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
* and has just returned */
if (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;
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;
ts_t ts_now;
/* Submit anything over 95% of the diff in case of rounding errors */
if (diff < current_workbase->network_diff * 0.95)
/* Submit anything over 99% of the diff in case of rounding errors */
if (diff < current_workbase->network_diff * 0.99)
return;
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;
}
invalid = false;
if (wb->proxy && sdiff > wdiff)
if (wb->proxy && sdiff >= wdiff)
submit = true;
out_unlock:
ck_runlock(&workbase_lock);
@ -1812,7 +1807,7 @@ out_unlock:
}
} else
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. */
val = json_object();

Loading…
Cancel
Save