Browse Source

Merge branch 'master' of bitbucket.org:ckolivas/ckpool

master
Con Kolivas 8 years ago
parent
commit
38b20f2efb
  1. 2
      pool/page_addrmgt.php
  2. 4
      pool/page_settings.php
  3. 125
      src/ckdb.c
  4. 59
      src/ckdb.h
  5. 78
      src/ckdb.php
  6. 135
      src/ckdb_cmd.c
  7. 67
      src/ckdb_data.c
  8. 68
      src/ckdb_dbio.c
  9. 153
      src/cmd.sh
  10. 2
      src/klist.h

2
pool/page_addrmgt.php

@ -162,7 +162,7 @@ function doaddrmgt($data, $user)
$nam = ''; $nam = '';
$ratio = getparam('ratio:'.$i, false); $ratio = getparam('ratio:'.$i, false);
if (!nuem($addr) && !nuem($ratio)) if (!nuem($addr) && !nuem($ratio))
$addrarr[] = array('addr' => $addr, 'payname' => $nam, 'ratio' => $ratio); $addrarr[] = array('addr' => trim($addr), 'payname' => trim($nam), 'ratio' => $ratio);
} }
$ans = userSettings($user, null, $addrarr, $pass, $twofa); $ans = userSettings($user, null, $addrarr, $pass, $twofa);
if ($ans['STATUS'] != 'ok') if ($ans['STATUS'] != 'ok')

4
pool/page_settings.php

