Browse Source

ckdb/php - add some block stats to workers

master
kanoi 10 years ago
parent
commit
e44de0112b
  1. 8
      pool/page_allwork.php
  2. 37
      pool/page_workers.php
  3. 14
      src/ckdb.c

8
pool/page_allwork.php

@ -13,6 +13,8 @@ function doallwork($data, $user)
$totinvalid = 0; $totinvalid = 0;
$totrate = 0; $totrate = 0;
$offset = 0; $offset = 0;
$blockacc = 0;
$blockreward = 0;
$pg .= worktitle($data, $user); $pg .= worktitle($data, $user);
@ -24,11 +26,13 @@ function doallwork($data, $user)
{ {
$pg .= workuser($data, $ans['username:'.$i], $pg .= workuser($data, $ans['username:'.$i],
$offset, $totshare, $totdiff, $offset, $totshare, $totdiff,
$totinvalid, $totrate, 3600); $totinvalid, $totrate,
$blockacc, $blockreward, 3600);
} }
} }
$pg .= worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate); $pg .= worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate,
$blockacc, $blockreward);
$pg .= "</table>\n"; $pg .= "</table>\n";

37
pool/page_workers.php

@ -9,19 +9,25 @@ function worktitle($data, $user)
$pg .= '<td class=dr>Shares</td>'; $pg .= '<td class=dr>Shares</td>';
$pg .= '<td class=dr>Diff</td>'; $pg .= '<td class=dr>Diff</td>';
$pg .= '<td class=dr>Invalid</td>'; $pg .= '<td class=dr>Invalid</td>';
$pg .= '<td class=dr>Block %</td>';
$pg .= '<td class=dr>Hash Rate</td>'; $pg .= '<td class=dr>Hash Rate</td>';
$pg .= "</tr>\n"; $pg .= "</tr>\n";
return $pg; return $pg;
} }
# #
function workuser($data, $user, &$offset, &$totshare, &$totdiff, function workuser($data, $user, &$offset, &$totshare, &$totdiff,
&$totinvalid, &$totrate, $old = false) &$totinvalid, &$totrate, &$blockacc,
&$blockreward, $old = false)
{ {
$ans = getWorkers($user); $ans = getWorkers($user);
$pg = ''; $pg = '';
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
{ {
if (isset($ans['blockacc']))
$blockacc = $ans['blockacc'];
if (isset($ans['blockreward']))
$blockreward = $ans['blockreward'];
$count = $ans['rows']; $count = $ans['rows'];
for ($i = 0; $i < $count; $i++) for ($i = 0; $i < $count; $i++)
{ {
@ -60,6 +66,13 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$pg .= "<td class=dr>$rej%</td>"; $pg .= "<td class=dr>$rej%</td>";
if ($blockacc <= 0)
$blkpct = '&nbsp;';
else
$blkpct = number_format(100.0 * $ans['w_diffacc:'.$i] / $blockacc, 3) . '%';
$pg .= "<td class=dr>$blkpct</td>";
if ($ans['w_elapsed:'.$i] > 3600) if ($ans['w_elapsed:'.$i] > 3600)
$uhr = $ans['w_hashrate1hr:'.$i]; $uhr = $ans['w_hashrate1hr:'.$i];
else else
@ -90,7 +103,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
return $pg; return $pg;
} }
# #
function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate) function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate, $blockacc, $blockreward)
{ {
$pg = ''; $pg = '';
$totrate /= 10000000; $totrate /= 10000000;
@ -118,6 +131,11 @@ function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate)
else else
$rej = '0'; $rej = '0';
$pg .= "<td class=dr>$rej%</td>"; $pg .= "<td class=dr>$rej%</td>";
if ($blockacc <= 0)
$blkpct = '&nbsp;';
else
$blkpct = number_format(100.0 * $totdiff / $blockacc, 3) . '%';
$pg .= "<td class=dr>$blkpct</td>";
$pg .= "<td class=dr>$totrate</td></tr>\n"; $pg .= "<td class=dr>$totrate</td></tr>\n";
return $pg; return $pg;
} }
@ -133,11 +151,22 @@ function doworker($data, $user)
$totinvalid = 0; $totinvalid = 0;
$totrate = 0; $totrate = 0;
$offset = 0; $offset = 0;
$blockacc = 0;
$blockreward = 0;
$pg .= worktitle($data, $user); $pg .= worktitle($data, $user);
$pg .= workuser($data, $user, $offset, $totshare, $totdiff, $totinvalid, $pg .= workuser($data, $user, $offset, $totshare, $totdiff, $totinvalid,
$totrate, false); $totrate, $blockacc, $blockreward, false);
$pg .= worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate); $pg .= worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate,
$blockacc, $blockreward);
if ($blockacc > 0 && $blockreward > 0)
{
$btc = btcfmt($totdiff / $blockacc * $blockreward);
$pg .= '<tr><td colspan=8 class=dc>';
$pg .= "<br>Payout est if block found at 100%: ~$btc BTC";
$pg .= '</td></tr>';
}
$pg .= "</table>\n"; $pg .= "</table>\n";

