diff --git a/pool/base.php b/pool/base.php index 53426167..a016fc3e 100644 --- a/pool/base.php +++ b/pool/base.php @@ -173,12 +173,15 @@ function btcfmt($amt) return number_format($amt, 8); } # -function utcd($when, $brief = false) +function utcd($when, $brief = false, $zone = true) { if ($brief) - return gmdate('M-d H:i:s', round($when)); + return gmdate('M‑d H:i:s', round($when)); else - return gmdate('Y-m-d H:i:s+00', round($when)); + if ($zone) + return gmdate('Y‑m‑d H:i:s+00', round($when)); + else + return gmdate('Y‑m‑d H:i:s', round($when)); } # global $sipre; diff --git a/pool/page_blocks.php b/pool/page_blocks.php index 0e90c41a..231703ad 100644 --- a/pool/page_blocks.php +++ b/pool/page_blocks.php @@ -140,6 +140,7 @@ function doblocks($data, $user) if ($ans['STATUS'] == 'ok') { $count = $ans['rows']; + $histsiz = $ans['historysize'] . ' '; if ($count == 1) { $num = ''; @@ -154,7 +155,10 @@ function doblocks($data, $user) $pg .= "

Last$num Block$s

"; } else + { + $histsiz = ''; $pg .= '

Blocks

