From 17f9bdf44728340866fee235fd3f62c9687cafd6 Mon Sep 17 00:00:00 2001 From: kanoi Date: Mon, 28 Sep 2015 19:16:21 +1000 Subject: [PATCH] ckdb - add a lower block limit to when diff change shift ends occur --- pool/page_payout.php | 18 ++++++++----- src/ckdb.c | 63 +++++++++++++++++++++++++++++--------------- src/ckdb.h | 5 ++-- src/ckdb_cmd.c | 3 +-- src/ckdb_data.c | 2 +- 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/pool/page_payout.php b/pool/page_payout.php index 8f7ff36b..b691f1f4 100644 --- a/pool/page_payout.php +++ b/pool/page_payout.php @@ -2,9 +2,10 @@ # function dopayout($data, $user) { - $t = '5'; - $ot = '1/5'; - $n = '5Nd'; + $N = 5; + $t = "$N"; + $ot = "1/$N"; + $n = "${N}Nd"; $n1 = 'N'; $n1d = 'Nd'; $bc = '+101 Confirms'; @@ -13,7 +14,7 @@ function dopayout($data, $user) if (isset($data['info']['currndiff'])) $nd = $data['info']['currndiff']; $nv = number_format($nd, 1); - $nv5 = number_format(5.0*$nd, 1); + $nvx = number_format($N*$nd, 1); $pg = "

Payouts

@@ -41,11 +42,14 @@ Shifts are ~50min or less in length.
Aproximately every 30s, the pool generates new work and sends that to all the miners.
The pool also sends new work every time a block is found on the Bitcoin network.
A shift summarises all the shares submitted to the pool for 100 work changes.
-However, when we find pool blocks, the current shift ends at the work in which the block was found.
-A ckpool restart will also end the current shift and start a new one.

+However, when we find pool blocks, the current shift ends at the work in which the block was found
+and a new shift starts.
+A ckpool restart will also end the current shift and start a new shift.
+Also, a network difficulty change will end the current shift and start a new shift.
+The network difficulty changes every 2016 block or about every 2 weeks.
So, what's the $n value?

-The current Bitcoin network value for $n1d is $nv and thus $n is $nv5
+The current Bitcoin network value for $n1d is $nv and thus $n is $nvx
Bitcoin adjusts the $n1d value every 2016 blocks, which is about every 2 weeks.