14
src/ckdb.c

@ -49,7 +49,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.2" #define DB_VERSION "0.9.2"
#define CKDB_VERSION DB_VERSION"-0.331" #define CKDB_VERSION DB_VERSION"-0.332"
#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__
@ -240,13 +240,14 @@ static LOADSTATUS dbstatus;
typedef struct poolstatus { typedef struct poolstatus {
int64_t workinfoid; // Last block int64_t workinfoid; // Last block
int32_t height; int32_t height;
int64_t reward;
double diffacc; double diffacc;
double diffinv; // Non-acc double diffinv; // Non-acc
double shareacc; double shareacc;
double shareinv; // Non-acc double shareinv; // Non-acc
double best_sdiff; // TODO (maybe) double best_sdiff; // TODO (maybe)
} POOLSTATUS; } POOLSTATUS;
static POOLSTATUS pool = { 0, START_POOL_HEIGHT, 0, 0, 0, 0, 0 }; static POOLSTATUS pool = { 0, START_POOL_HEIGHT, 0, 0, 0, 0, 0, 0 };
/* TODO: when we know about orphans, the count reset to zero /* TODO: when we know about orphans, the count reset to zero
* will need to be undone - i.e. recalculate this data from * will need to be undone - i.e. recalculate this data from
* the memory tables - maybe ... */ * the memory tables - maybe ... */
@ -4994,6 +4995,7 @@ static int64_t workinfo_add(PGconn *conn, char *workinfoidstr, char *poolinstanc
STRNCPY(row->bits, bits); STRNCPY(row->bits, bits);
STRNCPY(row->ntime, ntime); STRNCPY(row->ntime, ntime);
TXT_TO_BIGINT("reward", reward, row->reward); TXT_TO_BIGINT("reward", reward, row->reward);
pool.reward = row->reward;
HISTORYDATEINIT(row, cd, by, code, inet); HISTORYDATEINIT(row, cd, by, code, inet);
HISTORYDATETRANSFER(trf_root, row); HISTORYDATETRANSFER(trf_root, row);
@ -5524,6 +5526,7 @@ static bool workinfo_fill(PGconn *conn)
if (!ok) if (!ok)
break; break;
TXT_TO_BIGINT("reward", field, row->reward); TXT_TO_BIGINT("reward", field, row->reward);
pool.reward = row->reward;
HISTORYDATEFLDS(res, i, row, ok); HISTORYDATEFLDS(res, i, row, ok);
if (!ok) if (!ok)
@ -9795,6 +9798,13 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
DATA_WORKERS_NULL(workers, w_item); DATA_WORKERS_NULL(workers, w_item);
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
APPEND_REALLOC(buf, off, len, "ok."); APPEND_REALLOC(buf, off, len, "ok.");
snprintf(tmp, sizeof(tmp), "blockacc=%.1f%c",
pool.diffacc, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "blockreward=%"PRId64"%c",
pool.reward, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
rows = 0; rows = 0;
while (w_item && workers->userid == users->userid) { while (w_item && workers->userid == users->userid) {
if (CURRENT(&(workers->expirydate))) { if (CURRENT(&(workers->expirydate))) {

Loading…
Cancel
Save