diff --git a/src/ckpool.c b/src/ckpool.c index 54156d08..52275a6c 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -274,6 +274,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_decref(json_conf); } @@ -426,6 +428,10 @@ int main(int argc, char **argv) ckp.blockpoll = 500; if (!ckp.update_interval) ckp.update_interval = 30; + if (!ckp.mindiff) + ckp.mindiff = 1; + if (!ckp.startdiff) + ckp.startdiff = 42; ckp.main.ckp = &ckp; ckp.main.processname = strdup("main"); diff --git a/src/ckpool.h b/src/ckpool.h index 18e72a16..327e63eb 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -54,6 +54,10 @@ struct ckpool_instance { char *btcdpass; int blockpoll; // How frequently in ms to poll bitcoind for block updates + /* Difficulty settings */ + int mindiff; // Default 1 + int startdiff; // Default 42 + /* Coinbase data */ char *btcaddress; // Address to mine to char *btcsig; // Optional signature to add to coinbase diff --git a/src/stratifier.c b/src/stratifier.c index ae93acf9..9b1f443e 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -460,7 +460,7 @@ static stratum_instance_t *__stratum_add_instance(int id) stats.live_clients++; instance->id = id; - instance->diff = instance->old_diff = 1; + instance->diff = instance->old_diff = global_ckp->startdiff; tv_time(&instance->ldc); LOGINFO("Added instance %d", id); HASH_ADD_INT(stratum_instances, id, instance); @@ -808,11 +808,19 @@ out: return json_boolean(ret); } +static void stratum_send_diff(stratum_instance_t *client) +{ + json_t *json_msg; + + json_msg = json_pack("{s[i]soss}", "params", client->diff, "id", json_null(), + "method", "mining.set_difficulty"); + stratum_add_send(json_msg, client->id); +} + static void add_submit(stratum_instance_t *client, int diff, bool valid) { int next_blockid, optimal, share_duration; double tdiff, drr, dsps, network_diff; - json_t *json_msg; tv_t now_t; tv_time(&now_t); @@ -864,10 +872,10 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid) } optimal = round(dsps * 3.33); - if (optimal <= 1) { - if (client->diff == 1) + if (optimal <= global_ckp->mindiff) { + if (client->diff == global_ckp->mindiff) return; - optimal = 1; + optimal = global_ckp->mindiff; } ck_rlock(&workbase_lock); @@ -894,9 +902,7 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid) client->diff_change_job_id = next_blockid; client->old_diff = client->diff; client->diff = optimal; - json_msg = json_pack("{s[i]soss}", "params", client->diff, "id", json_null(), - "method", "mining.set_difficulty"); - stratum_add_send(json_msg, client->id); + stratum_send_diff(client); } /* FIXME Add logging of these as well */ @@ -1312,8 +1318,18 @@ out: json_object_set_nocheck(json_msg, "result", result_val); stratum_add_send(json_msg, client_id); - if (update) + if (update) { + stratum_instance_t *client; + stratum_send_update(client_id, true); + + ck_rlock(&instance_lock); + client = __instance_by_id(client_id); + ck_runlock(&instance_lock); + + if (likely(client)) + stratum_send_diff(client); + } } static void *stratum_receiver(void *arg)