'; + } list($fg, $bg) = pctcolour(25.0); $pg .= ""; @@ -176,11 +180,12 @@ function doblocks($data, $user) if ($user !== null) $pg .= "Who"; $pg .= "Block Reward"; - $pg .= "When"; + $pg .= "When UTC"; $pg .= "Status"; $pg .= "Diff"; $pg .= "Diff%"; $pg .= "CDF"; + $pg .= "${histsiz}Luck%"; $pg .= "B"; $pg .= "\n"; } @@ -286,6 +291,7 @@ function doblocks($data, $user) $diffratio = $ans['diffratio:'.$i]; $cdf = $ans['cdf:'.$i]; $luck = $ans['luck:'.$i]; + $hist = $ans['luckhistory:'.$i]; if ($diffratio > 0) { @@ -296,11 +302,13 @@ function doblocks($data, $user) list($fg, $bg) = pctcolour($colpct); $bpct = "$approx".number_format($pct, 3).'%'; $bg = " bgcolor=$bg"; + $histdsp = "$approx".number_format(100.0 * $hist, 2).'%'; } else { $bpct = "$approx".number_format($pct, 3).'%'; $bg = ''; + $histdsp = ' '; } $blktot += $diffacc; if ($conf != 'O' and $conf != 'R') @@ -313,6 +321,7 @@ function doblocks($data, $user) $bg = ''; $bpct = '?'; $cdfdsp = '?'; + $histdsp = '?'; } if ($wantcsv === false) @@ -323,11 +332,12 @@ function doblocks($data, $user) if ($user !== null) $pg .= "".htmlspecialchars($ans['workername:'.$i]).''; $pg .= "".btcfmt($ans['reward:'.$i]).''; - $pg .= "".utcd($ans['firstcreatedate:'.$i]).''; + $pg .= "".utcd($ans['firstcreatedate:'.$i], false, false).''; $pg .= "$tt$stat"; $pg .= "$stara$approx$acc"; $pg .= "$bpct"; $pg .= "$cdfdsp"; + $pg .= "$histdsp"; $pg .= "$nn"; $pg .= "\n"; } @@ -353,9 +363,9 @@ function doblocks($data, $user) { $pg .= 'netdiff, FLDSEP, rows, blocks->blockdiffratio, FLDSEP, rows, blocks->blockcdf, FLDSEP, - rows, blocks->blockluck, FLDSEP); + rows, blocks->blockluck, FLDSEP, + rows, blocks->luckhistory, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); } else { snprintf(tmp, sizeof(tmp), "netdiff:%d=?%cdiffratio:%d=?%c" - "cdf:%d=?%cluck:%d=?%c", + "cdf:%d=?%cluck:%d=?%c" + "luckhistory:%d=?%c", rows, FLDSEP, rows, FLDSEP, - rows, FLDSEP, rows, FLDSEP); + rows, FLDSEP, rows, FLDSEP, + rows, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); } @@ -1515,11 +1519,12 @@ redo: APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), - "rows=%d%cflds=%s%c", - rows, FLDSEP, + "historysize=%d%crows=%d%cflds=%s%c", + LUCKNUM, FLDSEP, rows, FLDSEP, "seq,height,blockhash,nonce,reward,workername,first"CDTRF"," CDTRF",prev"CDTRF",confirmed,status,info,statsconf,diffacc," - "diffinv,shareacc,shareinv,elapsed,netdiff,diffratio,cdf,luck", + "diffinv,shareacc,shareinv,elapsed,netdiff,diffratio,cdf,luck," + "luckhistory", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 7928938b..2604e5cc 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -3021,42 +3021,36 @@ bool check_update_blocks_stats(tv_t *stats) WORKINFO *workinfo; BLOCKS *blocks; double ok, diffacc, netsumm, diffmean, pending, txmean, cr; + double meansum, meanall[LUCKNUM]; bool ret = false; tv_t now; + int i, lim; /* Wait for startup_complete rather than db_load_complete * This avoids doing a 'long' lock stats update while reloading */ if (!startup_complete) return false; + for (i = 0; i < LUCKNUM; i++) + meanall[i] = 0.0; + K_RLOCK(workinfo_free); K_WLOCK(blocks_free); if (blocks_stats_rebuild) { /* Have to first work out the diffcalc for each block * Orphans count towards the next valid block after the orphan * so this has to be done in the reverse order of the range - * calculations */ + * calculations + * Luckhistory is calculated from earlier blocks up to the + * current block so must be calculated in reverse order also + * Luckhistory requires netdiff */ pending = 0.0; + ok = 0; b_item = first_in_ktree(blocks_root, ctx); while (b_item) { DATA_BLOCKS(blocks, b_item); if (CURRENT(&(blocks->expirydate))) { pending += blocks->diffacc; - if (blocks->confirmed[0] == BLOCKS_ORPHAN || - blocks->confirmed[0] == BLOCKS_REJECT) - blocks->diffcalc = 0.0; - else { - blocks->diffcalc = pending; - pending = 0.0; - } - } - b_item = next_in_ktree(ctx); - } - ok = diffacc = netsumm = diffmean = txmean = 0.0; - b_item = last_in_ktree(blocks_root, ctx); - while (b_item) { - DATA_BLOCKS(blocks, b_item); - if (CURRENT(&(blocks->expirydate))) { if (blocks->netdiff == 0) { w_item = _find_workinfo(blocks->workinfoid, true, NULL); if (!w_item) { @@ -3076,6 +3070,42 @@ bool check_update_blocks_stats(tv_t *stats) DATA_WORKINFO(workinfo, w_item); blocks->netdiff = workinfo->diff_target; } + if (blocks->confirmed[0] == BLOCKS_ORPHAN || + blocks->confirmed[0] == BLOCKS_REJECT) { + blocks->diffcalc = 0.0; + blocks->luckhistory = 0.0; + } else { + ok++; + blocks->diffcalc = pending; + pending = 0.0; + + meansum = 0.0; + for (i = LUCKNUM-1; i > 0; i--) { + meanall[i] = meanall[i-1]; + meansum += meanall[i]; + } + + if (blocks->netdiff == 0.0) + meanall[0] = 0.0; + else + meanall[0] = blocks->diffcalc / blocks->netdiff; + + meansum += meanall[0]; + + lim = (ok < LUCKNUM) ? ok : LUCKNUM; + if (meansum == 0.0) + blocks->luckhistory = 0.0; + else + blocks->luckhistory = lim / meansum; + } + } + b_item = next_in_ktree(ctx); + } + ok = diffacc = netsumm = diffmean = txmean = 0.0; + b_item = last_in_ktree(blocks_root, ctx); + while (b_item) { + DATA_BLOCKS(blocks, b_item); + if (CURRENT(&(blocks->expirydate))) { /* Stats for each blocks are independent of * if they are orphans or not */ if (blocks->netdiff == 0.0) @@ -3108,8 +3138,12 @@ bool check_update_blocks_stats(tv_t *stats) else blocks->diffratio = diffacc / netsumm; - diffmean = ((diffmean * (ok - 1)) + - (blocks->diffcalc / blocks->netdiff)) / ok; + if (blocks->netdiff == 0.0) + diffmean = (diffmean * (ok - 1)) / ok; + else { + diffmean = ((diffmean * (ok - 1)) + + (blocks->diffcalc / blocks->netdiff)) / ok; + } blocks->diffmean = diffmean; if (diffmean == 0.0) { @@ -3121,8 +3155,12 @@ bool check_update_blocks_stats(tv_t *stats) } cr = coinbase_reward(blocks->height); - txmean = ((txmean * (ok - 1)) + - ((double)(blocks->reward) / cr)) / ok; + if (cr == 0.0) + txmean = (txmean * (ok - 1)) / ok; + else { + txmean = ((txmean * (ok - 1)) + + ((double)(blocks->reward) / cr)) / ok; + } blocks->txmean = txmean; } }