Browse Source

ckdb - correct orphan diff redistribution

master
kanoi 10 years ago
parent
commit
09a5de8e2c
  1. 6
      src/ckdb.h
  2. 10
      src/ckdb_cmd.c
  3. 29
      src/ckdb_data.c

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

10
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),

29
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) {

Loading…
Cancel
Save