From 5d266a0faac0adc813e9d2998fb8bad71ba10b6c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 12:35:42 +1000 Subject: [PATCH 1/6] Use cmdmatch in connector and ckpool --- src/ckpool.c | 8 ++++---- src/connector.c | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 5b212564..9f9d333a 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -195,14 +195,14 @@ retry: if (!buf) { LOGWARNING("Failed to get message in listener"); send_unix_msg(sockd, "failed"); - } else if (!strncasecmp(buf, "shutdown", 8)) { + } else if (cmdmatch(buf, "shutdown")) { LOGWARNING("Listener received shutdown message, terminating ckpool"); send_unix_msg(sockd, "exiting"); goto out; - } else if (!strncasecmp(buf, "ping", 4)) { + } else if (cmdmatch(buf, "ping")) { LOGDEBUG("Listener received ping request"); send_unix_msg(sockd, "pong"); - } else if (!strncasecmp(buf, "loglevel", 8)) { + } else if (cmdmatch(buf, "loglevel")) { int loglevel; if (sscanf(buf, "loglevel=%d", &loglevel) != 1) { @@ -216,7 +216,7 @@ retry: broadcast_proc(ckp, buf); send_unix_msg(sockd, "success"); } - } else if (!strncasecmp(buf, "getfd", 5)) { + } else if (cmdmatch(buf, "getfd")) { char *msg; msg = send_recv_proc(ckp->connector, "getfd"); diff --git a/src/connector.c b/src/connector.c index 7ea47e6f..466cf5de 100644 --- a/src/connector.c +++ b/src/connector.c @@ -514,30 +514,30 @@ retry: LOGWARNING("Failed to get message in connector_loop"); goto retry; } - if (!strncasecmp(buf, "ping", 4)) { + if (cmdmatch(buf, "ping")) { LOGDEBUG("Connector received ping request"); send_unix_msg(sockd, "pong"); goto retry; } - if (!strncasecmp(buf, "accept", 6)) { + if (cmdmatch(buf, "accept")) { LOGDEBUG("Connector received accept signal"); ci->accept = true; goto retry; } - if (!strncasecmp(buf, "reject", 6)) { + if (cmdmatch(buf, "reject")) { LOGDEBUG("Connector received reject signal"); ci->accept = false; goto retry; } - if (!strncasecmp(buf, "loglevel", 8)) { + if (cmdmatch(buf, "loglevel")) { sscanf(buf, "loglevel=%d", &ckp->loglevel); goto retry; } LOGDEBUG("Connector received message: %s", buf); - if (!strncasecmp(buf, "shutdown", 8)) + if (cmdmatch(buf, "shutdown")) goto out; - if (!strncasecmp(buf, "dropclient", 10)) { + if (cmdmatch(buf, "dropclient")) { client_instance_t *client; int client_id; @@ -556,7 +556,7 @@ retry: LOGINFO("Connector dropped client id: %d", client_id); goto retry; } - if (!strncasecmp(buf, "getfd", 5)) { + if (cmdmatch(buf, "getfd")) { send_fd(ci->serverfd, sockd); goto retry; } From 973571c70c5a0f63ecf4e7edc060738c757c255a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 12:47:22 +1000 Subject: [PATCH 2/6] Only show queueing message to ckdb once and display resumed message --- src/stratifier.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index f3bd2b75..297f5f51 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2130,17 +2130,25 @@ out: static void ckdbq_process(ckpool_t *ckp, ckdb_msg_t *data) { + static bool failed = false; bool logged = false; char *buf = NULL; while (!buf) { buf = json_ckdb_call(ckp, ckdb_ids[data->idtype], data->val, logged); if (unlikely(!buf)) { - LOGWARNING("Failed to talk to ckdb, queueing messages"); + if (!failed) { + failed = true; + LOGWARNING("Failed to talk to ckdb, queueing messages"); + } sleep(5); } logged = true; } + if (failed) { + failed = false; + LOGWARNING("Successfully resumed talking to ckdb"); + } LOGINFO("Got %s ckdb response: %s", ckdb_ids[data->idtype], buf); free(buf); } From fd45d582d4570d3f5f0398b4c1a05a2e8acf1943 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 13:05:52 +1000 Subject: [PATCH 3/6] Add messages for when each process is ready --- src/connector.c | 5 +++++ src/generator.c | 17 ++++++++++++++++- src/stratifier.c | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/connector.c b/src/connector.c index 466cf5de..676f23dc 100644 --- a/src/connector.c +++ b/src/connector.c @@ -499,6 +499,9 @@ static int connector_loop(proc_instance_t *pi, conn_instance_t *ci) goto out; } } while (selret < 1); + + LOGWARNING("%s connector ready", ckp->name); + retry: close(sockd); sockd = accept(us->sockd, NULL, NULL); @@ -595,6 +598,8 @@ int connector(proc_instance_t *pi) const int on = 1; int tries = 0; + LOGWARNING("%s connector starting", ckp->name); + if (ckp->serverurl) { if (!extract_sockaddr(ckp->serverurl, &url, &port)) { LOGWARNING("Failed to extract server address from %s", ckp->serverurl); diff --git a/src/generator.c b/src/generator.c index 85f04c42..b0fc61c5 100644 --- a/src/generator.c +++ b/src/generator.c @@ -193,6 +193,7 @@ static int gen_loop(proc_instance_t *pi) server_instance_t *si = NULL; unixsock_t *us = &pi->us; ckpool_t *ckp = pi->ckp; + bool started = false; char *buf = NULL; connsock_t *cs; gbtbase_t *gbt; @@ -255,8 +256,13 @@ retry: LOGINFO("No best block hash support from %s:%s", cs->url, cs->port); send_unix_msg(sockd, "Failed"); - } else + } else { + if (unlikely(!started)) { + started = true; + LOGWARNING("%s generator ready", ckp->name); + } send_unix_msg(sockd, hash); + } } else if (cmdmatch(buf, "getlast")) { int height = get_blockcount(cs); @@ -269,6 +275,11 @@ retry: send_unix_msg(sockd, "Failed"); goto reconnect; } else { + if (unlikely(!started)) { + started = true; + LOGWARNING("%s generator ready", ckp->name); + } + send_unix_msg(sockd, hash); LOGDEBUG("Hash: %s", hash); } @@ -1330,6 +1341,8 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) proxi->cs = &si->cs; } + LOGWARNING("%s generator ready", ckp->name); + ret = proxy_loop(pi); for (i = 0; i < ckp->proxies; i++) { @@ -1358,6 +1371,8 @@ int generator(proc_instance_t *pi) ckpool_t *ckp = pi->ckp; int ret; + LOGWARNING("%s generator starting", ckp->name); + if (ckp->proxy) ret = proxy_mode(ckp, pi); else diff --git a/src/stratifier.c b/src/stratifier.c index 297f5f51..f5e889d0 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2434,6 +2434,8 @@ int stratifier(proc_instance_t *pi) char *buf; int ret; + LOGWARNING("%s stratifier starting", ckp->name); + /* Store this for use elsewhere */ hex2bin(scriptsig_header_bin, scriptsig_header, 41); address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress); @@ -2472,6 +2474,8 @@ int stratifier(proc_instance_t *pi) cklock_init(&share_lock); + LOGWARNING("%s stratifier ready", ckp->name); + ret = stratum_loop(ckp, pi); out: return process_exit(ckp, pi, ret); From 5fc1aa28a1ef6a59a4fc5dcce7b604a68008a7f1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 13:14:53 +1000 Subject: [PATCH 4/6] Add a throbber to the stratifier to show activity --- src/stratifier.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/stratifier.c b/src/stratifier.c index f5e889d0..e8a98cc7 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -413,9 +413,17 @@ static void purge_share_hashtable(int64_t wb_id) LOGINFO("Cleared %d shares from share hashtable", purged); } +static char *status_chars = "|/-\\"; + static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val) { + static int counter = 0; ckdb_msg_t *msg; + char ch; + + ch = status_chars[(counter++) & 0x3]; + fprintf(stdout, "%c\r", ch); + fflush(stdout); if (ckp->standalone) return json_decref(val); From eff11a1024f3e7affce1554646186c0a34095c9d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 15:50:55 +1000 Subject: [PATCH 5/6] Avoid trying to send a message to ckdb if it's invalid json and identify where it came from --- src/stratifier.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index e8a98cc7..14d7cb85 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -415,7 +415,8 @@ static void purge_share_hashtable(int64_t wb_id) static char *status_chars = "|/-\\"; -static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val) +static void _ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val, const char *file, + const char *func, const int line) { static int counter = 0; ckdb_msg_t *msg; @@ -425,6 +426,11 @@ static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val) fprintf(stdout, "%c\r", ch); fflush(stdout); + if (!val) { + LOGWARNING("Invalid json sent to ckdbq_add from %s %s:%d", file, func, line); + return; + } + if (ckp->standalone) return json_decref(val); @@ -434,6 +440,8 @@ static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val) ckmsgq_add(ckdbq, msg); } +#define ckdbq_add(ckp, idtype, val) _ckdbq_add(ckp, idtype, val, __FILE__, __func__, __LINE__) + static void send_workinfo(ckpool_t *ckp, workbase_t *wb) { char cdfield[64]; From d253a97e793f5d2391ec469b18f49d80939c322f Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Aug 2014 15:59:07 +1000 Subject: [PATCH 6/6] Fix null txn hashes being passed to ckdb in proxy mode --- src/stratifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stratifier.c b/src/stratifier.c index 14d7cb85..19074635 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -712,6 +712,7 @@ static void update_notify(ckpool_t *ckp) workpadding); LOGDEBUG("Header: %s", header); hex2bin(wb->headerbin, header, 112); + wb->txn_hashes = ckzalloc(1); ck_rlock(&workbase_lock); strcpy(wb->enonce1const, proxy_base.enonce1);