Browse Source

Make the start and minimum diff configurable and set them to 42 and 1 by default

master
Con Kolivas 11 years ago
parent
commit
55045434f1
  1. 6
      src/ckpool.c
  2. 4
      src/ckpool.h
  3. 34
      src/stratifier.c

6
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->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_int(&ckp->startdiff, json_conf, "startdiff");
json_decref(json_conf); json_decref(json_conf);
} }
@ -426,6 +428,10 @@ int main(int argc, char **argv)
ckp.blockpoll = 500; ckp.blockpoll = 500;
if (!ckp.update_interval) if (!ckp.update_interval)
ckp.update_interval = 30; ckp.update_interval = 30;
if (!ckp.mindiff)
ckp.mindiff = 1;
if (!ckp.startdiff)
ckp.startdiff = 42;
ckp.main.ckp = &ckp; ckp.main.ckp = &ckp;
ckp.main.processname = strdup("main"); ckp.main.processname = strdup("main");

4
src/ckpool.h

@ -54,6 +54,10 @@ struct ckpool_instance {
char *btcdpass; char *btcdpass;
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 */
int mindiff; // Default 1
int startdiff; // Default 42
/* Coinbase data */ /* Coinbase data */
char *btcaddress; // Address to mine to char *btcaddress; // Address to mine to
char *btcsig; // Optional signature to add to coinbase char *btcsig; // Optional signature to add to coinbase

34
src/stratifier.c

@ -460,7 +460,7 @@ static stratum_instance_t *__stratum_add_instance(int id)
stats.live_clients++; stats.live_clients++;
instance->id = id; instance->id = id;
instance->diff = instance->old_diff = 1; instance->diff = instance->old_diff = global_ckp->startdiff;
tv_time(&instance->ldc); tv_time(&instance->ldc);
LOGINFO("Added instance %d", id); LOGINFO("Added instance %d", id);
HASH_ADD_INT(stratum_instances, id, instance); HASH_ADD_INT(stratum_instances, id, instance);
@ -808,11 +808,19 @@ out:
return json_boolean(ret); 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) static void add_submit(stratum_instance_t *client, int diff, bool valid)
{ {
int next_blockid, optimal, share_duration; int next_blockid, optimal, share_duration;
double tdiff, drr, dsps, network_diff; double tdiff, drr, dsps, network_diff;
json_t *json_msg;
tv_t now_t; tv_t now_t;
tv_time(&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); optimal = round(dsps * 3.33);
if (optimal <= 1) { if (optimal <= global_ckp->mindiff) {
if (client->diff == 1) if (client->diff == global_ckp->mindiff)
return; return;
optimal = 1; optimal = global_ckp->mindiff;
} }
ck_rlock(&workbase_lock); 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->diff_change_job_id = next_blockid;
client->old_diff = client->diff; client->old_diff = client->diff;
client->diff = optimal; client->diff = optimal;
json_msg = json_pack("{s[i]soss}", "params", client->diff, "id", json_null(), stratum_send_diff(client);
"method", "mining.set_difficulty");
stratum_add_send(json_msg, client->id);
} }
/* FIXME Add logging of these as well */ /* FIXME Add logging of these as well */
@ -1312,8 +1318,18 @@ out:
json_object_set_nocheck(json_msg, "result", result_val); json_object_set_nocheck(json_msg, "result", result_val);
stratum_add_send(json_msg, client_id); stratum_add_send(json_msg, client_id);
if (update) if (update) {
stratum_instance_t *client;
stratum_send_update(client_id, true); 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) static void *stratum_receiver(void *arg)

Loading…
Cancel
Save