Browse Source

ckdb/php - add a block timestamp to the rewards page

master
kanoi 9 years ago
parent
commit
87b8a187f9
  1. 4
      pool/page_mpayouts.php
  2. 1
      src/ckdb.c
  3. 4
      src/ckdb.h
  4. 7
      src/ckdb_cmd.c
  5. 50
      src/ckdb_data.c
  6. 27
      src/ckdb_dbio.c

4
pool/page_mpayouts.php

@ -14,6 +14,7 @@ function dompayouts($data, $user)
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>";
$pg .= "<td class=dr>Block</td>";
$pg .= "<td class=dr>Block UTC</td>";
$pg .= "<td class=dr>Miner Reward</td>";
$pg .= "<td class=dr>N Diff</td>";
$pg .= "<td class=dr>N Range</td>";
@ -36,6 +37,7 @@ function dompayouts($data, $user)
$pg .= "<tr class=$row>";
$pg .= '<td class=dr>'.$ans['height:'.$i].'</td>';
$pg .= '<td class=dr>'.gmdate('d/M H:i',$ans['blockcreatedate:'.$i]).'</td>';
$pg .= '<td class=dr>'.btcfmt($ans['minerreward:'.$i]).'</td>';
$diffused = $ans['diffused:'.$i];
$pg .= '<td class=dr>'.difffmt($diffused).'</td>';
@ -63,7 +65,7 @@ function dompayouts($data, $user)
$pg .= "<tr class=$row>";
$pg .= '<td class=dr>Total:</td>';
$pg .= '<td class=dl colspan=7></td>';
$pg .= '<td class=dl colspan=8></td>';
$pg .= '<td class=dr>'.btcfmt($totamt).'</td>';
$pg .= "</tr>\n";
}

1
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)

4
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();

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

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

27
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);

Loading…
Cancel
Save