Browse Source

Make share logging optional and off by default

master
Con Kolivas 10 years ago
parent
commit
c4fae526fd
  1. 6
      src/ckpool.c
  2. 2
      src/ckpool.h
  3. 32
      src/stratifier.c

6
src/ckpool.c

@ -1015,6 +1015,7 @@ static struct option long_options[] = {
{"handover", no_argument, 0, 'H'}, {"handover", no_argument, 0, 'H'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"killold", no_argument, 0, 'k'}, {"killold", no_argument, 0, 'k'},
{"log-shares", no_argument, 0, 'L'},
{"loglevel", required_argument, 0, 'l'}, {"loglevel", required_argument, 0, 'l'},
{"name", required_argument, 0, 'n'}, {"name", required_argument, 0, 'n'},
{"passthrough", no_argument, 0, 'P'}, {"passthrough", no_argument, 0, 'P'},
@ -1042,7 +1043,7 @@ int main(int argc, char **argv)
ckp.initial_args[ckp.args] = strdup(argv[ckp.args]); ckp.initial_args[ckp.args] = strdup(argv[ckp.args]);
ckp.initial_args[ckp.args] = NULL; ckp.initial_args[ckp.args] = NULL;
while ((c = getopt_long(argc, argv, "Ac:d:g:Hhkl:n:PpS:s:", long_options, &i)) != -1) { while ((c = getopt_long(argc, argv, "Ac:d:g:HhkLl:n:PpS:s:", long_options, &i)) != -1) {
switch (c) { switch (c) {
case 'A': case 'A':
ckp.standalone = true; ckp.standalone = true;
@ -1080,6 +1081,9 @@ int main(int argc, char **argv)
case 'k': case 'k':
ckp.killold = true; ckp.killold = true;
break; break;
case 'L':
ckp.logshares = true;
break;
case 'l': case 'l':
ckp.loglevel = atoi(optarg); ckp.loglevel = atoi(optarg);
if (ckp.loglevel < LOG_EMERG || ckp.loglevel > LOG_DEBUG) { if (ckp.loglevel < LOG_EMERG || ckp.loglevel > LOG_DEBUG) {

2
src/ckpool.h

@ -87,6 +87,8 @@ struct ckpool_instance {
char *config; char *config;
/* Kill old instance with same name */ /* Kill old instance with same name */
bool killold; bool killold;
/* Whether to log shares or not */
bool logshares;
/* Logging level */ /* Logging level */
int loglevel; int loglevel;
/* Main process name */ /* Main process name */

32
src/stratifier.c

@ -530,14 +530,15 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
memcpy(lasthash, wb->prevhash, 65); memcpy(lasthash, wb->prevhash, 65);
blockchange_id = wb->id; blockchange_id = wb->id;
} }
if (*new_block) { if (*new_block && ckp->logshares) {
sprintf(wb->logdir, "%s%08x/", ckp->logdir, wb->height); sprintf(wb->logdir, "%s%08x/", ckp->logdir, wb->height);
ret = mkdir(wb->logdir, 0750); ret = mkdir(wb->logdir, 0750);
if (unlikely(ret && errno != EEXIST)) if (unlikely(ret && errno != EEXIST))
LOGERR("Failed to create log directory %s", wb->logdir); LOGERR("Failed to create log directory %s", wb->logdir);
} }
sprintf(wb->idstring, "%016lx", wb->id); sprintf(wb->idstring, "%016lx", wb->id);
sprintf(wb->logdir, "%s%08x/%s", ckp->logdir, wb->height, wb->idstring); if (ckp->logshares)
sprintf(wb->logdir, "%s%08x/%s", ckp->logdir, wb->height, wb->idstring);
HASH_ITER(hh, workbases, tmp, tmpa) { HASH_ITER(hh, workbases, tmp, tmpa) {
if (HASH_COUNT(workbases) < 3) if (HASH_COUNT(workbases) < 3)
@ -1680,9 +1681,9 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg,
char hexhash[68] = {}, sharehash[32], cdfield[64]; char hexhash[68] = {}, sharehash[32], cdfield[64];
enum share_err err = SE_NONE; enum share_err err = SE_NONE;
ckpool_t *ckp = client->ckp; ckpool_t *ckp = client->ckp;
char *fname = NULL, *s;
char idstring[20]; char idstring[20];
uint32_t ntime32; uint32_t ntime32;
char *fname, *s;
workbase_t *wb; workbase_t *wb;
uchar hash[32]; uchar hash[32];
int64_t id; int64_t id;
@ -1836,17 +1837,19 @@ out_unlock:
json_set_string(val, "workername", client->workername); json_set_string(val, "workername", client->workername);
json_set_string(val, "username", client->user_instance->username); json_set_string(val, "username", client->user_instance->username);
fp = fopen(fname, "a"); if (ckp->logshares) {
if (likely(fp)) { fp = fopen(fname, "a");
s = json_dumps(val, 0); if (likely(fp)) {
len = strlen(s); s = json_dumps(val, 0);
len = fprintf(fp, "%s\n", s); len = strlen(s);
free(s); len = fprintf(fp, "%s\n", s);
fclose(fp); free(s);
if (unlikely(len < 0)) fclose(fp);
LOGERR("Failed to fwrite to %s", fname); if (unlikely(len < 0))
} else LOGERR("Failed to fwrite to %s", fname);
LOGERR("Failed to fopen %s", fname); } else
LOGERR("Failed to fopen %s", fname);
}
ckdbq_add(ckp, ID_SHARES, val); ckdbq_add(ckp, ID_SHARES, val);
out: out:
if (!share) { if (!share) {
@ -1866,6 +1869,7 @@ out:
ckdbq_add(ckp, ID_SHAREERR, val); ckdbq_add(ckp, ID_SHAREERR, val);
LOGINFO("Invalid share from client %d: %s", client->id, client->workername); LOGINFO("Invalid share from client %d: %s", client->id, client->workername);
} }
free(fname);
return json_boolean(result); return json_boolean(result);
} }

Loading…
Cancel
Save