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. 70
      src/ckdb_data.c

9
pool/base.php

@ -173,12 +173,15 @@ function btcfmt($amt)
return number_format($amt, 8); return number_format($amt, 8);
} }
# #
function utcd($when, $brief = false) function utcd($when, $brief = false, $zone = true)
{ {
if ($brief) if ($brief)
return gmdate('M-d H:i:s', round($when)); return gmdate('M‑d H:i:s', round($when));
else 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; global $sipre;

18
pool/page_blocks.php

@ -140,6 +140,7 @@ function doblocks($data, $user)
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
{ {
$count = $ans['rows']; $count = $ans['rows'];
$histsiz = $ans['historysize'] . ' ';
if ($count == 1) if ($count == 1)
{ {
$num = ''; $num = '';
@ -154,7 +155,10 @@ function doblocks($data, $user)
$pg .= "<h1>Last$num Block$s</h1>"; $pg .= "<h1>Last$num Block$s</h1>";
} }
else else
{
$histsiz = '';
$pg .= '<h1>Blocks</h1>'; $pg .= '<h1>Blocks</h1>';
}
list($fg, $bg) = pctcolour(25.0); list($fg, $bg) = pctcolour(25.0);
$pg .= "<span style='background:$bg; color:$fg;'>"; $pg .= "<span style='background:$bg; color:$fg;'>";
@ -176,11 +180,12 @@ function doblocks($data, $user)
if ($user !== null) if ($user !== null)
$pg .= "<td class=dl>Who</td>"; $pg .= "<td class=dl>Who</td>";
$pg .= "<td class=dr>Block Reward</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>Status</td>";
$pg .= "<td class=dr>Diff</td>"; $pg .= "<td class=dr>Diff</td>";
$pg .= "<td class=dr>Diff%</td>"; $pg .= "<td class=dr>Diff%</td>";
$pg .= "<td class=dr>CDF</td>"; $pg .= "<td class=dr>CDF</td>";
$pg .= "<td class=dr>${histsiz}Luck%</td>";
$pg .= "<td class=dr>B</td>"; $pg .= "<td class=dr>B</td>";
$pg .= "</tr></thead>\n"; $pg .= "</tr></thead>\n";
} }
@ -286,6 +291,7 @@ function doblocks($data, $user)
$diffratio = $ans['diffratio:'.$i]; $diffratio = $ans['diffratio:'.$i];
$cdf = $ans['cdf:'.$i]; $cdf = $ans['cdf:'.$i];
$luck = $ans['luck:'.$i]; $luck = $ans['luck:'.$i];
$hist = $ans['luckhistory:'.$i];
if ($diffratio > 0) if ($diffratio > 0)
{ {
@ -296,11 +302,13 @@ function doblocks($data, $user)
list($fg, $bg) = pctcolour($colpct); list($fg, $bg) = pctcolour($colpct);
$bpct = "<font color=$fg>$approx".number_format($pct, 3).'%</font>'; $bpct = "<font color=$fg>$approx".number_format($pct, 3).'%</font>';
$bg = " bgcolor=$bg"; $bg = " bgcolor=$bg";
$histdsp = "$approx".number_format(100.0 * $hist, 2).'%';
} }
else else
{ {
$bpct = "$approx".number_format($pct, 3).'%'; $bpct = "$approx".number_format($pct, 3).'%';
$bg = ''; $bg = '';
$histdsp = '&nbsp;';
} }
$blktot += $diffacc; $blktot += $diffacc;
if ($conf != 'O' and $conf != 'R') if ($conf != 'O' and $conf != 'R')
@ -313,6 +321,7 @@ function doblocks($data, $user)
$bg = ''; $bg = '';
$bpct = '?'; $bpct = '?';
$cdfdsp = '?'; $cdfdsp = '?';
$histdsp = '?';
} }
if ($wantcsv === false) if ($wantcsv === false)
@ -323,11 +332,12 @@ function doblocks($data, $user)
if ($user !== null) if ($user !== null)
$pg .= "<td class=dl$ex>".htmlspecialchars($ans['workername:'.$i]).'</td>'; $pg .= "<td class=dl$ex>".htmlspecialchars($ans['workername:'.$i]).'</td>';
$pg .= "<td class=dr$ex>".btcfmt($ans['reward:'.$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$ex>$tt$stat</td>";
$pg .= "<td class=dr>$stara$approx$acc</td>"; $pg .= "<td class=dr>$stara$approx$acc</td>";
$pg .= "<td class=dr$bg>$bpct</td>"; $pg .= "<td class=dr$bg>$bpct</td>";
$pg .= "<td class=dr>$cdfdsp</td>"; $pg .= "<td class=dr>$cdfdsp</td>";
$pg .= "<td class=dr>$histdsp</td>";
$pg .= "<td class=dr>$nn</td>"; $pg .= "<td class=dr>$nn</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
@ -353,9 +363,9 @@ function doblocks($data, $user)
{ {
$pg .= '<tfoot><tr><td colspan='; $pg .= '<tfoot><tr><td colspan=';
if ($user === null) if ($user === null)
$pg .= '7';
else
$pg .= '8'; $pg .= '8';
else
$pg .= '9';
$pg .= ' class=dc><font size=-1><span class=st1>*</span>'; $pg .= ' class=dc><font size=-1><span class=st1>*</span>';
$pg .= 'Orphans/Rejects count as shares but not as a block in calculations'; $pg .= 'Orphans/Rejects count as shares but not as a block in calculations';
$pg .= '</font></td></tr></tfoot>'; $pg .= '</font></td></tr></tfoot>';

7
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.5" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -1960,6 +1960,8 @@ extern K_STORE *sharesummary_store;
extern K_TREE *sharesummary_pool_root; extern K_TREE *sharesummary_pool_root;
extern K_STORE *sharesummary_pool_store; extern K_STORE *sharesummary_pool_store;
#define LUCKNUM 100
// BLOCKS block.id.json={...} // BLOCKS block.id.json={...}
typedef struct blocks { typedef struct blocks {
int32_t height; int32_t height;
@ -2003,6 +2005,9 @@ typedef struct blocks {
double diffmean; double diffmean;
double cdferl; double cdferl;
double luck; 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 // Mean reward ratio per block from last to this
double txmean; double txmean;

19
src/ckdb_cmd.c

@ -1411,18 +1411,22 @@ redo:
if (has_stats) { if (has_stats) {
snprintf(tmp, sizeof(tmp), snprintf(tmp, sizeof(tmp),
"netdiff:%d=%.8f%cdiffratio:%d=%.8f%c" "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->netdiff, FLDSEP,
rows, blocks->blockdiffratio, FLDSEP, rows, blocks->blockdiffratio, FLDSEP,
rows, blocks->blockcdf, FLDSEP, rows, blocks->blockcdf, FLDSEP,
rows, blocks->blockluck, FLDSEP); rows, blocks->blockluck, FLDSEP,
rows, blocks->luckhistory, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
} else { } else {
snprintf(tmp, sizeof(tmp), snprintf(tmp, sizeof(tmp),
"netdiff:%d=?%cdiffratio:%d=?%c" "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, rows, FLDSEP,
rows, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
} }
@ -1515,11 +1519,12 @@ redo:
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), snprintf(tmp, sizeof(tmp),
"rows=%d%cflds=%s%c", "historysize=%d%crows=%d%cflds=%s%c",
rows, FLDSEP, LUCKNUM, FLDSEP, rows, FLDSEP,
"seq,height,blockhash,nonce,reward,workername,first"CDTRF"," "seq,height,blockhash,nonce,reward,workername,first"CDTRF","
CDTRF",prev"CDTRF",confirmed,status,info,statsconf,diffacc," 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); FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);

70
src/ckdb_data.c

@ -3021,42 +3021,36 @@ bool check_update_blocks_stats(tv_t *stats)
WORKINFO *workinfo; WORKINFO *workinfo;
BLOCKS *blocks; BLOCKS *blocks;
double ok, diffacc, netsumm, diffmean, pending, txmean, cr; double ok, diffacc, netsumm, diffmean, pending, txmean, cr;
double meansum, meanall[LUCKNUM];
bool ret = false; bool ret = false;
tv_t now; tv_t now;
int i, lim;
/* Wait for startup_complete rather than db_load_complete /* Wait for startup_complete rather than db_load_complete
* This avoids doing a 'long' lock stats update while reloading */ * This avoids doing a 'long' lock stats update while reloading */
if (!startup_complete) if (!startup_complete)
return false; return false;
for (i = 0; i < LUCKNUM; i++)
meanall[i] = 0.0;
K_RLOCK(workinfo_free); K_RLOCK(workinfo_free);
K_WLOCK(blocks_free); K_WLOCK(blocks_free);
if (blocks_stats_rebuild) { if (blocks_stats_rebuild) {
/* Have to first work out the diffcalc for each block /* Have to first work out the diffcalc for each block
* Orphans count towards the next valid block after the orphan * Orphans count towards the next valid block after the orphan
* so this has to be done in the reverse order of the range * 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; pending = 0.0;
ok = 0;
b_item = first_in_ktree(blocks_root, ctx); b_item = first_in_ktree(blocks_root, ctx);
while (b_item) { while (b_item) {
DATA_BLOCKS(blocks, b_item); DATA_BLOCKS(blocks, b_item);
if (CURRENT(&(blocks->expirydate))) { if (CURRENT(&(blocks->expirydate))) {
pending += blocks->diffacc; 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) { if (blocks->netdiff == 0) {
w_item = _find_workinfo(blocks->workinfoid, true, NULL); w_item = _find_workinfo(blocks->workinfoid, true, NULL);
if (!w_item) { if (!w_item) {
@ -3076,6 +3070,42 @@ bool check_update_blocks_stats(tv_t *stats)
DATA_WORKINFO(workinfo, w_item); DATA_WORKINFO(workinfo, w_item);
blocks->netdiff = workinfo->diff_target; 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 /* Stats for each blocks are independent of
* if they are orphans or not */ * if they are orphans or not */
if (blocks->netdiff == 0.0) if (blocks->netdiff == 0.0)
@ -3108,8 +3138,12 @@ bool check_update_blocks_stats(tv_t *stats)
else else
blocks->diffratio = diffacc / netsumm; blocks->diffratio = diffacc / netsumm;
if (blocks->netdiff == 0.0)
diffmean = (diffmean * (ok - 1)) / ok;
else {
diffmean = ((diffmean * (ok - 1)) + diffmean = ((diffmean * (ok - 1)) +
(blocks->diffcalc / blocks->netdiff)) / ok; (blocks->diffcalc / blocks->netdiff)) / ok;
}
blocks->diffmean = diffmean; blocks->diffmean = diffmean;
if (diffmean == 0.0) { if (diffmean == 0.0) {
@ -3121,8 +3155,12 @@ bool check_update_blocks_stats(tv_t *stats)
} }
cr = coinbase_reward(blocks->height); cr = coinbase_reward(blocks->height);
if (cr == 0.0)
txmean = (txmean * (ok - 1)) / ok;
else {
txmean = ((txmean * (ok - 1)) + txmean = ((txmean * (ok - 1)) +
((double)(blocks->reward) / cr)) / ok; ((double)(blocks->reward) / cr)) / ok;
}
blocks->txmean = txmean; blocks->txmean = txmean;
} }
} }

Loading…
Cancel
Save