Browse Source

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

master
Con Kolivas 10 years ago
parent
commit
4745e7d6e7
  1. 5
      pool/page_blocks.php
  2. 288
      src/ckdb.c
  3. 11
      src/ckdb.h
  4. 15
      src/ckdb_cmd.c

5
pool/page_blocks.php

@ -96,10 +96,10 @@ function doblocks($data, $user)
$csv = "Sequence,Height,Status,Timestamp,DiffAcc,NetDiff,Hash\n"; $csv = "Sequence,Height,Status,Timestamp,DiffAcc,NetDiff,Hash\n";
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
{ {
$tot = $ans['tot'];
$count = $ans['rows']; $count = $ans['rows'];
for ($i = 0; $i < $count; $i++) for ($i = 0; $i < $count; $i++)
{ {
$seq = $i + 1;
if (($i % 2) == 0) if (($i % 2) == 0)
$row = 'even'; $row = 'even';
else else
@ -114,7 +114,10 @@ function doblocks($data, $user)
{ {
$ex = 's'; $ex = 's';
$orph = true; $orph = true;
$seq = '';
} }
else
$seq = $tot--;
if ($stat == '1-Confirm') if ($stat == '1-Confirm')
{ {
if (isset($data['info']['lastheight'])) if (isset($data['info']['lastheight']))

288
src/ckdb.c

@ -1233,9 +1233,10 @@ static enum cmd_values breakdown(K_TREE **trf_root, K_STORE **trf_store,
TRANSFER *transfer; TRANSFER *transfer;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
K_ITEM *item; K_ITEM *item;
char *cmdptr, *idptr, *next, *eq; char *cmdptr, *idptr, *next, *eq, *end, *was;
char *data = NULL; char *data = NULL, *tmp;
bool noid = false; bool noid = false;
size_t siz;
*trf_root = NULL; *trf_root = NULL;
*trf_store = NULL; *trf_store = NULL;
@ -1284,122 +1285,180 @@ static enum cmd_values breakdown(K_TREE **trf_root, K_STORE **trf_store,
*trf_store = k_new_store(transfer_free); *trf_store = k_new_store(transfer_free);
next = data; next = data;
if (next && strncmp(next, JSON_TRANSFER, JSON_TRANSFER_LEN) == 0) { if (next && strncmp(next, JSON_TRANSFER, JSON_TRANSFER_LEN) == 0) {
json_t *json_data; // It's json
json_error_t err_val;
void *json_iter;
const char *json_key, *json_str;
json_t *json_value;
int json_typ;
size_t siz;
bool ok;
next += JSON_TRANSFER_LEN; next += JSON_TRANSFER_LEN;
json_data = json_loads(next, JSON_DISABLE_EOF_CHECK, &err_val); was = next;
if (!json_data) { while (*next == ' ')
/* This REALLY shouldn't ever get an error since the input next++;
* is a json generated string if (*next != JSON_BEGIN) {
* If that happens then dump lots of information */ LOGERR("JSON_BEGIN '%c' was: %.32s...",
char *text = safe_text(next); JSON_BEGIN, tmp = safe_text(was));
LOGERR("Json decode error from command: '%s' " free(tmp);
"json_err=(%d:%d:%d)%s:%s input='%s'",
cmd, err_val.line, err_val.column,
err_val.position, err_val.source,
err_val.text, text);
free(text);
free(cmdptr); free(cmdptr);
return CMD_REPLY; return CMD_REPLY;
} }
json_iter = json_object_iter(json_data); next++;
K_WLOCK(transfer_free); // while we have a new quoted name
while (json_iter) { while (*next == JSON_STR) {
json_key = json_object_iter_key(json_iter); was = next;
json_value = json_object_iter_value(json_iter); end = ++next;
// look for the end quote
while (*end && *end != JSON_STR) {
if (*(end++) == JSON_ESC)
end++;
}
if (!*end) {
LOGERR("JSON name no trailing '%c' was: %.32s...",
JSON_STR, tmp = safe_text(was));
free(tmp);
free(cmdptr);
return CMD_REPLY;
}
if (next == end) {
LOGERR("JSON zero length name was: %.32s...",
tmp = safe_text(was));
free(tmp);
free(cmdptr);
return CMD_REPLY;
}
*(end++) = '\0';
K_WLOCK(transfer_free);
item = k_unlink_head(transfer_free); item = k_unlink_head(transfer_free);
K_WUNLOCK(transfer_free);
DATA_TRANSFER(transfer, item); DATA_TRANSFER(transfer, item);
ok = true; STRNCPY(transfer->name, next);
json_typ = json_typeof(json_value); was = next = end;
switch (json_typ) { while (*next == ' ')
case JSON_STRING: next++;
json_str = json_string_value(json_value); // we have a name, now expect a value after it
siz = strlen(json_str); if (*next != JSON_VALUE) {
if (siz >= sizeof(transfer->svalue)) LOGERR("JSON_VALUE '%c' '%s' was: %.32s...",
transfer->mvalue = strdup(json_str); JSON_VALUE, transfer->name,
else { tmp = safe_text(was));
STRNCPY(transfer->svalue, json_str); free(tmp);
transfer->mvalue = transfer->svalue; free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
was = ++next;
while (*next == ' ')
next++;
if (*next == JSON_STR) {
end = ++next;
// A quoted value must have a terminating quote
while (*end && *end != JSON_STR) {
if (*(end++) == JSON_ESC)
end++;
} }
break; if (!*end) {
case JSON_REAL: LOGERR("JSON '%s' value was: %.32s...",
snprintf(transfer->svalue, transfer->name,
sizeof(transfer->svalue), tmp = safe_text(was));
"%f", json_real_value(json_value)); free(tmp);
transfer->mvalue = transfer->svalue; free(cmdptr);
break; K_WLOCK(transfer_free);
case JSON_INTEGER: k_add_head(transfer_free, item);
snprintf(transfer->svalue, K_WUNLOCK(transfer_free);
sizeof(transfer->svalue), return CMD_REPLY;
"%"PRId64,
(int64_t)json_integer_value(json_value));
transfer->mvalue = transfer->svalue;
break;
case JSON_TRUE:
case JSON_FALSE:
snprintf(transfer->svalue,
sizeof(transfer->svalue),
"%s", (json_typ == JSON_TRUE) ?
TRUE_STR : FALSE_STR);
transfer->mvalue = transfer->svalue;
break;
case JSON_ARRAY:
{
/* only one level array of strings for now (merkletree)
* ignore other data */
size_t i, len, off, count = json_array_size(json_value);
json_t *json_element;
bool first = true;
APPEND_REALLOC_INIT(transfer->mvalue, off, len);
for (i = 0; i < count; i++) {
json_element = json_array_get(json_value, i);
if (json_is_string(json_element)) {
json_str = json_string_value(json_element);
siz = strlen(json_str);
if (first)
first = false;
else {
APPEND_REALLOC(transfer->mvalue,
off, len, " ");
}
APPEND_REALLOC(transfer->mvalue,
off, len, json_str);
} else
LOGERR("%s() unhandled json type %d in array %s"
" in cmd %s", __func__,
json_typ, json_key, cmd);
}
} }
break; siz = end - next;
default: end++;
LOGERR("%s() unhandled json type %d in cmd %s", } else if (*next == JSON_ARRAY) {
__func__, json_typ, cmd); // Only merklehash for now
ok = false; if (strcmp(transfer->name, "merklehash")) {
break; LOGERR("JSON '%s' can't be an array",
transfer->name);
free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
end = ++next;
/* No structure testing for now since we
* don't expect merklehash to get it wrong,
* and if it does, it will show up as some
* other error anyway */
while (*end && *end != JSON_ARRAY_END)
end++;
if (end < next+1) {
LOGERR("JSON '%s' zero length value "
"was: %.32s...",
transfer->name,
tmp = safe_text(was));
free(tmp);
free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
siz = end - next;
end++;
} else {
end = next;
// A non quoted value ends on SEP, END or space
while (*end && *end != JSON_SEP &&
*end != JSON_END && *end != ' ') {
end++;
}
if (!*end) {
LOGERR("JSON '%s' value was: %.32s...",
transfer->name,
tmp = safe_text(was));
free(tmp);
free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
if (next == end) {
LOGERR("JSON '%s' zero length value "
"was: %.32s...",
transfer->name,
tmp = safe_text(was));
free(tmp);
free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
siz = end - next;
} }
if (siz >= sizeof(transfer->svalue)) {
if (ok) transfer->mvalue = malloc(siz+1);
STRNCPY(transfer->name, json_key); STRNCPYSIZ(transfer->mvalue, next, siz+1);
if (!ok || find_in_ktree(*trf_root, item, cmp_transfer, ctx)) {
if (transfer->mvalue != transfer->svalue)
FREENULL(transfer->mvalue);
k_add_head(transfer_free, item);
} else { } else {
*trf_root = add_to_ktree(*trf_root, item, cmp_transfer); STRNCPYSIZ(transfer->svalue, next, siz+1);
k_add_head(*trf_store, item); transfer->mvalue = transfer->svalue;
}
*trf_root = add_to_ktree(*trf_root, item, cmp_transfer);
k_add_head(*trf_store, item);
// find the separator then move to the next name
next = end;
while (*next == ' ')
next++;
if (*next == JSON_SEP) {
next++;
while (*next == ' ')
next++;
} }
json_iter = json_object_iter_next(json_data, json_iter);
} }
K_WUNLOCK(transfer_free); if (*next != JSON_END) {
json_decref(json_data); LOGERR("JSON_END '%c' was: %.32s...",
JSON_END, tmp = safe_text(next));
free(tmp);
free(cmdptr);
K_WLOCK(transfer_free);
k_add_head(transfer_free, item);
K_WUNLOCK(transfer_free);
return CMD_REPLY;
}
} else { } else {
K_WLOCK(transfer_free); K_WLOCK(transfer_free);
while (next && *next) { while (next && *next) {
@ -1433,8 +1492,10 @@ static enum cmd_values breakdown(K_TREE **trf_root, K_STORE **trf_store,
} }
if (ckdb_cmds[*which_cmds].createdate) { if (ckdb_cmds[*which_cmds].createdate) {
item = require_name(*trf_root, "createdate", 10, NULL, reply, sizeof(reply)); item = require_name(*trf_root, "createdate", 10, NULL, reply, sizeof(reply));
if (!item) if (!item) {
free(cmdptr);
return CMD_REPLY; return CMD_REPLY;
}
DATA_TRANSFER(transfer, item); DATA_TRANSFER(transfer, item);
txt_to_ctv("createdate", transfer->mvalue, cd, sizeof(*cd)); txt_to_ctv("createdate", transfer->mvalue, cd, sizeof(*cd));
@ -2922,7 +2983,8 @@ static bool reload_from(tv_t *start)
bool finished = false, matched = false, ret = true, ok, apipe = false; bool finished = false, matched = false, ret = true, ok, apipe = false;
char *filename = NULL; char *filename = NULL;
uint64_t count, total; uint64_t count, total;
tv_t now; tv_t now, begin;
double diff;
FILE *fp = NULL; FILE *fp = NULL;
reload_buf = malloc(MAX_READ); reload_buf = malloc(MAX_READ);
@ -2943,6 +3005,7 @@ static bool reload_from(tv_t *start)
quithere(1, "Failed to open '%s'", filename); quithere(1, "Failed to open '%s'", filename);
setnow(&now); setnow(&now);
copy_tv(&begin, &now);
tvs_to_buf(&now, run, sizeof(run)); tvs_to_buf(&now, run, sizeof(run));
snprintf(reload_buf, MAX_READ, "reload.%s.s0", run); snprintf(reload_buf, MAX_READ, "reload.%s.s0", run);
LOGQUE(reload_buf); LOGQUE(reload_buf);
@ -3026,12 +3089,17 @@ static bool reload_from(tv_t *start)
PQfinish(conn); PQfinish(conn);
setnow(&now);
diff = tvdiff(&now, &begin);
if (diff == 0)
diff = 1;
snprintf(reload_buf, MAX_READ, "reload.%s.%"PRIu64, run, total); snprintf(reload_buf, MAX_READ, "reload.%s.%"PRIu64, run, total);
LOGQUE(reload_buf); LOGQUE(reload_buf);
LOGWARNING("%s(): read %d file%s, total %"PRIu64" line%s", LOGWARNING("%s(): read %d file%s, total %"PRIu64" line%s %.2f/s",
__func__, __func__,
processing, processing == 1 ? "" : "s", processing, processing == 1 ? "" : "s",
total, total == 1 ? "" : "s"); total, total == 1 ? "" : "s", (total / diff));
if (everyone_die) if (everyone_die)
return true; return true;

11
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.6" #define DB_VERSION "0.9.6"
#define CKDB_VERSION DB_VERSION"-0.841" #define CKDB_VERSION DB_VERSION"-0.903"
#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__
@ -268,6 +268,15 @@ extern bool everyone_die;
#define JSON_TRANSFER "json=" #define JSON_TRANSFER "json="
#define JSON_TRANSFER_LEN (sizeof(JSON_TRANSFER)-1) #define JSON_TRANSFER_LEN (sizeof(JSON_TRANSFER)-1)
#define JSON_BEGIN '{'
// Arrays have limited support in breakdown()
#define JSON_ARRAY '['
#define JSON_ARRAY_END ']'
#define JSON_STR '"'
#define JSON_VALUE ':'
#define JSON_SEP ','
#define JSON_END '}'
#define JSON_ESC '\\'
// Methods for sharelog (common function for all) // Methods for sharelog (common function for all)
#define STR_WORKINFO "workinfo" #define STR_WORKINFO "workinfo"

15
src/ckdb_cmd.c

@ -819,7 +819,7 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id,
size_t len, off; size_t len, off;
int32_t height = -1; int32_t height = -1;
tv_t first_cd = {0,0}; tv_t first_cd = {0,0};
int rows; int rows, tot;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
@ -828,6 +828,16 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id,
rows = 0; rows = 0;
K_RLOCK(blocks_free); K_RLOCK(blocks_free);
b_item = last_in_ktree(blocks_root, ctx); b_item = last_in_ktree(blocks_root, ctx);
tot = 0;
while (b_item) {
DATA_BLOCKS(blocks, b_item);
if (CURRENT(&(blocks->expirydate))) {
if (blocks->confirmed[0] != BLOCKS_ORPHAN)
tot++;
}
b_item = prev_in_ktree(ctx);
}
b_item = last_in_ktree(blocks_root, ctx);
while (b_item && rows < 42) { while (b_item && rows < 42) {
DATA_BLOCKS(blocks, b_item); DATA_BLOCKS(blocks, b_item);
if (height != blocks->height) { if (height != blocks->height) {
@ -914,7 +924,8 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id,
} }
K_RUNLOCK(blocks_free); K_RUNLOCK(blocks_free);
snprintf(tmp, sizeof(tmp), snprintf(tmp, sizeof(tmp),
"rows=%d%cflds=%s%c", "tot=%d%crows=%d%cflds=%s%c",
tot, FLDSEP,
rows, FLDSEP, rows, FLDSEP,
"height,blockhash,nonce,reward,workername,firstcreatedate," "height,blockhash,nonce,reward,workername,firstcreatedate,"
"createdate,status,diffacc,diffinv,shareacc,shareinv,elapsed," "createdate,status,diffacc,diffinv,shareacc,shareinv,elapsed,"

Loading…
Cancel
Save