Browse Source

ckdb/php - add 100 block luck history to the blocks page

master
kanoi 9 years ago
parent
commit
ba69ac6a45
  1. 9
      pool/base.php
  2. 18
      pool/page_blocks.php
  3. 7
      src/ckdb.h
  4. 19
      src/ckdb_cmd.c
  5. 78
      src/ckdb_data.c

9
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;

18
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 .= "<h1>Last$num Block$s</h1>";
}
else
{
$histsiz = '';
$pg .= '<h1>Blocks</h1>';
}
list($fg, $bg) = pctcolour(25.0);
$pg .= "<span style='background:$bg; color:$fg;'>";
@ -176,11 +180,12 @@ function doblocks($data, $user)
if ($user !== null)
$pg .= "<td class=dl>Who</td>";
$pg .= "<td class=dr>Block Reward</td>";
$pg .= "<td class=dc>When</td>";
$pg .= "<td class=dc>When UTC</td>";
$pg .= "<td class=dr>Status</td>";
$pg .= "<td class=dr>Diff</td>";
$pg .= "<td class=dr>Diff%</td>";
$pg .= "<td class=dr>CDF</td>";
$pg .= "<td class=dr>${histsiz}Luck%</td>";
$pg .= "<td class=dr>B</td>";
$pg .= "</tr></thead>\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 = "<font color=$fg>$approx".number_format($pct, 3).'%</font>';
$bg = " bgcolor=$bg";
$histdsp = "$approx".number_format(100.0 * $hist, 2).'%';
}
else
{
$bpct = "$approx".number_format($pct, 3).'%';
$bg = '';
$histdsp = '&nbsp;';
}
$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 .= "<td class=dl$ex>".htmlspecialchars($ans['workername:'.$i]).'</td>';
$pg .= "<td class=dr$ex>".btcfmt($ans['reward:'.$i]).'</td>';
$pg .= "<td class=dl$ex>".utcd($ans['firstcreatedate:'.$i]).'</td>';
$pg .= "<td class=dl$ex>".utcd($ans['firstcreatedate:'.$i], false, false).'</td>';
$pg .= "<td class=dr$ex>$tt$stat</td>";
$pg .= "<td class=dr>$stara$approx$acc</td>";
$pg .= "<td class=dr$bg>$bpct</td>";
$pg .= "<td class=dr>$cdfdsp</td>";
$pg .= "<td class=dr>$histdsp</td>";
$pg .= "<td class=dr>$nn</td>";
$pg .= "</tr>\n";
}
@ -353,9 +363,9 @@ function doblocks($data, $user)
{
$pg .= '<tfoot><tr><td colspan=';
if ($user === null)
$pg .= '7';
else
$pg .= '8';
else
$pg .= '9';
$pg .= ' class=dc><font size=-1><span class=st1>*</span>';
$pg .= 'Orphans/Rejects count as shares but not as a block in calculations';
$pg .= '</font></td></tr></tfoot>';

7
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "1.0.5"
#define CKDB_VERSION DB_VERSION"-2.103"
#define CKDB_VERSION DB_VERSION"-2.104"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -1960,6 +1960,8 @@ extern K_STORE *sharesummary_store;
extern K_TREE *sharesummary_pool_root;
extern K_STORE *sharesummary_pool_store;
#define LUCKNUM 100
// BLOCKS block.id.json={...}
typedef struct blocks {
int32_t height;
@ -2003,6 +2005,9 @@ typedef struct blocks {
double diffmean;
double cdferl;
double luck;
/* Last LUCKNUM block luck - or
* back to the first block if there aren't LUCKNUM blocks before it */
double luckhistory;
// Mean reward ratio per block from last to this
double txmean;

19
src/ckdb_cmd.c

@ -1411,18 +1411,22 @@ redo:
if (has_stats) {
snprintf(tmp, sizeof(tmp),
"netdiff:%d=%.8f%cdiffratio:%d=%.8f%c"
"cdf:%d=%.8f%cluck:%d=%.8f%c",
"cdf:%d=%.8f%cluck:%d=%.8f%c"
"luckhistory:%d=%.8f%c",
rows, blocks->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);

78
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;
}
}

Loading…
Cancel
Save