When a block is found, the reward process counts back shifts until the total share difficulty included is $n.
Since shares are summarised into shifts, it will include the full shift at the end of the range counting backwards,
diff --git a/src/ckdb.c b/src/ckdb.c index c9525a63..581f1967 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -3154,6 +3154,12 @@ ASSERT4((sizeof(shift_words) == (sizeof(char *) * SHIFT_WORDS))); // Number of workinfoids per shift #define WID_PER_SHIFT 100 +// A diff change will end the current shift if it occurs after this block +#define SHIFT_DIFF_BLOCK 376500 + +// optioncontrol name to override the SHIFT_DIFF_BLOCK value +#define SHIFT_DIFF_BLOCK_STR "ShiftDiffBlock" + static void make_a_shift_mark() { K_TREE_CTX ss_ctx[1], m_ctx[1], wi_ctx[1], b_ctx[1]; @@ -3165,8 +3171,10 @@ static void make_a_shift_mark() BLOCKS *blocks = NULL; MARKS *marks = NULL, *sh_marks = NULL; int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid; + int64_t shiftdiffblock = SHIFT_DIFF_BLOCK; + int32_t height; char wi_bits[TXT_SML+1]; - bool was_block = false, ok; + bool was_block = false, ok, oc_look = true; char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ], cd_buf3[DATE_BUFSIZ]; int used_wid; @@ -3393,28 +3401,41 @@ static void make_a_shift_mark() if (wi_bits[0] == '\0') STRNCPY(wi_bits, workinfo->bits); else { + /* Make sure you set the SHIFT_DIFF_BLOCK_STR + * optioncontrol if you changed ckdb to V1.323 + * before the diff change, before the block= + * SHIFT_DIFF_BLOCK default value + * This however, would only affect a reload + * after that if the reload crossed the + * previous diff change and the shifts had not + * already been stored in the DB (i.e. next to + * zero probability) + * However a DB rollback and reload across that + * diff change would be affected */ + if (oc_look) { + shiftdiffblock = sys_setting(SHIFT_DIFF_BLOCK_STR, + SHIFT_DIFF_BLOCK, + &date_eot); + oc_look = false; + } /* Did difficulty change? * Stop at the last workinfo, before the diff - * changed - * IMPORTANT: this change will create different - * shifts if you were to reload a database, - * that you rolled back from after a diff - * change to before a diff change, if the data - * at the diff change was created with a - * version of ckdb before V1.323 - * THUS if that was the case, then some payouts - * that were generated before the rollback will - * be a small bit different to those created - * after reloading the same data */ + * changed */ if (strcmp(wi_bits, workinfo->bits) != 0) { - LOGDEBUG("%s() OK shift stops at diff" - " change '%s->%s' %"PRId64 - "->%"PRId64, - __func__, wi_bits, - workinfo->bits, prev_wid, - workinfo->workinfoid); - marks_wid = prev_wid; - break; + height = coinbase1height(workinfo->coinbase1); + if (height > (int32_t)shiftdiffblock) { + LOGDEBUG("%s() OK shift stops at diff" + " change '%s->%s' %"PRId64 + "->%"PRId64" height %"PRId32 + " limit %"PRId64, + __func__, wi_bits, + workinfo->bits, prev_wid, + workinfo->workinfoid, + height, + shiftdiffblock); + marks_wid = prev_wid; + break; + } } } /* Did we find a pool restart? i.e. a wid skip @@ -5466,7 +5487,7 @@ int main(int argc, char **argv) memset(&ckp, 0, sizeof(ckp)); ckp.loglevel = LOG_NOTICE; - while ((c = getopt_long(argc, argv, "c:d:hkl:mn:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) { + while ((c = getopt_long(argc, argv, "c:d:ghkl:mn:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) { switch(c) { case 'c': ckp.config = strdup(optarg); diff --git a/src/ckdb.h b/src/ckdb.h index eb454c02..cda98b56 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.333" +#define CKDB_VERSION DB_VERSION"-1.334" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -2286,8 +2286,9 @@ extern cmp_t cmp_accountbalance(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_accountbalance(int64_t userid); extern cmp_t cmp_optioncontrol(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_optioncontrol(char *optionname, const tv_t *now, int32_t height); +#define sys_setting(_name, _def, _now) user_sys_setting(0, _name, _def, _now) extern int64_t user_sys_setting(int64_t userid, char *setting_name, - int64_t setting_default, tv_t *now); + int64_t setting_default, const tv_t *now); extern cmp_t cmp_workinfo(K_ITEM *a, K_ITEM *b); #define coinbase1height(_cb1) _coinbase1height(_cb1, WHERE_FFL_HERE) extern int32_t _coinbase1height(char *coinbase1, WHERE_FFL_ARGS); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 4a757840..d1ec179c 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1156,8 +1156,7 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - // 0 means just the system setting - maxrows = user_sys_setting(0, BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now); + maxrows = sys_setting(BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now); APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC(buf, off, len, "ok."); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 2aa4feb4..dd32fb69 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -1922,7 +1922,7 @@ K_ITEM *find_optioncontrol(char *optionname, const tv_t *now, int32_t height) * i.e. ensure now and pool.height are correct (e.g. during a reload) */ int64_t user_sys_setting(int64_t userid, char *setting_name, - int64_t setting_default, tv_t *now) + int64_t setting_default, const tv_t *now) { OPTIONCONTROL *optioncontrol; K_ITEM *ua_item, *oc_item;