From 09a5de8e2cda85edbbe18f33b536a37f1b92409a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 12 Mar 2015 16:24:07 +1100 Subject: [PATCH] ckdb - correct orphan diff redistribution --- src/ckdb.h | 6 +++++- src/ckdb_cmd.c | 10 ++++++---- src/ckdb_data.c | 29 +++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index e59f475a..ecddeebc 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.022" +#define CKDB_VERSION DB_VERSION"-1.023" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1113,6 +1113,10 @@ typedef struct blocks { double blockcdf; double blockluck; + /* diffacc for range calculations - includes orphans before it + * orphans have this set to 0 so they can't be double counted */ + double diffcalc; + /* From the last found block to this one * Orphans have these set to zero */ double diffratio; diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 8dbc872b..80b1f9d1 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -960,10 +960,12 @@ redo: desc = "Last 5"; } else if (seq == tot - 9) { desc = "Last 10"; - } else if (seq == tot - 19) { - desc = "Last 20"; - } else if (seq == tot - 41) { - desc = "Last 42"; + } else if (seq == tot - 24) { + desc = "Last 25"; + } else if (seq == tot - 49) { + desc = "Last 50"; + } else if (seq == tot - 99) { + desc = "Last 100"; } if (desc) { snprintf(tmp, sizeof(tmp), diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 5d9907f6..a4227e7e 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2425,7 +2425,26 @@ bool check_update_blocks_stats(tv_t *stats) return false; if (blocks_stats_rebuild) { - ok = diffacc = netsumm = diffmean = pending = 0.0; + /* 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 */ + pending = 0.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->diffcalc = 0.0; + else { + blocks->diffcalc = pending; + pending = 0.0; + } + } + b_item = next_in_ktree(ctx); + } + ok = diffacc = netsumm = diffmean = 0.0; b_item = last_in_ktree(blocks_root, ctx); while (b_item) { DATA_BLOCKS(blocks, b_item); @@ -2453,8 +2472,6 @@ bool check_update_blocks_stats(tv_t *stats) hex2bin(ndiffbin, workinfo->bits, 4); blocks->netdiff = diff_from_nbits(ndiffbin); } - pending += blocks->diffacc; - /* Stats for each blocks are independent of * if they are orphans or not */ if (blocks->netdiff == 0.0) @@ -2477,8 +2494,7 @@ bool check_update_blocks_stats(tv_t *stats) blocks->luck = 0.0; } else { ok++; - diffacc += pending; - pending = 0.0; + diffacc += blocks->diffcalc; netsumm += blocks->netdiff; if (netsumm == 0.0) @@ -2486,7 +2502,8 @@ bool check_update_blocks_stats(tv_t *stats) else blocks->diffratio = diffacc / netsumm; - diffmean = (diffmean * (ok - 1) + blocks->blockdiffratio) / ok; + diffmean = ((diffmean * (ok - 1)) + + (blocks->diffcalc / blocks->netdiff)) / ok; blocks->diffmean = diffmean; if (diffmean == 0.0) {