Browse Source

Add an optional field notify per btcd that tells ckpool not to pool for block changes

master
Con Kolivas 10 years ago
parent
commit
5c52cc65c7
  1. 4
      README
  2. 8
      ckpool.conf
  3. 21
      src/ckpool.c
  4. 2
      src/ckpool.h
  5. 17
      src/generator.c
  6. 4
      src/stratifier.c

4
README

@ -219,7 +219,9 @@ The options recognised are as follows:
"btcd" : This is an array of bitcoind(s) with the options url, auth and pass
which match the configured bitcoind. This is mandatory in pool mode.
which match the configured bitcoind. This is mandatory in pool mode. The
optional boolean field notify tells ckpool this btcd is using the notifier
and does not need to be polled for block changes.
"proxy" : This is an array in the same format as btcd above but is used in
proxy and passthrough mode to set the upstream pool and is mandatory.

8
ckpool.conf

@ -3,17 +3,19 @@
{
"url" : "localhost:8332",
"auth" : "user",
"pass" : "pass"
"pass" : "pass",
"notify" : true
},
{
"url" : "backup:8332",
"auth" : "user",
"pass" : "pass"
"pass" : "pass",
"notify" : false
}
],
"btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e",
"btcsig" : "/mined by ck/",
"blockpoll" : 5000,
"blockpoll" : 100,
"update_interval" : 30,
"serverurl" : "ckpool.org:3333",
"mindiff" : 1,

21
src/ckpool.c

@ -888,6 +888,21 @@ static void json_get_int(int *store, json_t *val, const char *res)
*store = json_integer_value(entry);
}
static void json_get_bool(bool *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_boolean(entry)) {
LOGWARNING("Json entry %s is not a boolean", res);
return;
}
*store = json_is_true(entry);
}
static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size)
{
json_t *val;
@ -897,11 +912,13 @@ static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size)
ckp->btcdurl = ckzalloc(sizeof(char *) * arr_size);
ckp->btcdauth = ckzalloc(sizeof(char *) * arr_size);
ckp->btcdpass = ckzalloc(sizeof(char *) * arr_size);
ckp->btcdnotify = ckzalloc(sizeof(bool *) * arr_size);
for (i = 0; i < arr_size; i++) {
val = json_array_get(arr_val, i);
json_get_string(&ckp->btcdurl[i], val, "url");
json_get_string(&ckp->btcdauth[i], val, "auth");
json_get_string(&ckp->btcdpass[i], val, "pass");
json_get_bool(&ckp->btcdnotify[i], val, "notify");
}
}
@ -1207,10 +1224,8 @@ int main(int argc, char **argv)
ckp.donaddress = "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e";
if (!ckp.btcaddress)
ckp.btcaddress = ckp.donaddress;
/* Default blockpoll is sanity check only when notifier is not used or
* fails */
if (!ckp.blockpoll)
ckp.blockpoll = 5000;
ckp.blockpoll = 100;
if (!ckp.update_interval)
ckp.update_interval = 30;
if (!ckp.mindiff)

2
src/ckpool.h

@ -71,6 +71,7 @@ struct server_instance {
char *url;
char *auth;
char *pass;
bool notify;
connsock_t cs;
void *data; // Private data
@ -143,6 +144,7 @@ struct ckpool_instance {
char **btcdurl;
char **btcdauth;
char **btcdpass;
bool *btcdnotify;
int blockpoll; // How frequently in ms to poll bitcoind for block updates
/* Difficulty settings */

17
src/generator.c

@ -299,10 +299,12 @@ retry:
clear_gbtbase(gbt);
}
} else if (cmdmatch(buf, "getbest")) {
if (!get_bestblockhash(cs, hash)) {
if (si->notify)
send_unix_msg(sockd, "notify");
else if (!get_bestblockhash(cs, hash)) {
LOGINFO("No best block hash support from %s:%s",
cs->url, cs->port);
send_unix_msg(sockd, "Failed");
send_unix_msg(sockd, "failed");
} else {
if (unlikely(!started)) {
started = true;
@ -311,15 +313,17 @@ retry:
send_unix_msg(sockd, hash);
}
} else if (cmdmatch(buf, "getlast")) {
int height = get_blockcount(cs);
int height;
if (height == -1) {
send_unix_msg(sockd, "Failed");
if (si->notify)
send_unix_msg(sockd, "notify");
else if ((height = get_blockcount(cs)) == -1) {
send_unix_msg(sockd, "failed");
goto reconnect;
} else {
LOGDEBUG("Height: %d", height);
if (!get_blockhash(cs, height, hash)) {
send_unix_msg(sockd, "Failed");
send_unix_msg(sockd, "failed");
goto reconnect;
} else {
if (unlikely(!started)) {
@ -1497,6 +1501,7 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi)
si->url = ckp->btcdurl[i];
si->auth = ckp->btcdauth[i];
si->pass = ckp->btcdpass[i];
si->notify = ckp->btcdnotify[i];
}
ret = gen_loop(pi);

4
src/stratifier.c

@ -1211,7 +1211,9 @@ static void *blockupdate(void *arg)
while (42) {
dealloc(buf);
buf = send_recv_generator(ckp, request, GEN_LAX);
if (buf && strcmp(buf, lastswaphash) && !cmdmatch(buf, "failed")) {
if (buf && cmdmatch(buf, "notify"))
cksleep_ms(5000);
else if (buf && strcmp(buf, lastswaphash) && !cmdmatch(buf, "failed")) {
LOGNOTICE("Block hash changed to %s", buf);
update_base(ckp, GEN_PRIORITY);
} else

Loading…
Cancel
Save