diff --git a/pool/page_mpayouts.php b/pool/page_mpayouts.php index 18e0df0b..60eec061 100644 --- a/pool/page_mpayouts.php +++ b/pool/page_mpayouts.php @@ -14,6 +14,7 @@ function dompayouts($data, $user) $pg .= "\n"; $pg .= ""; $pg .= ""; + $pg .= ""; $pg .= ""; $pg .= ""; $pg .= ""; @@ -36,6 +37,7 @@ function dompayouts($data, $user) $pg .= ""; $pg .= ''; + $pg .= ''; $pg .= ''; $diffused = $ans['diffused:'.$i]; $pg .= ''; @@ -63,7 +65,7 @@ function dompayouts($data, $user) $pg .= ""; $pg .= ''; - $pg .= ''; + $pg .= ''; $pg .= ''; $pg .= "\n"; } diff --git a/src/ckdb.c b/src/ckdb.c index 97b473b7..4cccaf8c 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -772,6 +772,7 @@ static bool getdata3() if (!confirm_sharesummary) { if (!(ok = paymentaddresses_fill(conn)) || everyone_die) goto sukamudai; + /* FYI must be after blocks */ if (!(ok = payments_fill(conn)) || everyone_die) goto sukamudai; if (!(ok = miningpayouts_fill(conn)) || everyone_die) diff --git a/src/ckdb.h b/src/ckdb.h index 8acdd7b1..8ab5cf26 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.2" -#define CKDB_VERSION DB_VERSION"-1.228" +#define CKDB_VERSION DB_VERSION"-1.229" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1578,6 +1578,7 @@ typedef struct payouts { int64_t payoutid; int32_t height; char blockhash[TXT_BIG+1]; + tv_t blockcreatedate; // non-DB field int64_t minerreward; int64_t workinfoidstart; int64_t workinfoidend; @@ -2303,6 +2304,7 @@ extern double _blockhash_diff(char *hash, WHERE_FFL_ARGS); extern void dsp_blocks(K_ITEM *item, FILE *stream); extern cmp_t cmp_blocks(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_blocks(int32_t height, char *blockhash, K_TREE_CTX *ctx); +extern K_ITEM *find_blocks_new(K_ITEM *b_item, K_TREE_CTX *ctx); extern K_ITEM *find_prev_blocks(int32_t height); extern const char *blocks_confirmed(char *confirmed); extern void zero_on_new_block(); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 1e41f13a..ed5e9786 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -4997,6 +4997,11 @@ static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), + "block"CDTRF":%d=%ld%c", rows, + payouts->blockcreatedate.tv_sec, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + bigint_to_buf(payouts->elapsed, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "elapsed:%d=%s%c", @@ -5041,7 +5046,7 @@ static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c", rows, FLDSEP, - "payoutid,height,elapsed,amount,diffacc,minerreward,diffused,status", + "payoutid,height,block"CDTRF",elapsed,amount,diffacc,minerreward,diffused,status", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 71754783..7942a790 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2621,6 +2621,33 @@ K_ITEM *find_blocks(int32_t height, char *blockhash, K_TREE_CTX *ctx) return find_in_ktree(blocks_root, &look, cmp_blocks, ctx); } +/* Find the matching NEW block - requires K_RLOCK() + * This requires calling find_blocks() first to get ctx */ +K_ITEM *find_blocks_new(K_ITEM *b_item, K_TREE_CTX *ctx) +{ + BLOCKS *blocks, *blocks2; + K_ITEM *b2_item; + + // Return what was passed in if it was NULL or was the NEW block + DATA_BLOCKS_NULL(blocks, b_item); + if (!b_item || blocks->confirmed[0] == BLOCKS_NEW) + return b_item; + + // NEW should be after the non-NEW block + b2_item = next_in_ktree(ctx); + DATA_BLOCKS_NULL(blocks2, b2_item); + while (b2_item && blocks2->height == blocks->height && + strcmp(blocks2->blockhash, blocks->blockhash) == 0) { + if (blocks2->confirmed[0] == BLOCKS_NEW) + return b2_item; + + b2_item = next_in_ktree(ctx); + DATA_BLOCKS_NULL(blocks2, b2_item); + } + + return NULL; +} + // Must be R or W locked before call K_ITEM *find_prev_blocks(int32_t height) { @@ -3314,22 +3341,9 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) goto oku; } DATA_BLOCKS(blocks, b_item); - b2_item = b_item; - DATA_BLOCKS(blocks2, b2_item); - while (b2_item && blocks2->height == height && - strcmp(blocks2->blockhash, blockhash) == 0) { - if (blocks2->confirmed[0] == BLOCKS_NEW) { - copy_tv(&end_tv, &(blocks2->createdate)); - if (!addr_cd) - addr_cd = &(blocks2->createdate); - break; - } - b2_item = next_in_ktree(b_ctx); - DATA_BLOCKS_NULL(blocks2, b2_item); - } + b2_item = find_blocks_new(b_item, b_ctx); K_RUNLOCK(blocks_free); - // If addr_cd was null it should've been set to the block NEW createdate - if (!addr_cd || end_tv.tv_sec == 0) { + if (!b2_item) { LOGEMERG("%s(): missing %s record for block %"PRId32 "/%"PRId64"/%s/%s/%"PRId64, __func__, blocks_confirmed(BLOCKS_NEW_STR), @@ -3338,6 +3352,10 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) blocks->reward); goto oku; } + DATA_BLOCKS(blocks2, b2_item); + copy_tv(&end_tv, &(blocks2->createdate)); + if (!addr_cd) + addr_cd = &(blocks2->createdate); LOGDEBUG("%s(): block %"PRId32"/%"PRId64"/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, @@ -3639,6 +3657,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) bzero(payouts, sizeof(*payouts)); payouts->height = height; STRNCPY(payouts->blockhash, blockhash); + copy_tv(&(payouts->blockcreatedate), &(blocks2->createdate)); d64 = blocks->reward * 9 / 1000; g64 = blocks->reward - d64; payouts->minerreward = g64; @@ -3905,6 +3924,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) payouts2->payoutid = payouts->payoutid; payouts2->height = payouts->height; STRNCPY(payouts2->blockhash, payouts->blockhash); + copy_tv(&(payouts2->blockcreatedate), &(payouts->blockcreatedate)); payouts2->minerreward = payouts->minerreward; payouts2->workinfoidstart = payouts->workinfoidstart; payouts2->workinfoidend = payouts->workinfoidend; diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index d355be78..b4fd8eee 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -5501,8 +5501,10 @@ bool payouts_fill(PGconn *conn) { ExecStatusType rescode; PGresult *res; - K_ITEM *item; + K_ITEM *item, *b_item, *b2_item; + K_TREE_CTX ctx[1]; PAYOUTS *row; + BLOCKS *blocks; int n, i; char *field; char *sel; @@ -5616,6 +5618,29 @@ bool payouts_fill(PGconn *conn) if (!ok) break; + // This also of course, verifies the payouts -> blocks reference + b_item = find_blocks(row->height, row->blockhash, ctx); + if (!b_item) { + LOGERR("%s(): payoutid %"PRId64" references unknown " + "block %"PRId32"/%s", + __func__, row->payoutid, row->height, + row->blockhash); + ok = false; + break; + } else { + b2_item = find_blocks_new(b_item, ctx); + if (!b2_item) { + LOGERR("%s(): payoutid %"PRId64" references " + "block %"PRId32"/%s that has no NEW", + __func__, row->payoutid, row->height, + row->blockhash); + ok = false; + break; + } + DATA_BLOCKS(blocks, b2_item); + copy_tv(&(row->blockcreatedate), &(blocks->createdate)); + } + payouts_root = add_to_ktree(payouts_root, item, cmp_payouts); payouts_id_root = add_to_ktree(payouts_id_root, item, cmp_payouts_id); k_add_head(payouts_store, item);
BlockBlock UTCMiner RewardN DiffN Range
'.$ans['height:'.$i].''.gmdate('d/M H:i',$ans['blockcreatedate:'.$i]).''.btcfmt($ans['minerreward:'.$i]).''.difffmt($diffused).'
Total:'.btcfmt($totamt).'