From e30cc81cad143b168e4ff1088446247172aa882a Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 27 Feb 2015 14:10:23 +1100 Subject: [PATCH] ckdb/php - add extra pplns2 epoch information like pplns --- pool/page_pplns2.php | 12 ++++---- src/ckdb.h | 2 +- src/ckdb_cmd.c | 71 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/pool/page_pplns2.php b/pool/page_pplns2.php index 01c4c4ca..781fab51 100644 --- a/pool/page_pplns2.php +++ b/pool/page_pplns2.php @@ -188,14 +188,14 @@ Block: 'Elapsed Seconds' => ',pplns_elapsed', 'Users' => 'rows', 'Oldest Workinfoid' => 'begin_workinfoid', -# 'Oldest Time' => 'begin_stamp', -# 'Oldest Epoch' => 'begin_epoch', + 'Oldest Time' => 'begin_stamp', + 'Oldest Epoch' => 'begin_epoch', 'Block Workinfoid' => 'block_workinfoid', -# 'Block Time' => 'block_stamp', -# 'Block Epoch' => 'block_epoch', + 'Block Time' => 'block_stamp', + 'Block Epoch' => 'block_epoch', 'Newest Workinfoid' => 'end_workinfoid', -# 'Newest Share Time' => 'end_stamp', -# 'Newest Share Epoch' => 'end_epoch', + 'Newest Share Time' => 'end_stamp', + 'Newest Share Epoch' => 'end_epoch', 'Network Difficulty' => 'block_ndiff', 'PPLNS Factor' => 'diff_times', 'PPLNS Added' => 'diff_add', diff --git a/src/ckdb.h b/src/ckdb.h index d817ef9b..b11bb0a9 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.004" +#define CKDB_VERSION DB_VERSION"-1.005" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 14606a80..a9c32c77 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -3828,13 +3828,19 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, size_t siz = sizeof(reply); K_ITEM *i_height; K_ITEM b_look, *b_item, *p_item, *mp_item, *pay_item, *u_item; + K_ITEM *w_item; MININGPAYOUTS *miningpayouts; PAYMENTS *payments; PAYOUTS *payouts; BLOCKS lookblocks, *blocks; + tv_t block_tv = { 0L, 0L }; + WORKINFO *bworkinfo, *workinfo; + char ndiffbin[TXT_SML+1]; + double ndiff; USERS *users; int32_t height; K_TREE_CTX b_ctx[1], mp_ctx[1], pay_ctx[1]; + char tv_buf[DATE_BUFSIZ]; size_t len, off; int rows; bool pok; @@ -3851,18 +3857,38 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): height %"PRId32, __func__, height); - lookblocks.height = height; + lookblocks.height = height + 1; lookblocks.blockhash[0] = '\0'; INIT_BLOCKS(&b_look); b_look.data = (void *)(&lookblocks); K_RLOCK(blocks_free); - b_item = find_after_in_ktree(blocks_root, &b_look, cmp_blocks, b_ctx); + b_item = find_before_in_ktree(blocks_root, &b_look, cmp_blocks, b_ctx); + if (!b_item) { + K_RUNLOCK(blocks_free); + snprintf(reply, siz, "ERR.no block height %"PRId32, height); + return strdup(reply); + } + DATA_BLOCKS(blocks, b_item); + while (b_item && blocks->height == height) { + if (blocks->confirmed[0] == BLOCKS_NEW) + copy_tv(&block_tv, &(blocks->createdate)); + // Allow any state, but report it + if (CURRENT(&(blocks->expirydate))) + break; + b_item = prev_in_ktree(b_ctx); + DATA_BLOCKS_NULL(blocks, b_item); + } K_RUNLOCK(blocks_free); - DATA_BLOCKS_NULL(blocks, b_item); if (!b_item || blocks->height != height) { snprintf(reply, siz, "ERR.no block height %"PRId32, height); return strdup(reply); } + if (block_tv.tv_sec == 0) { + snprintf(reply, siz, "ERR.block %"PRId32" missing '%s' record", + height, + blocks_confirmed(BLOCKS_NEW_STR)); + return strdup(reply); + } if (!CURRENT(&(blocks->expirydate))) { snprintf(reply, siz, "ERR.no CURRENT block %d"PRId32, height); return strdup(reply); @@ -3882,6 +3908,15 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, break; } + w_item = find_workinfo(blocks->workinfoid, NULL); + if (!w_item) { + snprintf(reply, siz, "ERR.missing block workinfo record!" + " %"PRId64, + blocks->workinfoid); + return strdup(reply); + } + DATA_WORKINFO(bworkinfo, w_item); + pok = false; K_RLOCK(payouts_free); p_item = find_payouts(height, blocks->blockhash); @@ -3905,6 +3940,15 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): total %.1f want %.1f", __func__, payouts->diffused, payouts->diffwanted); + w_item = find_workinfo(payouts->workinfoidstart, NULL); + if (!w_item) { + snprintf(reply, siz, "ERR.missing begin workinfo record!" + " %"PRId64, + payouts->workinfoidstart); + return strdup(reply); + } + DATA_WORKINFO(workinfo, w_item); + APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC(buf, off, len, "ok."); snprintf(tmp, sizeof(tmp), "block=%d%c", height, FLDSEP); @@ -4012,8 +4056,29 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, "Users", FLDSEP, "", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + tv_to_buf(&(workinfo->createdate), tv_buf, sizeof(tv_buf)); + snprintf(tmp, sizeof(tmp), "begin_stamp=%s%c", tv_buf, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "begin_epoch=%ld%c", + workinfo->createdate.tv_sec, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + tv_to_buf(&block_tv, tv_buf, sizeof(tv_buf)); + snprintf(tmp, sizeof(tmp), "block_stamp=%s%c", tv_buf, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "block_epoch=%ld%c", block_tv.tv_sec, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + tv_to_buf(&(payouts->lastshareacc), tv_buf, sizeof(tv_buf)); + snprintf(tmp, sizeof(tmp), "end_stamp=%s%c", tv_buf, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "end_epoch=%ld%c", + payouts->lastshareacc.tv_sec, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "%s%c", payouts->stats, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + hex2bin(ndiffbin, bworkinfo->bits, 4); + ndiff = diff_from_nbits(ndiffbin); + snprintf(tmp, sizeof(tmp), "block_ndiff=%f%c", ndiff, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "diff_want=%.1f%c", payouts->diffwanted, FLDSEP); APPEND_REALLOC(buf, off, len, tmp);