From 7b9233054a6a757e161f4b95d20d643e688d0e53 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 1 Oct 2015 17:00:02 +1000 Subject: [PATCH] ckdb/php - add block reward mean to block stats --- pool/page_blocks.php | 3 +++ src/ckdb.c | 2 +- src/ckdb.h | 6 +++++- src/ckdb_cmd.c | 8 +++++--- src/ckdb_data.c | 27 +++++++++++++++++++++------ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/pool/page_blocks.php b/pool/page_blocks.php index e8d473bd..86e923b4 100644 --- a/pool/page_blocks.php +++ b/pool/page_blocks.php @@ -98,6 +98,7 @@ function doblocks($data, $user) $pg .= "Mean%"; $pg .= "CDF[Erl]"; $pg .= "Luck%"; + $pg .= "MeanTx%"; $pg .= "\n"; $since = $data['info']['lastblock']; @@ -121,6 +122,7 @@ function doblocks($data, $user) $bg = " bgcolor=$bg"; $luck = number_format(100 * $ans['s_luck:'.$i], 2); + $txm = number_format(100 * $ans['s_txmean:'.$i], 1); $pg .= ""; $pg .= "$desc Blocks"; @@ -129,6 +131,7 @@ function doblocks($data, $user) $pg .= "$mean%"; $pg .= "$cdferldsp"; $pg .= "$luck%"; + $pg .= "$txm%"; $pg .= "\n"; } $pg .= "\n"; diff --git a/src/ckdb.c b/src/ckdb.c index 0143a0c3..909e5b41 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -4621,7 +4621,7 @@ static bool reload_from(tv_t *start) /* Used by marker() to start mark generation during a longer * than normal reload */ if (count > RELOAD_N_COUNT) { - if (--file_N_limit < 1) + if (file_N_limit-- < 1) reloaded_N_files = true; } diff --git a/src/ckdb.h b/src/ckdb.h index 94ac6fbc..2dd2d5a7 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.3" -#define CKDB_VERSION DB_VERSION"-1.401" +#define CKDB_VERSION DB_VERSION"-1.402" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1514,6 +1514,9 @@ typedef struct blocks { double cdferl; double luck; + // Mean reward ratio per block from last to this + double txmean; + // To save looking them up when needed tv_t prevcreatedate; // non-DB field tv_t blockcreatedate; // non-DB field @@ -2303,6 +2306,7 @@ extern bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code, char *inet, tv_t *cd, tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, int64_t *s_count, int64_t *s_diff); +extern double coinbase_reward(int32_t height); extern double workinfo_pps(K_ITEM *w_item, int64_t workinfoid, bool lock); extern cmp_t cmp_shares(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_shareerrors(K_ITEM *a, K_ITEM *b); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 2a6fd845..f5669b95 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1329,7 +1329,8 @@ redo: "s_diffratio:%d=%.8f%c" "s_diffmean:%d=%.8f%c" "s_cdferl:%d=%.8f%c" - "s_luck:%d=%.8f%c", + "s_luck:%d=%.8f%c" + "s_txmean:%d=%.8f%c", srows, seq, FLDSEP, srows, desc, FLDSEP, srows, (int)(blocks->height), FLDSEP, @@ -1338,7 +1339,8 @@ redo: srows, blocks->diffratio, FLDSEP, srows, blocks->diffmean, FLDSEP, srows, blocks->cdferl, FLDSEP, - srows, blocks->luck, FLDSEP); + srows, blocks->luck, FLDSEP, + srows, blocks->txmean, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); srows++; } @@ -1367,7 +1369,7 @@ redo: "s_rows=%d%cs_flds=%s%c", srows, FLDSEP, "s_seq,s_desc,s_height,s_"CDTRF",s_prev"CDTRF",s_diffratio," - "s_diffmean,s_cdferl,s_luck", + "s_diffmean,s_cdferl,s_luck,s_txmean", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 5a98946e..ff6f102c 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2235,6 +2235,15 @@ bye: return ok; } +// Block height coinbase reward value +double coinbase_reward(int32_t height) +{ + double value; + + value = REWARD_BASE * pow(0.5, floor((double)height / REWARD_HALVE)); + + return(value); +} // The PPS value of a 1diff share for the given workinfoid double workinfo_pps(K_ITEM *w_item, int64_t workinfoid, bool lock) @@ -2246,7 +2255,7 @@ double workinfo_pps(K_ITEM *w_item, int64_t workinfoid, bool lock) char ndiffbin[TXT_SML+1]; WORKINFO *workinfo; double w_diff; - int w_blocknum; + int32_t w_blocknum; size_t len; // Allow optioncontrol override for a given workinfoid @@ -2284,10 +2293,10 @@ double workinfo_pps(K_ITEM *w_item, int64_t workinfoid, bool lock) w_diff = diff_from_nbits(ndiffbin); hex2bin(coinbase1bin, workinfo->coinbase1 + (BLOCKNUM_OFFSET * 2), (len - (BLOCKNUM_OFFSET * 2)) >> 1); - w_blocknum = get_sernumber((uchar *)coinbase1bin); + w_blocknum = (int32_t)get_sernumber((uchar *)coinbase1bin); - // BASE halving to determine coinbase reward then divided by difficulty - return(REWARD_BASE * pow(0.5, floor((double)w_blocknum / REWARD_HALVE)) / w_diff); + // PPS 1diff is worth coinbase reward divided by difficulty + return(coinbase_reward(w_blocknum) / w_diff); } // order by workinfoid asc,userid asc,workername asc,createdate asc,nonce asc,expirydate desc @@ -2965,7 +2974,7 @@ bool check_update_blocks_stats(tv_t *stats) WORKINFO *workinfo; BLOCKS *blocks; char ndiffbin[TXT_SML+1]; - double ok, diffacc, netsumm, diffmean, pending; + double ok, diffacc, netsumm, diffmean, pending, txmean, cr; tv_t now; /* Wait for startup_complete rather than db_load_complete @@ -2994,7 +3003,7 @@ bool check_update_blocks_stats(tv_t *stats) } b_item = next_in_ktree(ctx); } - ok = diffacc = netsumm = diffmean = 0.0; + ok = diffacc = netsumm = diffmean = 0.0, txmean = 0.0; b_item = last_in_ktree(blocks_root, ctx); while (b_item) { DATA_BLOCKS(blocks, b_item); @@ -3043,6 +3052,7 @@ bool check_update_blocks_stats(tv_t *stats) blocks->diffmean = 0.0; blocks->cdferl = 0.0; blocks->luck = 0.0; + blocks->txmean = 0.0; } else { ok++; diffacc += blocks->diffcalc; @@ -3064,6 +3074,11 @@ bool check_update_blocks_stats(tv_t *stats) blocks->cdferl = gsl_cdf_gamma_P(diffmean, ok, 1.0 / ok); blocks->luck = 1.0 / diffmean; } + + cr = coinbase_reward(blocks->height); + txmean = ((txmean * (ok - 1)) + + ((double)(blocks->reward) / cr)) / ok; + blocks->txmean = txmean; } } b_item = prev_in_ktree(ctx);