@ -149,7 +149,9 @@ function dosettings($data, $user)
else else
{ {
$addr = getparam('baddr', false); $addr = getparam('baddr', false);
$addrarr = array(array('addr' => $addr)); if (nuem($addr))
$addr = '';
$addrarr = array(array('addr' => trim($addr)));
$pass = getparam('pass', false); $pass = getparam('pass', false);
$twofa = getparam('2fa', false); $twofa = getparam('2fa', false);
$ans = userSettings($user, null, $addrarr, $pass, $twofa); $ans = userSettings($user, null, $addrarr, $pass, $twofa);

125
src/ckdb.c

@ -209,24 +209,22 @@ const char Transfer[] = "Transfer";
// older version missing field defaults // older version missing field defaults
// see end of alloc_storage() // see end of alloc_storage()
static TRANSFER auth_1 = { "poolinstance", "", NULL, NULL }; static TRANSFER auth_2 = { "preauth", FALSE_STR, auth_2.svalue, 0, NULL };
K_ITEM auth_poolinstance = { Transfer, NULL, NULL, (void *)(&auth_1) };
static TRANSFER auth_2 = { "preauth", FALSE_STR, auth_2.svalue, NULL };
K_ITEM auth_preauth = { Transfer, NULL, NULL, (void *)(&auth_2) }; K_ITEM auth_preauth = { Transfer, NULL, NULL, (void *)(&auth_2) };
static TRANSFER poolstats_1 = { "elapsed", "0", poolstats_1.svalue, NULL }; static TRANSFER poolstats_1 = { "elapsed", "0", poolstats_1.svalue, 0, NULL };
K_ITEM poolstats_elapsed = { Transfer, NULL, NULL, (void *)(&poolstats_1) }; K_ITEM poolstats_elapsed = { Transfer, NULL, NULL, (void *)(&poolstats_1) };
static TRANSFER userstats_1 = { "elapsed", "0", userstats_1.svalue, NULL }; static TRANSFER userstats_1 = { "elapsed", "0", userstats_1.svalue, 0, NULL };
K_ITEM userstats_elapsed = { Transfer, NULL, NULL, (void *)(&userstats_1) }; K_ITEM userstats_elapsed = { Transfer, NULL, NULL, (void *)(&userstats_1) };
// see end of alloc_storage() // see end of alloc_storage()
INTRANSIENT *userstats_workername = NULL; INTRANSIENT *userstats_workername = NULL;
static TRANSFER userstats_3 = { "idle", FALSE_STR, userstats_3.svalue, NULL }; static TRANSFER userstats_3 = { "idle", FALSE_STR, userstats_3.svalue, 0, NULL };
K_ITEM userstats_idle = { Transfer, NULL, NULL, (void *)(&userstats_3) }; K_ITEM userstats_idle = { Transfer, NULL, NULL, (void *)(&userstats_3) };
static TRANSFER userstats_4 = { "eos", TRUE_STR, userstats_4.svalue, NULL }; static TRANSFER userstats_4 = { "eos", TRUE_STR, userstats_4.svalue, 0, NULL };
K_ITEM userstats_eos = { Transfer, NULL, NULL, (void *)(&userstats_4) }; K_ITEM userstats_eos = { Transfer, NULL, NULL, (void *)(&userstats_4) };
static TRANSFER shares_1 = { "secondaryuserid", TRUE_STR, shares_1.svalue, NULL }; static TRANSFER shares_1 = { "secondaryuserid", TRUE_STR, shares_1.svalue, 0, NULL };
K_ITEM shares_secondaryuserid = { Transfer, NULL, NULL, (void *)(&shares_1) }; K_ITEM shares_secondaryuserid = { Transfer, NULL, NULL, (void *)(&shares_1) };
static TRANSFER shareerrors_1 = { "secondaryuserid", TRUE_STR, shareerrors_1.svalue, NULL }; static TRANSFER shareerrors_1 = { "secondaryuserid", TRUE_STR, shareerrors_1.svalue, 0, NULL };
K_ITEM shareerrors_secondaryuserid = { Transfer, NULL, NULL, (void *)(&shareerrors_1) }; K_ITEM shareerrors_secondaryuserid = { Transfer, NULL, NULL, (void *)(&shareerrors_1) };
// Time limit that this problem occurred // Time limit that this problem occurred
// 24-Aug-2014 05:20+00 (1st one shortly after this) // 24-Aug-2014 05:20+00 (1st one shortly after this)
@ -409,7 +407,7 @@ char *inet_default = "127.0.0.1";
char *id_default = "42"; char *id_default = "42";
// NULL or poolinstance must match // NULL or poolinstance must match
const char *poolinstance = NULL; const char *sys_poolinstance = NULL;
// lock for accessing all mismatch variables // lock for accessing all mismatch variables
cklock_t poolinstance_lock; cklock_t poolinstance_lock;
time_t last_mismatch_message; time_t last_mismatch_message;
@ -485,6 +483,8 @@ char *intransient_fields[] = {
NULL NULL
}; };
INTRANSIENT *in_empty;
// MSGLINE // MSGLINE
K_LIST *msgline_free; K_LIST *msgline_free;
K_STORE *msgline_store; K_STORE *msgline_store;
@ -2282,9 +2282,8 @@ static void alloc_storage()
check_deadlocks = true; check_deadlocks = true;
#endif #endif
// set intransient // setup intransients
auth_1.intransient = get_intransient(auth_1.name, ""); in_empty = get_intransient("empty", EMPTY);
auth_1.mvalue = auth_1.intransient->str;
userstats_workername = get_intransient("workername", "all"); userstats_workername = get_intransient("workername", "all");
} }
@ -3152,7 +3151,7 @@ static void msgs_seq(SEQFOUND *found_msgs)
* sequence code */ * sequence code */
static bool update_seq(enum seq_num seq, uint64_t n_seqcmd, static bool update_seq(enum seq_num seq, uint64_t n_seqcmd,
uint64_t n_seqstt, uint64_t n_seqpid, uint64_t n_seqstt, uint64_t n_seqpid,
char *nam, tv_t *now, tv_t *cd, char *code, char *nam, tv_t *now, tv_t *cd, INTRANSIENT *in_code,
int seqentryflags, char *msg) int seqentryflags, char *msg)
{ {
static SEQFOUND found[SEQ_MAX]; static SEQFOUND found[SEQ_MAX];
@ -3178,7 +3177,7 @@ static bool update_seq(enum seq_num seq, uint64_t n_seqcmd,
LOGDEBUG("%s() SQ %c:%d/%s/%"PRIu64"/%"PRIu64"/%"PRIu64"/%s '%.80s...", LOGDEBUG("%s() SQ %c:%d/%s/%"PRIu64"/%"PRIu64"/%"PRIu64"/%s '%.80s...",
__func__, SECHR(seqentryflags), seq, nam, n_seqcmd, n_seqstt, __func__, SECHR(seqentryflags), seq, nam, n_seqcmd, n_seqstt,
n_seqpid, code, st = safe_text(msg)); n_seqpid, in_code->str, st = safe_text(msg));
FREENULL(st); FREENULL(st);
firstseq = newseq = expseq = gothigh = okhi = gotstale = firstseq = newseq = expseq = gothigh = okhi = gotstale =
@ -3579,7 +3578,7 @@ setitemdata:
seqentry->flags = seqentryflags; seqentry->flags = seqentryflags;
copy_tv(&(seqentry->time), now); copy_tv(&(seqentry->time), now);
copy_tv(&(seqentry->cd), cd); copy_tv(&(seqentry->cd), cd);
STRNCPY(seqentry->code, code); seqentry->in_code = in_code->str;
seqdata->ok++; seqdata->ok++;
seqset->ok++; seqset->ok++;
} }
@ -3643,7 +3642,7 @@ setitemdata:
(level == LOG_DEBUG) ? "*" : EMPTY, (level == LOG_DEBUG) ? "*" : EMPTY,
SECHR(seqentryflags), SECHR(seqentry_copy.flags), SECHR(seqentryflags), SECHR(seqentry_copy.flags),
nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid, nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid,
t_buf2, code, t_buf2, in_code->str,
seqset_copy.seqdata[seq].minseq, seqset_copy.seqdata[seq].minseq,
seqset_copy.seqdata[seq].maxseq, seqset_copy.seqdata[seq].maxseq,
seqset_copy.seqdata[seq].missing, seqset_copy.seqdata[seq].missing,
@ -3742,7 +3741,7 @@ setitemdata:
LOGWARNING("SEQ recovered %s %"PRIu64" set:%d/%"PRIu64 LOGWARNING("SEQ recovered %s %"PRIu64" set:%d/%"PRIu64
"=%s/%"PRIu64" %s/%s", "=%s/%"PRIu64" %s/%s",
nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid, nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid,
t_buf2, code); t_buf2, in_code->str);
} }
if (gotstale || gotstalestart || gothigh) { if (gotstale || gotstalestart || gothigh) {
@ -3755,7 +3754,7 @@ setitemdata:
gothigh ? (okhi ? "OKHI" : "HIGH") : "stale", gothigh ? (okhi ? "OKHI" : "HIGH") : "stale",
gotstalestart ? "STARTUP " : EMPTY, gotstalestart ? "STARTUP " : EMPTY,
nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid, nam, n_seqcmd, set, n_seqstt, t_buf, n_seqpid,
t_buf2, code, t_buf2, in_code->str,
seqset_copy.seqdata[seq].minseq, seqset_copy.seqdata[seq].minseq,
seqset_copy.seqdata[seq].maxseq, seqset_copy.seqdata[seq].maxseq,
seqset_copy.seqdata[seq].missing, seqset_copy.seqdata[seq].missing,
@ -3827,7 +3826,7 @@ setitemdata:
seqnam[seq], range_buf, set, seqnam[seq], range_buf, set,
n_seqstt, t_buf, n_seqpid, n_seqstt, t_buf, n_seqpid,
isrange ? "last: " : EMPTY, isrange ? "last: " : EMPTY,
t_buf2, seqtrans->entry.code); t_buf2, seqtrans->entry.in_code);
} }
K_WLOCK(seqtrans_free); K_WLOCK(seqtrans_free);
k_list_transfer_to_head(lost, seqtrans_free); k_list_transfer_to_head(lost, seqtrans_free);
@ -3874,13 +3873,13 @@ static enum cmd_values process_seq(MSGLINE *msgline)
dupall = update_seq(SEQ_ALL, msgline->n_seqall, dupall = update_seq(SEQ_ALL, msgline->n_seqall,
msgline->n_seqstt, msgline->n_seqpid, msgline->n_seqstt, msgline->n_seqpid,
SEQALL, &(msgline->now), &(msgline->cd), SEQALL, &(msgline->now), &(msgline->cd),
msgline->code, msgline->seqentryflags, msgline->in_code, msgline->seqentryflags,
msgline->msg); msgline->msg);
} }
dupcmd = update_seq(ckdb_cmds[msgline->which_cmds].seq, dupcmd = update_seq(ckdb_cmds[msgline->which_cmds].seq,
msgline->n_seqcmd, msgline->n_seqstt, msgline->n_seqcmd, msgline->n_seqstt,
msgline->n_seqpid, msgline->seqcmdnam, msgline->n_seqpid, msgline->seqcmdnam,
&(msgline->now), &(msgline->cd), msgline->code, &(msgline->now), &(msgline->cd), msgline->in_code,
msgline->seqentryflags, msgline->msg); msgline->seqentryflags, msgline->msg);
if (ignore_seqall) if (ignore_seqall)
@ -3914,9 +3913,11 @@ static enum cmd_values process_seq(MSGLINE *msgline)
static void setup_seq(K_ITEM *seqall, MSGLINE *msgline) static void setup_seq(K_ITEM *seqall, MSGLINE *msgline)
{ {
K_ITEM *seqstt, *seqpid, *seqcmd, *i_code; K_ITEM *seqstt, *seqpid, *seqcmd;
char *err = NULL, *st = NULL; char *err = NULL, *st = NULL;
size_t len, off; size_t len, off;
char reply[16] = "";
size_t siz = sizeof(reply);
msgline->n_seqall = atol(transfer_data(seqall)); msgline->n_seqall = atol(transfer_data(seqall));
if ((seqstt = find_transfer(msgline->trf_root, SEQSTT))) if ((seqstt = find_transfer(msgline->trf_root, SEQSTT)))
@ -3985,16 +3986,13 @@ static void setup_seq(K_ITEM *seqall, MSGLINE *msgline)
msgline->hasseq = true; msgline->hasseq = true;
if ((i_code = find_transfer(msgline->trf_root, CODETRF))) { msgline->in_code = optional_in(msgline->trf_root, CODETRF, 1, NULL,
msgline->code = transfer_data(i_code); reply, siz);
if (!(*(msgline->code))) if (!(msgline->in_code)) {
msgline->code = NULL; msgline->in_code = optional_in(msgline->trf_root, BYTRF,
} 0, NULL, reply, siz);
if (!(msgline->code)) { if (!msgline->in_code)
if ((i_code = find_transfer(msgline->trf_root, BYTRF))) msgline->in_code = in_empty;
msgline->code = transfer_data(i_code);
else
msgline->code = EMPTY;
} }
} }
@ -4009,11 +4007,14 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
char *cmdptr, *idptr, *next, *eq, *end, *was; char *cmdptr, *idptr, *next, *eq, *end, *was;
char *data = NULL, *st = NULL, *st2 = NULL, *ip = NULL; char *data = NULL, *st = NULL, *st2 = NULL, *ip = NULL;
bool noid = false, intrans; bool noid = false, intrans;
uint64_t ram2 = 0;
size_t siz; size_t siz;
int i; int i;
siz = strlen(buf)+1;
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
*ml_item = k_unlink_head_zero(msgline_free); *ml_item = k_unlink_head_zero(msgline_free);
msgline_free->ram += siz;
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
DATA_MSGLINE(msgline, *ml_item); DATA_MSGLINE(msgline, *ml_item);
msgline->which_cmds = CMD_UNSET; msgline->which_cmds = CMD_UNSET;
@ -4023,6 +4024,7 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
DATE_ZERO(&(msgline->broken)); DATE_ZERO(&(msgline->broken));
DATE_ZERO(&(msgline->processed)); DATE_ZERO(&(msgline->processed));
msgline->msg = strdup(buf); msgline->msg = strdup(buf);
msgline->msgsiz = siz;
msgline->seqentryflags = seqentryflags; msgline->seqentryflags = seqentryflags;
cmdptr = strdup(buf); cmdptr = strdup(buf);
@ -4058,7 +4060,7 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
* you can ignore the access failed items by skipping items * you can ignore the access failed items by skipping items
* that start with a capital, since all (currently) are lower case * that start with a capital, since all (currently) are lower case
* however, command checks are case insensitive, so replaying * however, command checks are case insensitive, so replaying
* the file will allow these commands, if they are present */ * the file will try these commands, if they are present */
if ((ckdb_cmds[msgline->which_cmds].access & access) == 0) if ((ckdb_cmds[msgline->which_cmds].access & access) == 0)
buf[0] = toupper(buf[0]); buf[0] = toupper(buf[0]);
@ -4135,7 +4137,7 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
// LOGERR of buf could be truncated // LOGERR of buf could be truncated
*(end++) = '\0'; *(end++) = '\0';
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
t_item = k_unlink_head(transfer_free); t_item = k_unlink_head_zero(transfer_free);
K_WUNLOCK(transfer_free); K_WUNLOCK(transfer_free);
DATA_TRANSFER(transfer, t_item); DATA_TRANSFER(transfer, t_item);
STRNCPY(transfer->name, next); STRNCPY(transfer->name, next);
@ -4248,6 +4250,8 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
if (!intrans) { if (!intrans) {
transfer->intransient = NULL; transfer->intransient = NULL;
if (siz >= sizeof(transfer->svalue)) { if (siz >= sizeof(transfer->svalue)) {
transfer->msiz = siz+1;
ram2 += siz+1;
transfer->mvalue = malloc(siz+1); transfer->mvalue = malloc(siz+1);
STRNCPYSIZ(transfer->mvalue, next, STRNCPYSIZ(transfer->mvalue, next,
siz+1); siz+1);
@ -4293,7 +4297,7 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
*(eq++) = '\0'; *(eq++) = '\0';
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
t_item = k_unlink_head(transfer_free); t_item = k_unlink_head_zero(transfer_free);
K_WUNLOCK(transfer_free); K_WUNLOCK(transfer_free);
DATA_TRANSFER(transfer, t_item); DATA_TRANSFER(transfer, t_item);
STRNCPY(transfer->name, data); STRNCPY(transfer->name, data);
@ -4313,6 +4317,8 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
if (!intrans) { if (!intrans) {
transfer->intransient = NULL; transfer->intransient = NULL;
if (siz > sizeof(transfer->svalue)) { if (siz > sizeof(transfer->svalue)) {
ram2 += siz;
transfer->msiz = siz;
transfer->mvalue = malloc(siz); transfer->mvalue = malloc(siz);
STRNCPYSIZ(transfer->mvalue, eq, siz); STRNCPYSIZ(transfer->mvalue, eq, siz);
} else { } else {
@ -4323,8 +4329,9 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
// Discard duplicates // Discard duplicates
if (find_in_ktree_nolock(msgline->trf_root, t_item, ctx)) { if (find_in_ktree_nolock(msgline->trf_root, t_item, ctx)) {
if (transfer->mvalue != transfer->svalue) if (transfer->msiz)
FREENULL(transfer->mvalue); ram2 -= transfer->msiz;
free_transfer_data(transfer);
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
k_add_head(transfer_free, t_item); k_add_head(transfer_free, t_item);
K_WUNLOCK(transfer_free); K_WUNLOCK(transfer_free);
@ -4334,9 +4341,17 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
add_to_ktree_nolock(msgline->trf_root, t_item); add_to_ktree_nolock(msgline->trf_root, t_item);
k_add_head_nolock(msgline->trf_store, t_item); k_add_head_nolock(msgline->trf_store, t_item);
} }
t_item = NULL;
} }
} }
if (ram2) {
K_WLOCK(transfer_free);
transfer_free->ram += ram2;
K_WUNLOCK(transfer_free);
ram2 = 0;
}
seqall = find_transfer(msgline->trf_root, SEQALL); seqall = find_transfer(msgline->trf_root, SEQALL);
if (ckdb_cmds[msgline->which_cmds].createdate) { if (ckdb_cmds[msgline->which_cmds].createdate) {
cd_item = require_name(msgline->trf_root, CDTRF, 10, NULL, cd_item = require_name(msgline->trf_root, CDTRF, 10, NULL,
@ -4396,9 +4411,17 @@ static enum cmd_values breakdown(K_ITEM **ml_item, char *buf, tv_t *now,
return ckdb_cmds[msgline->which_cmds].cmd_val; return ckdb_cmds[msgline->which_cmds].cmd_val;
nogood: nogood:
if (t_item) { if (t_item || ram2) {
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
if (t_item) {
DATA_TRANSFER(transfer, t_item);
if (transfer->msiz)
ram2 -= transfer->msiz;
free_transfer_data(transfer);
k_add_head(transfer_free, t_item); k_add_head(transfer_free, t_item);
}
if (ram2)
transfer_free->ram += ram2;
K_WUNLOCK(transfer_free); K_WUNLOCK(transfer_free);
} }
free(cmdptr); free(cmdptr);
@ -4981,7 +5004,7 @@ static void summarise_blocks()
"/%"PRId64"/%s/%s crosses block " "/%"PRId64"/%s/%s crosses block "
"%"PRId32"/%"PRId64" boundary", "%"PRId32"/%"PRId64" boundary",
__func__, workmarkers->markerid, __func__, workmarkers->markerid,
workmarkers->poolinstance, workmarkers->in_poolinstance,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->workinfoidend, workmarkers->workinfoidend,
workmarkers->description, workmarkers->description,
@ -6014,6 +6037,7 @@ static void process_sockd(PGconn *conn, K_ITEM *wq_item, enum reply_type reply_t
free_msgline_data(ml_item, true, true); free_msgline_data(ml_item, true, true);
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
msgline_free->ram -= msgline->msgsiz;
k_add_head(msgline_free, ml_item); k_add_head(msgline_free, ml_item);
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
@ -6587,8 +6611,11 @@ static void *process_socket(__maybe_unused void *arg)
WORKQUEUE *wq; WORKQUEUE *wq;
DATA_WORKQUEUE(wq, wq2_item); DATA_WORKQUEUE(wq, wq2_item);
K_ITEM *ml_item = wq->msgline_item; K_ITEM *ml_item = wq->msgline_item;
MSGLINE *ml;
DATA_MSGLINE(ml, ml_item);
free_msgline_data(ml_item, true, false); free_msgline_data(ml_item, true, false);
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
msgline_free->ram -= ml->msgsiz;
k_add_head(msgline_free, ml_item); k_add_head(msgline_free, ml_item);
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
K_WLOCK(workqueue_free); K_WLOCK(workqueue_free);
@ -6627,8 +6654,11 @@ skippy:
dec_sockd = false; dec_sockd = false;
if (bq->ml_item) { if (bq->ml_item) {
MSGLINE *ml;
DATA_MSGLINE(ml, bq->ml_item);
free_msgline_data(bq->ml_item, true, true); free_msgline_data(bq->ml_item, true, true);
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
msgline_free->ram -= ml->msgsiz;
k_add_head(msgline_free, bq->ml_item); k_add_head(msgline_free, bq->ml_item);
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
bq->ml_item = NULL; bq->ml_item = NULL;
@ -6639,6 +6669,7 @@ skippy:
if (dec_sockd) if (dec_sockd)
sockd_count--; sockd_count--;
cmd_processing--; cmd_processing--;
breakqueue_free->ram -= bq->bufsiz;
k_add_head(breakqueue_free, bq_item); k_add_head(breakqueue_free, bq_item);
K_WUNLOCK(breakqueue_free); K_WUNLOCK(breakqueue_free);
} }
@ -6772,6 +6803,7 @@ static void *sockrun(void *arg)
K_WUNLOCK(breakqueue_free); K_WUNLOCK(breakqueue_free);
DATA_BREAKQUEUE(bq, bq_item); DATA_BREAKQUEUE(bq, bq_item);
bq->buf = buf; bq->buf = buf;
bq->bufsiz = strlen(buf)+1;
bq->source = (char *)(this->gdata); bq->source = (char *)(this->gdata);
bq->access = *(int *)(this->cdata); bq->access = *(int *)(this->cdata);
copy_tv(&(bq->accepted), &nowacc); copy_tv(&(bq->accepted), &nowacc);
@ -6782,6 +6814,7 @@ static void *sockrun(void *arg)
if (max_sockd_count < ++sockd_count) if (max_sockd_count < ++sockd_count)
max_sockd_count = sockd_count; max_sockd_count = sockd_count;
k_add_tail(cmd_breakqueue_store, bq_item); k_add_tail(cmd_breakqueue_store, bq_item);
breakqueue_free->ram += bq->bufsiz;
K_WUNLOCK(breakqueue_free); K_WUNLOCK(breakqueue_free);
setnow(&now2); setnow(&now2);
sock_lock_br_us[thissock] += us_tvdiff(&now2, &now1); sock_lock_br_us[thissock] += us_tvdiff(&now2, &now1);
@ -6976,8 +7009,10 @@ static void process_reload_item(PGconn *conn, K_ITEM *bq_item)
} }
if (bq->ml_item) { if (bq->ml_item) {
DATA_MSGLINE(msgline, bq->ml_item);
free_msgline_data(bq->ml_item, true, true); free_msgline_data(bq->ml_item, true, true);
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
msgline_free->ram -= msgline->msgsiz;
k_add_head(msgline_free, bq->ml_item); k_add_head(msgline_free, bq->ml_item);
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
bq->ml_item = NULL; bq->ml_item = NULL;
@ -6993,6 +7028,7 @@ static void *process_reload(__maybe_unused void *arg)
PGconn *conn = NULL; PGconn *conn = NULL;
K_ITEM *bq_item = NULL; K_ITEM *bq_item = NULL;
BREAKQUEUE *bq;
char buf[128]; char buf[128];
time_t now; time_t now;
ts_t when, when_add; ts_t when, when_add;
@ -7137,8 +7173,10 @@ static void *process_reload(__maybe_unused void *arg)
process_reload_item(conn, bq_item); process_reload_item(conn, bq_item);
DATA_BREAKQUEUE(bq, bq_item);
K_WLOCK(breakqueue_free); K_WLOCK(breakqueue_free);
reload_processing--; reload_processing--;
breakqueue_free->ram -= bq->bufsiz;
k_add_head(breakqueue_free, bq_item); k_add_head(breakqueue_free, bq_item);
K_WUNLOCK(breakqueue_free); K_WUNLOCK(breakqueue_free);
@ -7214,6 +7252,7 @@ static void reload_line(char *filename, char *buf, uint64_t count)
// release the lock since strdup could be slow, but rarely // release the lock since strdup could be slow, but rarely
DATA_BREAKQUEUE(bq, bq_item); DATA_BREAKQUEUE(bq, bq_item);
bq->buf = strdup(buf); bq->buf = strdup(buf);
bq->bufsiz = strlen(buf)+1;
// reloads are normally all pool data but access can be changed // reloads are normally all pool data but access can be changed
bq->source = (char *)ispool; bq->source = (char *)ispool;
bq->access = reload_access; bq->access = reload_access;
@ -7227,6 +7266,7 @@ static void reload_line(char *filename, char *buf, uint64_t count)
K_WLOCK(breakqueue_free); K_WLOCK(breakqueue_free);
k_add_tail(reload_breakqueue_store, bq_item); k_add_tail(reload_breakqueue_store, bq_item);
qcount = reload_breakqueue_store->count; qcount = reload_breakqueue_store->count;
breakqueue_free->ram += bq->bufsiz;
K_WUNLOCK(breakqueue_free); K_WUNLOCK(breakqueue_free);
mutex_lock(&bq_reload_waitlock); mutex_lock(&bq_reload_waitlock);
@ -7611,6 +7651,7 @@ static void process_queued(PGconn *conn, K_ITEM *wq_item)
free_msgline_data(ml_item, true, true); free_msgline_data(ml_item, true, true);
K_WLOCK(msgline_free); K_WLOCK(msgline_free);
msgline_free->ram -= msgline->msgsiz;
k_add_head(msgline_free, ml_item); k_add_head(msgline_free, ml_item);
K_WUNLOCK(msgline_free); K_WUNLOCK(msgline_free);
@ -8062,7 +8103,7 @@ static bool make_keysummaries()
LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/" LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/"
"Stt %"PRId64"/%s/%s", "Stt %"PRId64"/%s/%s",
__func__, workmarkers->markerid, workmarkers->poolinstance, __func__, workmarkers->markerid, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->workinfoidend, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->status); workmarkers->description, workmarkers->status);
@ -9133,7 +9174,7 @@ int main(int argc, char **argv)
* to have poolinstance set to the given -i value * to have poolinstance set to the given -i value
* since they will be blank */ * since they will be blank */
case 'i': case 'i':
poolinstance = (const char *)strdup(optarg); sys_poolinstance = (const char *)strdup(optarg);
break; break;
case 'I': case 'I':
ignore_seq = true; ignore_seq = true;

59
src/ckdb.h

@ -58,7 +58,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.7" #define DB_VERSION "1.0.7"
#define CKDB_VERSION DB_VERSION"-2.503" #define CKDB_VERSION DB_VERSION"-2.508"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -639,7 +639,7 @@ extern char *id_default;
} while (0) } while (0)
// NULL or poolinstance must match // NULL or poolinstance must match
extern const char *poolinstance; extern const char *sys_poolinstance;
// lock for accessing all mismatch variables // lock for accessing all mismatch variables
extern cklock_t poolinstance_lock; extern cklock_t poolinstance_lock;
extern time_t last_mismatch_message; extern time_t last_mismatch_message;
@ -1335,6 +1335,7 @@ extern K_LIST *intransient_free;
extern K_STORE *intransient_store; extern K_STORE *intransient_store;
extern char *intransient_fields[]; extern char *intransient_fields[];
extern INTRANSIENT *in_empty;
// MSGLINE // MSGLINE
typedef struct msgline { typedef struct msgline {
@ -1348,6 +1349,7 @@ typedef struct msgline {
char id[ID_SIZ+1]; char id[ID_SIZ+1];
char cmd[CMD_SIZ+1]; char cmd[CMD_SIZ+1];
char *msg; char *msg;
size_t msgsiz;
bool hasseq; bool hasseq;
char *seqcmdnam; char *seqcmdnam;
uint64_t n_seqall; uint64_t n_seqall;
@ -1355,7 +1357,7 @@ typedef struct msgline {
uint64_t n_seqstt; uint64_t n_seqstt;
uint64_t n_seqpid; uint64_t n_seqpid;
int seqentryflags; int seqentryflags;
char *code; INTRANSIENT *in_code;
K_TREE *trf_root; K_TREE *trf_root;
K_STORE *trf_store; K_STORE *trf_store;
int sockd; int sockd;
@ -1374,6 +1376,7 @@ extern K_STORE *msgline_store;
// BREAKQUEUE // BREAKQUEUE
typedef struct breakqueue { typedef struct breakqueue {
char *buf; char *buf;
size_t bufsiz;
char *source; char *source;
int access; int access;
tv_t accepted; // socket accepted or line read tv_t accepted; // socket accepted or line read
@ -1548,6 +1551,7 @@ typedef struct transfer {
char name[NAME_SIZE+1]; char name[NAME_SIZE+1];
char svalue[VALUE_SIZE+1]; char svalue[VALUE_SIZE+1];
char *mvalue; char *mvalue;
size_t msiz;
INTRANSIENT *intransient; INTRANSIENT *intransient;
} TRANSFER; } TRANSFER;
@ -1564,7 +1568,6 @@ extern K_LIST *transfer_free;
extern const char Transfer[]; extern const char Transfer[];
extern K_ITEM auth_poolinstance;
extern K_ITEM auth_preauth; extern K_ITEM auth_preauth;
extern K_ITEM poolstats_elapsed; extern K_ITEM poolstats_elapsed;
extern K_ITEM userstats_elapsed; extern K_ITEM userstats_elapsed;
@ -1680,9 +1683,6 @@ enum seq_num {
SEQ_MAX SEQ_MAX
}; };
// Ensure size is a (multiple of 8)-1
#define SEQ_CODE 15
#define SECHR(_sif) (((_sif) == SE_EARLYSOCK) ? 'E' : \ #define SECHR(_sif) (((_sif) == SE_EARLYSOCK) ? 'E' : \
(((_sif) == SE_RELOAD) ? 'R' : \ (((_sif) == SE_RELOAD) ? 'R' : \
(((_sif) == SE_SOCKET) ? 'S' : '?'))) (((_sif) == SE_SOCKET) ? 'S' : '?')))
@ -1698,7 +1698,7 @@ typedef struct seqentry {
int flags; int flags;
tv_t cd; // sec:0=missing, usec:0=miss !0=trans tv_t cd; // sec:0=missing, usec:0=miss !0=trans
tv_t time; tv_t time;
char code[SEQ_CODE+1]; char *in_code;
} SEQENTRY; } SEQENTRY;
typedef struct seqdata { typedef struct seqdata {
@ -2683,7 +2683,7 @@ extern int o_limits_max_lifetime;
// AUTHS authorise.id.json={...} // AUTHS authorise.id.json={...}
typedef struct auths { typedef struct auths {
int64_t authid; int64_t authid;
char poolinstance[TXT_BIG+1]; char *in_poolinstance;
int64_t userid; int64_t userid;
char *in_workername; char *in_workername;
int32_t clientid; int32_t clientid;
@ -2708,7 +2708,7 @@ extern K_STORE *auths_store;
#define STATS_PER (9.5*60.0) #define STATS_PER (9.5*60.0)
typedef struct poolstats { typedef struct poolstats {
char poolinstance[TXT_BIG+1]; char *in_poolinstance;
int64_t elapsed; int64_t elapsed;
int32_t users; int32_t users;
int32_t workers; int32_t workers;
@ -2739,7 +2739,7 @@ extern K_STORE *poolstats_store;
* Most of the #defines for USERSTATS are no longer needed * Most of the #defines for USERSTATS are no longer needed
* but are left here for now for historical reference */ * but are left here for now for historical reference */
typedef struct userstats { typedef struct userstats {
char poolinstance[TXT_BIG+1]; char *in_poolinstance;
int64_t userid; int64_t userid;
char *in_workername; char *in_workername;
int64_t elapsed; int64_t elapsed;
@ -3017,7 +3017,7 @@ extern K_STORE *keysummary_store;
// WORKMARKERS // WORKMARKERS
typedef struct workmarkers { typedef struct workmarkers {
int64_t markerid; int64_t markerid;
char *poolinstance; char *in_poolinstance;
int64_t workinfoidend; int64_t workinfoidend;
int64_t workinfoidstart; int64_t workinfoidstart;
char *description; char *description;
@ -3048,7 +3048,7 @@ extern K_STORE *workmarkers_store;
// MARKS // MARKS
typedef struct marks { typedef struct marks {
char *poolinstance; char *in_poolinstance;
int64_t workinfoid; int64_t workinfoid;
char *description; char *description;
char *extra; char *extra;
@ -3218,6 +3218,7 @@ extern void sequence_report(bool lock);
// Data free functions (first) // Data free functions (first)
#define FREE_ITEM(item) do { } while(0) #define FREE_ITEM(item) do { } while(0)
// TODO: make a macro for all other to use above macro // TODO: make a macro for all other to use above macro
extern void free_transfer_data(TRANSFER *transfer);
extern void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull); extern void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull);
extern void free_users_data(K_ITEM *item); extern void free_users_data(K_ITEM *item);
extern void free_workinfo_data(K_ITEM *item); extern void free_workinfo_data(K_ITEM *item);
@ -3319,8 +3320,8 @@ extern cmp_t cmp_intransient(K_ITEM *a, K_ITEM *b);
_get_intransient(_fld, _val, 0, WHERE_FFL_HERE) _get_intransient(_fld, _val, 0, WHERE_FFL_HERE)
#define get_intransient_siz(_fld, _val, _siz) \ #define get_intransient_siz(_fld, _val, _siz) \
_get_intransient(_fld, _val , _siz, WHERE_FFL_HERE) _get_intransient(_fld, _val , _siz, WHERE_FFL_HERE)
extern INTRANSIENT *_get_intransient(char *fldnam, char *value, size_t siz, extern INTRANSIENT *_get_intransient(const char *fldnam, char *value,
WHERE_FFL_ARGS); size_t siz, WHERE_FFL_ARGS);
#define intransient_str(_fld, _val) \ #define intransient_str(_fld, _val) \
_intransient_str(_fld, _val, WHERE_FFL_HERE) _intransient_str(_fld, _val, WHERE_FFL_HERE)
extern char *_intransient_str(char *fldnam, char *value, WHERE_FFL_ARGS); extern char *_intransient_str(char *fldnam, char *value, WHERE_FFL_ARGS);
@ -3444,9 +3445,9 @@ extern K_ITEM *_find_workinfo(int64_t workinfoid, bool gotlock, K_TREE_CTX *ctx)
extern K_ITEM *next_workinfo(int64_t workinfoid, K_TREE_CTX *ctx); extern K_ITEM *next_workinfo(int64_t workinfoid, K_TREE_CTX *ctx);
extern K_ITEM *find_workinfo_esm(int64_t workinfoid, bool error, bool *created, extern K_ITEM *find_workinfo_esm(int64_t workinfoid, bool error, bool *created,
tv_t *createdate); tv_t *createdate);
extern bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, extern bool workinfo_age(int64_t workinfoid, INTRANSIENT *in_poolinstance,
tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, tv_t *cd, tv_t *ss_first, tv_t *ss_last,
int64_t *s_count, int64_t *s_diff); int64_t *ss_count, int64_t *s_count, int64_t *s_diff);
extern double coinbase_reward(int32_t height); extern double coinbase_reward(int32_t height);
extern double workinfo_pps(K_ITEM *w_item, int64_t workinfoid); extern double workinfo_pps(K_ITEM *w_item, int64_t workinfoid);
extern cmp_t cmp_shares(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_shares(K_ITEM *a, K_ITEM *b);
@ -3467,7 +3468,8 @@ extern void zero_sharesummary(SHARESUMMARY *row);
extern K_ITEM *_find_sharesummary(int64_t userid, char *workername, extern K_ITEM *_find_sharesummary(int64_t userid, char *workername,
int64_t workinfoid, bool pool); int64_t workinfoid, bool pool);
extern K_ITEM *find_last_sharesummary(int64_t userid, char *workername); extern K_ITEM *find_last_sharesummary(int64_t userid, char *workername);
extern void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd); extern void auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance,
tv_t *cd);
#define dbhash2btchash(_hash, _buf, _siz) \ #define dbhash2btchash(_hash, _buf, _siz) \
_dbhash2btchash(_hash, _buf, _siz, WHERE_FFL_HERE) _dbhash2btchash(_hash, _buf, _siz, WHERE_FFL_HERE)
void _dbhash2btchash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS); void _dbhash2btchash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS);
@ -3755,13 +3757,14 @@ extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root)
#define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root) #define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root)
extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root); extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root);
#define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root) #define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root)
extern bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, extern bool auths_add(PGconn *conn, INTRANSIENT *in_poolinstance,
INTRANSIENT *in_workername, char *clientid, INTRANSIENT *in_username, INTRANSIENT *in_workername,
char *enonce1, char *useragent, char *preauth, char *by, char *clientid, char *enonce1, char *useragent,
char *code, char *inet, tv_t *cd, K_TREE *trf_root, char *preauth, char *by, char *code, char *inet,
bool addressuser, USERS **users, WORKERS **workers, tv_t *cd, K_TREE *trf_root, bool addressuser,
int *event, bool reload_data); USERS **users, WORKERS **workers, int *event,
extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, bool reload_data);
extern bool poolstats_add(PGconn *conn, bool store, INTRANSIENT *in_poolinstance,
char *elapsed, char *users, char *workers, char *elapsed, char *users, char *workers,
char *hashrate, char *hashrate5m, char *hashrate, char *hashrate5m,
char *hashrate1hr, char *hashrate24hr, char *hashrate1hr, char *hashrate24hr,
@ -3769,12 +3772,12 @@ extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance,
bool igndup, K_TREE *trf_root); bool igndup, K_TREE *trf_root);
extern bool poolstats_fill(PGconn *conn); extern bool poolstats_fill(PGconn *conn);
extern bool userstats_add_db(PGconn *conn, USERSTATS *row); extern bool userstats_add_db(PGconn *conn, USERSTATS *row);
extern bool userstats_add(char *poolinstance, char *elapsed, char *username, extern bool userstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username,
INTRANSIENT *in_workername, char *hashrate, INTRANSIENT *in_workername, char *hashrate,
char *hashrate5m, char *hashrate1hr, char *hashrate5m, char *hashrate1hr,
char *hashrate24hr, bool idle, bool eos, char *by, char *hashrate24hr, bool idle, bool eos, char *by,
char *code, char *inet, tv_t *cd, K_TREE *trf_root); char *code, char *inet, tv_t *cd, K_TREE *trf_root);
extern bool workerstats_add(char *poolinstance, char *elapsed, char *username, extern bool workerstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username,
INTRANSIENT *in_workername, char *hashrate, INTRANSIENT *in_workername, char *hashrate,
char *hashrate5m, char *hashrate1hr, char *hashrate5m, char *hashrate1hr,
char *hashrate24hr, bool idle, char *instances, char *hashrate24hr, bool idle, char *instances,

78
src/ckdb.php

@ -0,0 +1,78 @@
<?php
#
global $socket_name_def, $socket_dir_def, $socket_file_def;
global $socket_name, $socket_dir, $socket_file;
#
$socket_name_def = 'ckdb';
$socket_dir_def = '/opt/';
$socket_file_def = 'listenercmd';
#
$socket_name = $socket_name_def;
$socket_dir = $socket_dir_def;
$socket_file = $socket_file_def;
#
include_once('../pool/socket.php');
#
function getsock2($fun, $tmo)
{
global $socket_name, $socket_dir, $socket_file;
return _getsock($fun, "$socket_dir$socket_name/$socket_file", $tmo);
}
#
function msg($line, $tmo = false)
{
global $fld_sep, $val_sep;
$fun = 'stdin';
$ret = false;
$socket = getsock2($fun, $tmo);
if ($socket !== false)
{
$ret = dosend($fun, $socket, $line);
if ($ret !== false)
$ret = readsockline($fun, $socket);
socket_close($socket);
}
return $ret;
}
#
function usAge($a0)
{
global $socket_name_def, $socket_dir_def, $socket_file_def;
echo "usAge: php $a0 [name [dir [socket]]]\n";
echo " default name = $socket_name_def\n";
echo " default dir = $socket_dir_def\n";
echo " default socket = $socket_file_def\n";
echo " i.e. $socket_dir_def$socket_name_def/$socket_file_def\n";
exit(1);
}
#
if (count($argv) > 1)
{
if ($argv[1] == '-?' || $argv[1] == '-h' || $argv[1] == '-help'
|| $argv[1] == '--help')
usAge($argv[0]);
$socket_name = $argv[1];
if (count($argv) > 2)
{
$socket_dir = $argv[2];
if (count($argv) > 3)
$socket_file = $argv[3];
}
}
#
while ($line = fgets(STDIN))
{
$line = trim($line);
if (strlen($line) > 0)
{
$rep = msg($line);
if ($rep === false)
echo "Failed\n";
else
echo "$rep\n";
}
}
?>

135
src/ckdb_cmd.c

@ -992,20 +992,21 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by,
// log to logfile // log to logfile
K_ITEM *i_poolinstance, *i_elapsed, *i_users, *i_workers; K_ITEM *i_elapsed, *i_users, *i_workers;
K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr;
INTRANSIENT *in_poolinstance;
K_ITEM look, *ps; K_ITEM look, *ps;
POOLSTATS row, *poolstats; POOLSTATS row, *poolstats;
bool ok = false; bool ok = false;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance) if (!in_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(poolstats, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(poolstats, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
@ -1037,7 +1038,7 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by,
if (!i_hashrate24hr) if (!i_hashrate24hr)
return strdup(reply); return strdup(reply);
STRNCPY(row.poolinstance, transfer_data(i_poolinstance)); row.in_poolinstance = in_poolinstance->str;
row.createdate.tv_sec = date_eot.tv_sec; row.createdate.tv_sec = date_eot.tv_sec;
row.createdate.tv_usec = date_eot.tv_usec; row.createdate.tv_usec = date_eot.tv_usec;
INIT_POOLSTATS(&look); INIT_POOLSTATS(&look);
@ -1051,21 +1052,21 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by,
DATA_POOLSTATS(poolstats, ps); DATA_POOLSTATS(poolstats, ps);
// Find last stored matching the poolinstance and less than STATS_PER old // Find last stored matching the poolinstance and less than STATS_PER old
while (ps && !poolstats->stored && while (ps && !poolstats->stored &&
strcmp(row.poolinstance, poolstats->poolinstance) == 0 && INTREQ(row.in_poolinstance, poolstats->in_poolinstance) &&
tvdiff(cd, &(poolstats->createdate)) < STATS_PER) { tvdiff(cd, &(poolstats->createdate)) < STATS_PER) {
ps = prev_in_ktree(ctx); ps = prev_in_ktree(ctx);
DATA_POOLSTATS_NULL(poolstats, ps); DATA_POOLSTATS_NULL(poolstats, ps);
} }
if (!ps || !poolstats->stored || if (!ps || !poolstats->stored ||
strcmp(row.poolinstance, poolstats->poolinstance) != 0 || !INTREQ(row.in_poolinstance, poolstats->in_poolinstance) ||
tvdiff(cd, &(poolstats->createdate)) >= STATS_PER) tvdiff(cd, &(poolstats->createdate)) >= STATS_PER)
store = true; store = true;
else else
store = false; store = false;
} }
ok = poolstats_add(conn, store, transfer_data(i_poolinstance), ok = poolstats_add(conn, store, in_poolinstance,
transfer_data(i_elapsed), transfer_data(i_elapsed),
transfer_data(i_users), transfer_data(i_users),
transfer_data(i_workers), transfer_data(i_workers),
@ -1111,20 +1112,21 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id,
// log to logfile // log to logfile
K_ITEM *i_poolinstance, *i_elapsed, *i_username; K_ITEM *i_elapsed, *i_username;
K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr;
INTRANSIENT *in_poolinstance;
K_ITEM *i_eos, *i_idle; K_ITEM *i_eos, *i_idle;
INTRANSIENT *in_workername; INTRANSIENT *in_workername;
bool ok = false, idle, eos; bool ok = false, idle, eos;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance) if (!in_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(userstats, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(userstats, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
@ -1168,7 +1170,7 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id,
eos = (strcasecmp(transfer_data(i_eos), TRUE_STR) == 0); eos = (strcasecmp(transfer_data(i_eos), TRUE_STR) == 0);
ok = userstats_add(transfer_data(i_poolinstance), ok = userstats_add(in_poolinstance,
transfer_data(i_elapsed), transfer_data(i_elapsed),
transfer_data(i_username), transfer_data(i_username),
in_workername, in_workername,
@ -1197,20 +1199,21 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id,
// log to logfile // log to logfile
K_ITEM *i_poolinstance, *i_elapsed, *i_username; K_ITEM *i_elapsed, *i_username;
K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr;
INTRANSIENT *in_poolinstance;
K_ITEM *i_idle, *i_instances; K_ITEM *i_idle, *i_instances;
INTRANSIENT *in_workername; INTRANSIENT *in_workername;
bool ok = false, idle; bool ok = false, idle;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance) if (!in_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(workerstats, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(workerstats, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
@ -1250,7 +1253,7 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id,
i_instances = optional_name(trf_root, "instances", 1, NULL, reply, siz); i_instances = optional_name(trf_root, "instances", 1, NULL, reply, siz);
ok = workerstats_add(transfer_data(i_poolinstance), ok = workerstats_add(in_poolinstance,
transfer_data(i_elapsed), transfer_data(i_elapsed),
transfer_data(i_username), transfer_data(i_username),
in_workername, in_workername,
@ -2550,7 +2553,7 @@ static char *cmd_sharelog(PGconn *conn, char *cmd, char *id,
if (!in_poolinstance) if (!in_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, in_poolinstance->str)){ if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)){
POOLINSTANCE_DATA_SET(workinfo, in_poolinstance->str); POOLINSTANCE_DATA_SET(workinfo, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
@ -2843,17 +2846,18 @@ seconf:
snprintf(reply, siz, "ok.added %s", transfer_data(i_username)); snprintf(reply, siz, "ok.added %s", transfer_data(i_username));
return strdup(reply); return strdup(reply);
} else if (strcasecmp(cmd, STR_AGEWORKINFO) == 0) { } else if (strcasecmp(cmd, STR_AGEWORKINFO) == 0) {
K_ITEM *i_workinfoid, *i_poolinstance; K_ITEM *i_workinfoid;
INTRANSIENT *in_poolinstance;
int64_t ss_count, s_count, s_diff; int64_t ss_count, s_count, s_diff;
tv_t ss_first, ss_last; tv_t ss_first, ss_last;
bool ok; bool ok;
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance) if (!in_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(ageworkinfo, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(ageworkinfo, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
@ -2880,9 +2884,8 @@ seconf:
goto awconf; goto awconf;
} }
ok = workinfo_age(workinfoid, transfer_data(i_poolinstance), ok = workinfo_age(workinfoid, in_poolinstance, cd, &ss_first,
cd, &ss_first, &ss_last, &ss_count, &s_count, &ss_last, &ss_count, &s_count, &s_diff);
&s_diff);
if (!ok) { if (!ok) {
LOGERR("%s(%s) %s.failed.DATA", __func__, cmd, id); LOGERR("%s(%s) %s.failed.DATA", __func__, cmd, id);
return strdup("failed.DATA"); return strdup("failed.DATA");
@ -2893,8 +2896,7 @@ seconf:
* unaged workinfos and thus would stop marker() */ * unaged workinfos and thus would stop marker() */
if (!reloading || key_update || reloaded_N_files) { if (!reloading || key_update || reloaded_N_files) {
// Aging is a queued item thus the reply is ignored // Aging is a queued item thus the reply is ignored
auto_age_older(workinfoid, auto_age_older(workinfoid, in_poolinstance, cd);
transfer_data(i_poolinstance), cd);
} }
} }
LOGDEBUG("%s.ok.aged %"PRId64, id, workinfoid); LOGDEBUG("%s.ok.aged %"PRId64, id, workinfoid);
@ -3047,15 +3049,13 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd,
K_TREE *trf_root, bool reload_data) K_TREE *trf_root, bool reload_data)
{ {
K_ITEM tmp_poolinstance_item;
TRANSFER tmp_poolinstance;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
char reply[1024] = ""; char reply[1024] = "";
size_t siz = sizeof(reply); size_t siz = sizeof(reply);
int event = EVENT_OK; int event = EVENT_OK;
K_ITEM *i_poolinstance, *i_clientid; K_ITEM *i_clientid;
K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item;
INTRANSIENT *in_username, *in_workername; INTRANSIENT *in_poolinstance, *in_username, *in_workername;
USERS *users = NULL; USERS *users = NULL;
WORKERS *workers = NULL; WORKERS *workers = NULL;
OPTIONCONTROL *optioncontrol; OPTIONCONTROL *optioncontrol;
@ -3065,23 +3065,17 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, in_poolinstance = optional_in(trf_root, "poolinstance", 1, NULL,
reply, siz); reply, siz);
if (!i_poolinstance) { if (!in_poolinstance) {
if (poolinstance) { if (sys_poolinstance) {
STRNCPY(tmp_poolinstance.name, "poolinstance"); in_poolinstance = get_intransient("poolinstance",
STRNCPY(tmp_poolinstance.svalue, poolinstance); (char *)sys_poolinstance);
tmp_poolinstance.mvalue = tmp_poolinstance.svalue;
tmp_poolinstance_item.name = Transfer;
tmp_poolinstance_item.prev = NULL;
tmp_poolinstance_item.next = NULL;
tmp_poolinstance_item.data = (void *)(&tmp_poolinstance);
i_poolinstance = &tmp_poolinstance_item;
} else } else
i_poolinstance = &auth_poolinstance; in_poolinstance = in_empty;
} else { } else {
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(auth, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(auth, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
} }
@ -3130,7 +3124,7 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
} }
if (ok) { if (ok) {
ok = auths_add(conn, transfer_data(i_poolinstance), ok = auths_add(conn, in_poolinstance,
in_username, in_workername, in_username, in_workername,
transfer_data(i_clientid), transfer_data(i_clientid),
transfer_data(i_enonce1), transfer_data(i_enonce1),
@ -3203,15 +3197,13 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd,
K_TREE *trf_root, bool reload_data) K_TREE *trf_root, bool reload_data)
{ {
K_ITEM tmp_poolinstance_item;
TRANSFER tmp_poolinstance;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
char reply[1024] = ""; char reply[1024] = "";
size_t siz = sizeof(reply); size_t siz = sizeof(reply);
int event = EVENT_OK; int event = EVENT_OK;
K_ITEM *i_poolinstance, *i_clientid; K_ITEM *i_clientid;
K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item;
INTRANSIENT *in_username, *in_workername; INTRANSIENT *in_poolinstance, *in_username, *in_workername;
USERS *users = NULL; USERS *users = NULL;
WORKERS *workers = NULL; WORKERS *workers = NULL;
size_t len, off; size_t len, off;
@ -3220,23 +3212,17 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, in_poolinstance = optional_in(trf_root, "poolinstance", 1, NULL,
reply, siz); reply, siz);
if (!i_poolinstance) { if (!in_poolinstance) {
if (poolinstance) { if (sys_poolinstance) {
STRNCPY(tmp_poolinstance.name, "poolinstance"); in_poolinstance = get_intransient("poolinstance",
STRNCPY(tmp_poolinstance.svalue, poolinstance); (char *)sys_poolinstance);
tmp_poolinstance.mvalue = tmp_poolinstance.svalue;
tmp_poolinstance_item.name = Transfer;
tmp_poolinstance_item.prev = NULL;
tmp_poolinstance_item.next = NULL;
tmp_poolinstance_item.data = (void *)(&tmp_poolinstance);
i_poolinstance = &tmp_poolinstance_item;
} else } else
i_poolinstance = &auth_poolinstance; in_poolinstance = in_empty;
} else { } else {
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) {
POOLINSTANCE_DATA_SET(addrauth, transfer_data(i_poolinstance)); POOLINSTANCE_DATA_SET(addrauth, in_poolinstance->str);
return strdup(FAILED_PI); return strdup(FAILED_PI);
} }
} }
@ -3265,8 +3251,7 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
if (!i_preauth) if (!i_preauth)
return strdup(reply); return strdup(reply);
ok = auths_add(conn, transfer_data(i_poolinstance), ok = auths_add(conn, in_poolinstance, in_username, in_workername,
in_username, in_workername,
transfer_data(i_clientid), transfer_data(i_clientid),
transfer_data(i_enonce1), transfer_data(i_enonce1),
transfer_data(i_useragent), transfer_data(i_useragent),
@ -6311,7 +6296,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
action = "status-unchanged"; action = "status-unchanged";
ok = true; ok = true;
} else { } else {
ok = marks_process(conn, true, marks->poolinstance, ok = marks_process(conn, true, marks->in_poolinstance,
workinfoid, marks->description, workinfoid, marks->description,
marks->extra, marks->marktype, marks->extra, marks->marktype,
status, by, code, inet, cd, status, by, code, inet, cd,
@ -6350,7 +6335,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
action = "extra-unchanged"; action = "extra-unchanged";
ok = true; ok = true;
} else { } else {
ok = marks_process(conn, true, marks->poolinstance, ok = marks_process(conn, true, marks->in_poolinstance,
workinfoid, marks->description, workinfoid, marks->description,
extra, marks->marktype, extra, marks->marktype,
status, by, code, inet, cd, status, by, code, inet, cd,
@ -6449,7 +6434,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
return strdup(reply); return strdup(reply);
} }
ok = workmarkers_process(NULL, false, true, markerid, ok = workmarkers_process(NULL, false, true, markerid,
workmarkers->poolinstance, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidend,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->description,
@ -6482,7 +6467,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
return strdup(reply); return strdup(reply);
} }
ok = workmarkers_process(NULL, false, true, markerid, ok = workmarkers_process(NULL, false, true, markerid,
workmarkers->poolinstance, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidend,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->description,

67
src/ckdb_data.c

@ -12,11 +12,18 @@
// Data free functions (added here as needed) // Data free functions (added here as needed)
void free_transfer_data(TRANSFER *transfer)
{
if (transfer->msiz)
FREENULL(transfer->mvalue);
}
void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull) void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull)
{ {
K_ITEM *t_item = NULL; K_ITEM *t_item = NULL;
TRANSFER *transfer; TRANSFER *transfer;
MSGLINE *msgline; MSGLINE *msgline;
uint64_t ram2 = 0;
DATA_MSGLINE(msgline, item); DATA_MSGLINE(msgline, item);
if (msgline->trf_root) if (msgline->trf_root)
@ -25,17 +32,13 @@ void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull)
t_item = STORE_HEAD_NOLOCK(msgline->trf_store); t_item = STORE_HEAD_NOLOCK(msgline->trf_store);
while (t_item) { while (t_item) {
DATA_TRANSFER(transfer, t_item); DATA_TRANSFER(transfer, t_item);
if (transfer->mvalue != transfer->svalue) { ram2 += transfer->msiz;
if (transfer->intransient) { free_transfer_data(transfer);
transfer->intransient = NULL;
transfer->mvalue = NULL;
} else
FREENULL(transfer->mvalue);
}
t_item = t_item->next; t_item = t_item->next;
} }
if (t_lock) if (t_lock)
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
transfer_free->ram -= ram2;
k_list_transfer_to_head(msgline->trf_store, transfer_free); k_list_transfer_to_head(msgline->trf_store, transfer_free);
if (t_cull) { if (t_cull) {
if (transfer_free->count == transfer_free->total && if (transfer_free->count == transfer_free->total &&
@ -123,8 +126,6 @@ void free_workmarkers_data(K_ITEM *item)
WORKMARKERS *workmarkers; WORKMARKERS *workmarkers;
DATA_WORKMARKERS(workmarkers, item); DATA_WORKMARKERS(workmarkers, item);
LIST_MEM_SUB(workmarkers_free, workmarkers->poolinstance);
FREENULL(workmarkers->poolinstance);
LIST_MEM_SUB(workmarkers_free, workmarkers->description); LIST_MEM_SUB(workmarkers_free, workmarkers->description);
FREENULL(workmarkers->description); FREENULL(workmarkers->description);
} }
@ -134,8 +135,6 @@ void free_marks_data(K_ITEM *item)
MARKS *marks; MARKS *marks;
DATA_MARKS(marks, item); DATA_MARKS(marks, item);
LIST_MEM_SUB(marks_free, marks->poolinstance);
FREENULL(marks->poolinstance);
LIST_MEM_SUB(marks_free, marks->description); LIST_MEM_SUB(marks_free, marks->description);
FREENULL(marks->description); FREENULL(marks->description);
LIST_MEM_SUB(marks_free, marks->extra); LIST_MEM_SUB(marks_free, marks->extra);
@ -731,7 +730,8 @@ cmp_t cmp_intransient(K_ITEM *a, K_ITEM *b)
return CMP_STR(ia->str, ib->str); return CMP_STR(ia->str, ib->str);
} }
INTRANSIENT *_get_intransient(char *fldnam, char *value, size_t siz, WHERE_FFL_ARGS) INTRANSIENT *_get_intransient(const char *fldnam, char *value, size_t siz,
WHERE_FFL_ARGS)
{ {
INTRANSIENT intransient, *in = NULL; INTRANSIENT intransient, *in = NULL;
K_ITEM look, *i_item, *n_item; K_ITEM look, *i_item, *n_item;
@ -856,9 +856,8 @@ void dsp_transfer(K_ITEM *item, FILE *stream)
fprintf(stream, "%s() called with (null) item\n", __func__); fprintf(stream, "%s() called with (null) item\n", __func__);
else { else {
DATA_TRANSFER(t, item); DATA_TRANSFER(t, item);
fprintf(stream, " name='%s' mvalue='%s' malloc=%c\n", fprintf(stream, " name='%s' mvalue='%s' malloc=%"PRIu64"\n",
t->name, t->mvalue, t->name, t->mvalue, t->msiz);
(t->svalue == t->mvalue) ? 'N' : 'Y');
} }
} }
@ -1206,7 +1205,8 @@ K_ITEM *_find_create_workerstatus(bool gotlock, bool alertcreate,
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
row->userid = userid; row->userid = userid;
row->in_workername = workername; row->in_workername = intransient_str("workername",
workername);
add_to_ktree(workerstatus_root, ws_item); add_to_ktree(workerstatus_root, ws_item);
k_add_head(workerstatus_store, ws_item); k_add_head(workerstatus_store, ws_item);
@ -2662,7 +2662,7 @@ static void discard_shares(int64_t *shares_tot, int64_t *shares_dumped,
#endif #endif
// Duplicates during a reload are set to not show messages // Duplicates during a reload are set to not show messages
bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, bool workinfo_age(int64_t workinfoid, INTRANSIENT *in_poolinstance, tv_t *cd,
tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, tv_t *ss_first, tv_t *ss_last, int64_t *ss_count,
int64_t *s_count, int64_t *s_diff) int64_t *s_count, int64_t *s_diff)
{ {
@ -2689,18 +2689,18 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd,
if (!wi_item) { if (!wi_item) {
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s no workinfo! Age discarded!", LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s no workinfo! Age discarded!",
__func__, workinfoid, poolinstance, __func__, workinfoid, in_poolinstance->str,
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
goto bye; goto bye;
} }
DATA_WORKINFO(workinfo, wi_item); DATA_WORKINFO(workinfo, wi_item);
if (strcmp(poolinstance, workinfo->in_poolinstance) != 0) { if (!INTREQ(in_poolinstance->str, workinfo->in_poolinstance)) {
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s Poolinstance changed " LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s Poolinstance changed "
// "(from %s)! Age discarded!", // "(from %s)! Age discarded!",
"(from %s)! Age not discarded", "(from %s)! Age not discarded",
__func__, workinfoid, poolinstance, __func__, workinfoid, in_poolinstance->str,
cd->tv_sec, cd->tv_usec, cd_buf, cd->tv_sec, cd->tv_usec, cd_buf,
workinfo->in_poolinstance); workinfo->in_poolinstance);
// TODO: ckdb only supports one, so until multiple support is written: // TODO: ckdb only supports one, so until multiple support is written:
@ -2715,7 +2715,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd,
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s attempt to age a " LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s attempt to age a "
"workmarker! Age ignored!", "workmarker! Age ignored!",
__func__, workinfoid, poolinstance, __func__, workinfoid, in_poolinstance->str,
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
goto bye; goto bye;
} }
@ -2808,8 +2808,8 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd,
"/%s sstotal=%"PRId64" already=%"PRId64 "/%s sstotal=%"PRId64" already=%"PRId64
" failed=%"PRId64", sharestotal=%"PRId64 " failed=%"PRId64", sharestotal=%"PRId64
" dumped=%"PRId64", diff=%"PRId64, " dumped=%"PRId64", diff=%"PRId64,
__func__, workinfoid, poolinstance, ss_tot, __func__, workinfoid, in_poolinstance->str,
ss_already, ss_failed, shares_tot, ss_tot, ss_already, ss_failed, shares_tot,
shares_dumped, diff_tot); shares_dumped, diff_tot);
} }
} }
@ -2888,7 +2888,7 @@ skip_ss:
if (ks_already) { if (ks_already) {
LOGNOTICE("%s(): Keysummary aging of %"PRId64"/%s " LOGNOTICE("%s(): Keysummary aging of %"PRId64"/%s "
"kstotal=%"PRId64" already=%"PRId64" failed=%"PRId64, "kstotal=%"PRId64" already=%"PRId64" failed=%"PRId64,
__func__, workinfoid, poolinstance, __func__, workinfoid, in_poolinstance->str,
ks_tot, ks_already, ks_failed); ks_tot, ks_already, ks_failed);
} }
@ -3119,7 +3119,8 @@ K_ITEM *find_last_sharesummary(int64_t userid, char *workername)
} }
// key_update must age keysharesummary directly // key_update must age keysharesummary directly
static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) static void key_auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance,
tv_t *cd)
{ {
static int64_t last_attempted_id = -1; static int64_t last_attempted_id = -1;
static int64_t prev_found = 0; static int64_t prev_found = 0;
@ -3194,7 +3195,7 @@ static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd)
do_id = age_id; do_id = age_id;
to_id = 0; to_id = 0;
do { do {
ok = workinfo_age(do_id, poolinstance, cd, &kss_first, ok = workinfo_age(do_id, in_poolinstance, cd, &kss_first,
&kss_last, &kss_count, &s_count, &kss_last, &kss_count, &s_count,
&s_diff); &s_diff);
@ -3275,7 +3276,7 @@ static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd)
/* TODO: markersummary checking? /* TODO: markersummary checking?
* However, there should be no issues since the sharesummaries are removed */ * However, there should be no issues since the sharesummaries are removed */
void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) void auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance, tv_t *cd)
{ {
static int64_t last_attempted_id = -1; static int64_t last_attempted_id = -1;
static int64_t prev_found = 0; static int64_t prev_found = 0;
@ -3294,7 +3295,7 @@ void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd)
bool ok, found; bool ok, found;
if (key_update) { if (key_update) {
key_auto_age_older(workinfoid, poolinstance, cd); key_auto_age_older(workinfoid, in_poolinstance, cd);
return; return;
} }
@ -3359,7 +3360,7 @@ void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd)
do_id = age_id; do_id = age_id;
to_id = 0; to_id = 0;
do { do {
ok = workinfo_age(do_id, poolinstance, cd, &ss_first, ok = workinfo_age(do_id, in_poolinstance, cd, &ss_first,
&ss_last, &ss_count, &s_count, &ss_last, &ss_count, &s_count,
&s_diff); &s_diff);
@ -6175,7 +6176,7 @@ cmp_t cmp_poolstats(K_ITEM *a, K_ITEM *b)
POOLSTATS *pa, *pb; POOLSTATS *pa, *pb;
DATA_POOLSTATS(pa, a); DATA_POOLSTATS(pa, a);
DATA_POOLSTATS(pb, b); DATA_POOLSTATS(pb, b);
cmp_t c = CMP_STR(pa->poolinstance, pb->poolinstance); cmp_t c = CMP_STR(pa->in_poolinstance, pb->in_poolinstance);
if (c == 0) if (c == 0)
c = CMP_TV(pa->createdate, pb->createdate); c = CMP_TV(pa->createdate, pb->createdate);
return c; return c;
@ -6194,7 +6195,7 @@ void dsp_userstats(K_ITEM *item, FILE *stream)
tv_to_buf(&(u->createdate), createdate_buf, sizeof(createdate_buf)); tv_to_buf(&(u->createdate), createdate_buf, sizeof(createdate_buf));
fprintf(stream, " pi='%s' uid=%"PRId64" w='%s' e=%"PRId64" Hs=%f " fprintf(stream, " pi='%s' uid=%"PRId64" w='%s' e=%"PRId64" Hs=%f "
"Hs5m=%f Hs1hr=%f Hs24hr=%f sl=%s sc=%d sd=%s cd=%s\n", "Hs5m=%f Hs1hr=%f Hs24hr=%f sl=%s sc=%d sd=%s cd=%s\n",
u->poolinstance, u->userid, u->in_workername, u->in_poolinstance, u->userid, u->in_workername,
u->elapsed, u->hashrate, u->hashrate5m, u->elapsed, u->hashrate, u->hashrate5m,
u->hashrate1hr, u->hashrate24hr, u->summarylevel, u->hashrate1hr, u->hashrate24hr, u->summarylevel,
u->summarycount, statsdate_buf, createdate_buf); u->summarycount, statsdate_buf, createdate_buf);
@ -6403,7 +6404,7 @@ bool make_markersummaries(bool msg, char *by, char *code, char *inet,
LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/" LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/"
"Stt %"PRId64"/%s/%s", "Stt %"PRId64"/%s/%s",
__func__, workmarkers->markerid, workmarkers->poolinstance, __func__, workmarkers->markerid, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->workinfoidend, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->status); workmarkers->description, workmarkers->status);
@ -6516,7 +6517,7 @@ void dsp_workmarkers(K_ITEM *item, FILE *stream)
DATA_WORKMARKERS(wm, item); DATA_WORKMARKERS(wm, item);
fprintf(stream, " id=%"PRId64" pi='%s' end=%"PRId64" stt=%" fprintf(stream, " id=%"PRId64" pi='%s' end=%"PRId64" stt=%"
PRId64" sta='%s' des='%s'\n", PRId64" sta='%s' des='%s'\n",
wm->markerid, wm->poolinstance, wm->markerid, wm->in_poolinstance,
wm->workinfoidend, wm->workinfoidstart, wm->workinfoidend, wm->workinfoidstart,
wm->status, wm->description); wm->status, wm->description);
} }

68
src/ckdb_dbio.c

@ -1480,7 +1480,6 @@ bool useratts_fill(PGconn *conn)
return ok; return ok;
} }
// WARNING: workername must be intransient
K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws, K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws,
char *difficultydefault, char *idlenotificationenabled, char *difficultydefault, char *idlenotificationenabled,
char *idlenotificationtime, char *by, char *code, char *idlenotificationtime, char *by, char *code,
@ -1530,7 +1529,7 @@ K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws,
goto unitem; goto unitem;
row->userid = userid; row->userid = userid;
row->in_workername = workername; row->in_workername = intransient_str("workername", workername);
if (difficultydefault && *difficultydefault) { if (difficultydefault && *difficultydefault) {
diffdef = atoi(difficultydefault); diffdef = atoi(difficultydefault);
// If out of the range, set it in the range // If out of the range, set it in the range
@ -3275,7 +3274,8 @@ int64_t workinfo_add(PGconn *conn, char *workinfoidstr,
if (!igndup) { if (!igndup) {
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s(): Duplicate workinfo ignored %s/%s/%s", LOGERR("%s(): Duplicate workinfo ignored %s/%s/%s",
__func__, workinfoidstr, poolinstance, cd_buf); __func__, workinfoidstr, in_poolinstance->str,
cd_buf);
} }
return workinfoid; return workinfoid;
@ -3480,7 +3480,7 @@ bool workinfo_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) { if (sys_poolinstance && strcmp(field, sys_poolinstance)) {
k_add_head(workinfo_free, item); k_add_head(workinfo_free, item);
POOLINSTANCE_DBLOAD_SET(workinfo, field); POOLINSTANCE_DBLOAD_SET(workinfo, field);
continue; continue;
@ -4745,7 +4745,7 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers,
LOGWARNING("%s() Processing: workmarkers %"PRId64"/%s/" LOGWARNING("%s() Processing: workmarkers %"PRId64"/%s/"
"End %"PRId64"/Stt %"PRId64"/%s/%s", "End %"PRId64"/Stt %"PRId64"/%s/%s",
shortname, workmarkers->markerid, workmarkers->poolinstance, shortname, workmarkers->markerid, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->workinfoidend, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->status); workmarkers->description, workmarkers->status);
@ -5077,7 +5077,7 @@ dokey:
if (!key_update) { if (!key_update) {
ok = workmarkers_process(conn, true, true, ok = workmarkers_process(conn, true, true,
workmarkers->markerid, workmarkers->markerid,
workmarkers->poolinstance, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidend,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->description,
@ -5256,7 +5256,7 @@ flail:
shareacc, diffacc, shareacc, diffacc,
kshareacc >> 1, (kshareacc & 1) ? ".5" : "", kshareacc >> 1, (kshareacc & 1) ? ".5" : "",
kdiffacc >> 1, (kdiffacc & 1) ? ".5" : "", kdiffacc >> 1, (kdiffacc & 1) ? ".5" : "",
workmarkers->markerid, workmarkers->poolinstance, workmarkers->markerid, workmarkers->in_poolinstance,
workmarkers->workinfoidend, workmarkers->workinfoidend,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->description, workmarkers->description,
@ -5311,7 +5311,7 @@ bool delete_markersummaries(PGconn *conn, WORKMARKERS *wm)
LOGWARNING("%s() Deleting: markersummaries for workmarkers " LOGWARNING("%s() Deleting: markersummaries for workmarkers "
"%"PRId64"/%s/End %"PRId64"/Stt %"PRId64"/%s/%s", "%"PRId64"/%s/End %"PRId64"/Stt %"PRId64"/%s/%s",
shortname, wm->markerid, wm->poolinstance, shortname, wm->markerid, wm->in_poolinstance,
wm->workinfoidend, wm->workinfoidstart, wm->description, wm->workinfoidend, wm->workinfoidstart, wm->description,
wm->status); wm->status);
@ -5432,7 +5432,7 @@ flail:
"%"PRId64" diff for workmarkers %"PRId64"/%s/" "%"PRId64" diff for workmarkers %"PRId64"/%s/"
"End %"PRId64"/Stt %"PRId64"/%s/%s", "End %"PRId64"/Stt %"PRId64"/%s/%s",
shortname, ms_count, shareacc, diffacc, shortname, ms_count, shareacc, diffacc,
wm->markerid, wm->poolinstance, wm->workinfoidend, wm->markerid, wm->in_poolinstance, wm->workinfoidend,
wm->workinfoidstart, wm->description, wm->status); wm->workinfoidstart, wm->description, wm->status);
} }
@ -5651,6 +5651,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, tv_t *cd,
DATA_SHARESUMMARY(row, ss_item); DATA_SHARESUMMARY(row, ss_item);
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
row->userid = userid; row->userid = userid;
// workername is intransient
row->in_workername = workername; row->in_workername = workername;
row->workinfoid = workinfoid; row->workinfoid = workinfoid;
} }
@ -6051,6 +6052,7 @@ bool blocks_add(PGconn *conn, int32_t height, char *blockhash,
STRNCPY(row->confirmed, confirmed); STRNCPY(row->confirmed, confirmed);
STRNCPY(row->info, info); STRNCPY(row->info, info);
TXT_TO_BIGINT("workinfoid", workinfoid, row->workinfoid); TXT_TO_BIGINT("workinfoid", workinfoid, row->workinfoid);
// workername is intransient or EMPTY
row->in_workername = workername; row->in_workername = workername;
TXT_TO_INT("clientid", clientid, row->clientid); TXT_TO_INT("clientid", clientid, row->clientid);
STRNCPY(row->enonce1, enonce1); STRNCPY(row->enonce1, enonce1);
@ -7783,10 +7785,10 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des,
} }
// TODO: discard them from RAM // TODO: discard them from RAM
bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, bool auths_add(PGconn *conn, INTRANSIENT *in_poolinstance,
INTRANSIENT *in_workername, char *clientid, char *enonce1, INTRANSIENT *in_username, INTRANSIENT *in_workername,
char *useragent, char *preauth, char *by, char *code, char *clientid, char *enonce1, char *useragent, char *preauth,
char *inet, tv_t *cd, K_TREE *trf_root, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root,
bool addressuser, USERS **users, WORKERS **workers, bool addressuser, USERS **users, WORKERS **workers,
int *event, bool reload_data) int *event, bool reload_data)
{ {
@ -7831,7 +7833,7 @@ bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username,
if ((*users)->status[0]) if ((*users)->status[0])
goto unitem; goto unitem;
STRNCPY(row->poolinstance, poolinstance); row->in_poolinstance = in_poolinstance->str;
row->userid = (*users)->userid; row->userid = (*users)->userid;
// since update=false, a dup will be ok and do nothing when igndup=true // since update=false, a dup will be ok and do nothing when igndup=true
w_item = new_worker(conn, false, row->userid, in_workername->str, w_item = new_worker(conn, false, row->userid, in_workername->str,
@ -7860,7 +7862,7 @@ bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username,
// Shouldn't actually be possible unless twice in the logs // Shouldn't actually be possible unless twice in the logs
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s(): Duplicate auths ignored %s/%s/%s", LOGERR("%s(): Duplicate auths ignored %s/%s/%s",
__func__, poolinstance, __func__, in_poolinstance->str,
st = safe_text_nonull(in_workername->str), cd_buf); st = safe_text_nonull(in_workername->str), cd_buf);
FREENULL(st); FREENULL(st);
@ -7895,7 +7897,7 @@ unitem:
return ok; return ok;
} }
bool poolstats_add(PGconn *conn, bool store, char *poolinstance, bool poolstats_add(PGconn *conn, bool store, INTRANSIENT *in_poolinstance,
char *elapsed, char *users, char *workers, char *elapsed, char *users, char *workers,
char *hashrate, char *hashrate5m, char *hashrate, char *hashrate5m,
char *hashrate1hr, char *hashrate24hr, char *hashrate1hr, char *hashrate24hr,
@ -7924,7 +7926,7 @@ bool poolstats_add(PGconn *conn, bool store, char *poolinstance,
row->stored = false; row->stored = false;
STRNCPY(row->poolinstance, poolinstance); row->in_poolinstance = in_poolinstance->str;
TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); TXT_TO_BIGINT("elapsed", elapsed, row->elapsed);
TXT_TO_INT("users", users, row->users); TXT_TO_INT("users", users, row->users);
TXT_TO_INT("workers", workers, row->workers); TXT_TO_INT("workers", workers, row->workers);
@ -7946,7 +7948,7 @@ bool poolstats_add(PGconn *conn, bool store, char *poolinstance,
if (store) { if (store) {
par = 0; par = 0;
params[par++] = str_to_buf(row->poolinstance, NULL, 0); params[par++] = str_to_buf(row->in_poolinstance, NULL, 0);
params[par++] = bigint_to_buf(row->elapsed, NULL, 0); params[par++] = bigint_to_buf(row->elapsed, NULL, 0);
params[par++] = int_to_buf(row->users, NULL, 0); params[par++] = int_to_buf(row->users, NULL, 0);
params[par++] = int_to_buf(row->workers, NULL, 0); params[par++] = int_to_buf(row->workers, NULL, 0);
@ -8104,12 +8106,12 @@ bool poolstats_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) { if (sys_poolinstance && strcmp(field, sys_poolinstance)) {
k_add_head(poolstats_free, item); k_add_head(poolstats_free, item);
POOLINSTANCE_DBLOAD_SET(poolstats, field); POOLINSTANCE_DBLOAD_SET(poolstats, field);
continue; continue;
} }
TXT_TO_STR("poolinstance", field, row->poolinstance); row->in_poolinstance = intransient_str("poolinstance", field);
PQ_GET_FLD(res, i, "elapsed", field, ok); PQ_GET_FLD(res, i, "elapsed", field, ok);
if (!ok) if (!ok)
@ -8175,7 +8177,7 @@ clean:
} }
// To RAM // To RAM
bool userstats_add(char *poolinstance, char *elapsed, char *username, bool userstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username,
INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, INTRANSIENT *in_workername, char *hashrate, char *hashrate5m,
char *hashrate1hr, char *hashrate24hr, bool idle, bool eos, char *hashrate1hr, char *hashrate24hr, bool idle, bool eos,
char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root)
@ -8195,7 +8197,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username,
DATA_USERSTATS(row, us_item); DATA_USERSTATS(row, us_item);
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
STRNCPY(row->poolinstance, poolinstance); row->in_poolinstance = in_poolinstance->str;
TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); TXT_TO_BIGINT("elapsed", elapsed, row->elapsed);
K_RLOCK(users_free); K_RLOCK(users_free);
u_item = find_users(username); u_item = find_users(username);
@ -8281,7 +8283,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username,
} }
// To RAM // To RAM
bool workerstats_add(char *poolinstance, char *elapsed, char *username, bool workerstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username,
INTRANSIENT *in_workername, char *hashrate, INTRANSIENT *in_workername, char *hashrate,
char *hashrate5m, char *hashrate1hr, char *hashrate24hr, char *hashrate5m, char *hashrate1hr, char *hashrate24hr,
bool idle, char *instances, char *by, char *code, bool idle, char *instances, char *by, char *code,
@ -8301,7 +8303,7 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username,
DATA_USERSTATS(row, us_item); DATA_USERSTATS(row, us_item);
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
STRNCPY(row->poolinstance, poolinstance); row->in_poolinstance = in_poolinstance->str;
TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); TXT_TO_BIGINT("elapsed", elapsed, row->elapsed);
K_RLOCK(users_free); K_RLOCK(users_free);
u_item = find_users(username); u_item = find_users(username);
@ -9015,7 +9017,7 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add,
} }
} }
DUP_POINTER(workmarkers_free, row->poolinstance, poolinstance); row->in_poolinstance = intransient_str("poolinstance", poolinstance);
row->workinfoidend = workinfoidend; row->workinfoidend = workinfoidend;
row->workinfoidstart = workinfoidstart; row->workinfoidstart = workinfoidstart;
DUP_POINTER(workmarkers_free, row->description, description); DUP_POINTER(workmarkers_free, row->description, description);
@ -9029,7 +9031,7 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add,
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; HISTORYDATECONTROL ") values (" PQPARAM11 ")";
par = 0; par = 0;
params[par++] = bigint_to_buf(row->markerid, NULL, 0); params[par++] = bigint_to_buf(row->markerid, NULL, 0);
params[par++] = str_to_buf(row->poolinstance, NULL, 0); params[par++] = str_to_buf(row->in_poolinstance, NULL, 0);
params[par++] = bigint_to_buf(row->workinfoidend, NULL, 0); params[par++] = bigint_to_buf(row->workinfoidend, NULL, 0);
params[par++] = bigint_to_buf(row->workinfoidstart, NULL, 0); params[par++] = bigint_to_buf(row->workinfoidstart, NULL, 0);
params[par++] = str_to_buf(row->description, NULL, 0); params[par++] = str_to_buf(row->description, NULL, 0);
@ -9161,13 +9163,12 @@ bool workmarkers_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) { if (sys_poolinstance && strcmp(field, sys_poolinstance)) {
k_add_head(workmarkers_free, item); k_add_head(workmarkers_free, item);
POOLINSTANCE_DBLOAD_SET(workmarkers, field); POOLINSTANCE_DBLOAD_SET(workmarkers, field);
continue; continue;
} }
TXT_TO_PTR("poolinstance", field, row->poolinstance); row->in_poolinstance = intransient_str("poolinstance", field);
LIST_MEM_ADD(workmarkers_free, row->poolinstance);
PQ_GET_FLD(res, i, "markerid", field, ok); PQ_GET_FLD(res, i, "markerid", field, ok);
if (!ok) if (!ok)
@ -9355,7 +9356,7 @@ bool _marks_process(PGconn *conn, bool add, char *poolinstance,
K_WUNLOCK(marks_free); K_WUNLOCK(marks_free);
DATA_MARKS(row, m_item); DATA_MARKS(row, m_item);
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
DUP_POINTER(marks_free, row->poolinstance, poolinstance); row->in_poolinstance = intransient_str("poolinstance", poolinstance);
row->workinfoid = workinfoid; row->workinfoid = workinfoid;
DUP_POINTER(marks_free, row->description, description); DUP_POINTER(marks_free, row->description, description);
DUP_POINTER(marks_free, row->extra, extra); DUP_POINTER(marks_free, row->extra, extra);
@ -9369,7 +9370,7 @@ bool _marks_process(PGconn *conn, bool add, char *poolinstance,
"status" "status"
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; HISTORYDATECONTROL ") values (" PQPARAM11 ")";
par = 0; par = 0;
params[par++] = str_to_buf(row->poolinstance, NULL, 0); params[par++] = str_to_buf(row->in_poolinstance, NULL, 0);
params[par++] = bigint_to_buf(workinfoid, NULL, 0); params[par++] = bigint_to_buf(workinfoid, NULL, 0);
params[par++] = str_to_buf(row->description, NULL, 0); params[par++] = str_to_buf(row->description, NULL, 0);
params[par++] = str_to_buf(row->extra, NULL, 0); params[par++] = str_to_buf(row->extra, NULL, 0);
@ -9494,13 +9495,12 @@ bool marks_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) { if (sys_poolinstance && strcmp(field, sys_poolinstance)) {
k_add_head(marks_free, item); k_add_head(marks_free, item);
POOLINSTANCE_DBLOAD_SET(marks, field); POOLINSTANCE_DBLOAD_SET(marks, field);
continue; continue;
} }
TXT_TO_PTR("poolinstance", field, row->poolinstance); row->in_poolinstance = intransient_str("poolinstance", field);
LIST_MEM_ADD(marks_free, row->poolinstance);
PQ_GET_FLD(res, i, "workinfoid", field, ok); PQ_GET_FLD(res, i, "workinfoid", field, ok);
if (!ok) if (!ok)

153
src/cmd.sh

@ -0,0 +1,153 @@
#!/bin/bash
#
tab=" "
#
cmd="
a genoff - turn off mark and payout generation (2 commands)
b genon - turn on mark and payout generation (2 commands)
c hold user - put a payout hold on user
d lock user reason - put a mining lock on user| a blank reason unlocks user
e pay block - display payout info for block height
f opay payoutid - orphan payoutid
g unhold user - remove a payout hold on a user
h ban ip eventname - ban an ip eventname, forever until ckdb restart
i unban ip eventname - unban an ip eventname| use 'exp' to clear it afterwards
j exp - remove all expired IP bans
k block height - show block details
l reject height blockhash - reject a block as unworthy| when it wasn't actually a block, just a close share
m reject2 height blockhash type desc - reject a block with type and desc| e.g. 'Stale' and 'Share was submitted after the block changed'
n terminate - I'll be back
"
#
msg="
a marks.1.action=genoff|payouts.1.action=genoff
b marks.1.action=genon|payouts.1.action=genon
c setatts.1.ua_HoldPayouts.str=Y${tab}username=@user@
d userstatus.1.username=@user@${tab}status=@reason@
e query.1.request=payout${tab}height=@block@
f payouts.1.action=orphan${tab}payoutid=@payoutid@
g expatts.1.attlist=HoldPayouts${tab}username=@user@
h events.1.action=ban${tab}ip=@ip@${tab}eventname=@eventname@
i events.1.action=unban${tab}ip=@ip@${tab}eventname=@eventname@
j events.1.action=expire
k query.1.request=block${tab}height=@height@
l blockstatus.1.action=reject${tab}height=@height@${tab}blockhash=@blockhash@${tab}info=
m blockstatus.1.action=reject${tab}height=@height@${tab}blockhash=@blockhash@${tab}info=@type@:@desc@
n terminate
"
# grep pattern matching the starting field used in cmd -> msg
letters="[a-n]"
# params allowed to be entered as blank (but will be prompted for if blank)
allowblank="|reason|"
#
cproc()
{
echo "$cmd" | cut -d' ' -f2 | tr "\n" "|" | sed -e "s/|||*/|/g"
}
#
getex()
{
let="`echo "$cmd" | grep "^$letters $1 " | cut -d' ' -f1`"
echo "$msg" | grep "^$let " | cut -d' ' -f2-
}
#
dsp0()
{
grep -v "^$" | cut -d' ' -f2- | tr "|" "\n" | sed -e "s/^/ /"
}
#
dsp()
{
echo "$cmd" | grep "^$letters $1 " | dsp0
}
#
cmds="`cproc`"
#
cmdz()
{
echo "$cmds" | tr '|' ' ' | sed -e "s/^ *//" -e "s/ *$//"
}
#
pars()
{
echo "$cmd" | grep "^$letters $1" | cut -d'-' -f1 | cut -d' ' -f3-
}
#
show()
{
echo "$1" | sed -e "s/$tab/'TAB'/g" -e "s/|/ and /g"
}
#
usAge()
{
echo "usAge: `basename $0` [cmd [params...]]"
echo " missing cmd or required params are prompted for"
echo " it's easiest to just run `basename $0` with no cmd/params :)"
echo " params can't contain TAB or '|'"
echo " cmd [params...] is one of:"
echo "$cmd" | dsp0
exit 1
}
#
if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
usAge
fi
#
if [ -z "$1" ] ; then
echo "(`cmdz`)"
read -p " or '?' for help: " cm
else
cm="$1"
fi
#
ok="`echo "$cmds" | grep "|$cm|"`"
#
if [ -z "$ok" ] ; then
usAge
fi
#
echo "`dsp $cm`"
ex0="`getex $cm`"
#
p="1"
for i in `pars $cm` ; do
p="$[$p+1]"
v="${@:$p:1}"
if [ -z "$v" ] ; then
read -p "$i: " v
fi
t="`echo "$v" | grep "$tab"`"
if [ "$t" ] ; then
echo "ERR: values can't contain TAB"
usAge
fi
m="`echo "$v" | grep "|"`"
if [ "$m" ] ; then
echo "ERR: values can't contain '|'"
usAge
fi
ab="`echo "$allowblank" | grep "|$i|"`"
if [ -z "$ab" ] ; then
if [ -z "$v" ] ; then
echo "ERR: $i can't be blank"
usAge
fi
fi
ex="`echo "$ex0" | sed -e "s|@$i@|$v|g"`" # allow /
ex0="$ex"
done
#
s=""
multi="`echo "$ex0" | grep '|'`"
if [ "$multi" ] ; then
s="s"
fi
#
echo "Command$s: `show "$ex0"`"
read -p "ok? (y): " ok
if [ "${ok:0:1}" = "y" ] ; then
echo "$ex0" | tr "|" "\n" | php ckdb.php
echo "Done"
else
echo "Aborted"
fi

2
src/klist.h

@ -152,7 +152,7 @@ typedef struct k_list {
void **data_memory; // allocated item data memory buffers void **data_memory; // allocated item data memory buffers
void (*dsp_func)(K_ITEM *, FILE *); // optional data display to a file void (*dsp_func)(K_ITEM *, FILE *); // optional data display to a file
int cull_count; int cull_count;
int ram; // ram allocated for data pointers - code must manage it uint64_t ram; // ram allocated for data pointers - code must manage it
int stores; // how many stores it currently has int stores; // how many stores it currently has
#if LOCK_CHECK #if LOCK_CHECK
// Since each thread has it's own k_lock no locking is required on this // Since each thread has it's own k_lock no locking is required on this

Loading…
Cancel
Save