Browse Source

ckdb - add a lower block limit to when diff change shift ends occur

master
kanoi 9 years ago
parent
commit
17f9bdf447
  1. 18
      pool/page_payout.php
  2. 63
      src/ckdb.c
  3. 5
      src/ckdb.h
  4. 3
      src/ckdb_cmd.c
  5. 2
      src/ckdb_data.c

18
pool/page_payout.php

@ -2,9 +2,10 @@
# #
function dopayout($data, $user) function dopayout($data, $user)
{ {
$t = '<span class=nn>5</span>'; $N = 5;
$ot = '<span class=nn>1/5</span>'; $t = "<span class=nn>$N</span>";
$n = '<span class=nn>5Nd</span>'; $ot = "<span class=nn>1/$N</span>";
$n = "<span class=nn>${N}Nd</span>";
$n1 = '<span class=nn>N</span>'; $n1 = '<span class=nn>N</span>';
$n1d = '<span class=nn>Nd</span>'; $n1d = '<span class=nn>Nd</span>';
$bc = '+101 Confirms'; $bc = '+101 Confirms';
@ -13,7 +14,7 @@ function dopayout($data, $user)
if (isset($data['info']['currndiff'])) if (isset($data['info']['currndiff']))
$nd = $data['info']['currndiff']; $nd = $data['info']['currndiff'];
$nv = number_format($nd, 1); $nv = number_format($nd, 1);
$nv5 = number_format(5.0*$nd, 1); $nvx = number_format($N*$nd, 1);
$pg = "<h1>Payouts</h1> $pg = "<h1>Payouts</h1>
<table width=75% cellpadding=0 cellspacing=0 border=0><tr><td> <table width=75% cellpadding=0 cellspacing=0 border=0><tr><td>
@ -41,11 +42,14 @@ Shifts are ~50min or less in length.<br>
Aproximately every 30s, the pool generates new work and sends that to all the miners.<br> Aproximately every 30s, the pool generates new work and sends that to all the miners.<br>
The pool also sends new work every time a block is found on the Bitcoin network.<br> The pool also sends new work every time a block is found on the Bitcoin network.<br>
A shift summarises all the shares submitted to the pool for 100 work changes.<br> A shift summarises all the shares submitted to the pool for 100 work changes.<br>
However, when we find pool blocks, the current shift ends at the work in which the block was found.<br> However, when we find pool blocks, the current shift ends at the work in which the block was found<br>
A ckpool restart will also end the current shift and start a new one.<br><br> and a new shift starts.<br>
A ckpool restart will also end the current shift and start a new shift.<br>
Also, a network difficulty change will end the current shift and start a new shift.<br>
The network difficulty changes every 2016 block or about every 2 weeks.<br>
<span class=hdr>So, what's the $n value?</span><br><br> <span class=hdr>So, what's the $n value?</span><br><br>
The current Bitcoin network value for $n1d is $nv and thus $n is <b>$nv5</b><br> The current Bitcoin network value for $n1d is $nv and thus $n is <b>$nvx</b><br>
Bitcoin adjusts the $n1d value every 2016 blocks, which is about every 2 weeks.<br><br> Bitcoin adjusts the $n1d value every 2016 blocks, which is about every 2 weeks.<br><br>
When a block is found, the reward process counts back shifts until the total share difficulty included is $n.<br> When a block is found, the reward process counts back shifts until the total share difficulty included is $n.<br>
Since shares are summarised into shifts, it will include the full shift at the end of the range counting backwards,<br> Since shares are summarised into shifts, it will include the full shift at the end of the range counting backwards,<br>

63
src/ckdb.c

@ -3154,6 +3154,12 @@ ASSERT4((sizeof(shift_words) == (sizeof(char *) * SHIFT_WORDS)));
// Number of workinfoids per shift // Number of workinfoids per shift
#define WID_PER_SHIFT 100 #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() static void make_a_shift_mark()
{ {
K_TREE_CTX ss_ctx[1], m_ctx[1], wi_ctx[1], b_ctx[1]; 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; BLOCKS *blocks = NULL;
MARKS *marks = NULL, *sh_marks = NULL; MARKS *marks = NULL, *sh_marks = NULL;
int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid; 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]; 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]; char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ], cd_buf3[DATE_BUFSIZ];
int used_wid; int used_wid;
@ -3393,28 +3401,41 @@ static void make_a_shift_mark()
if (wi_bits[0] == '\0') if (wi_bits[0] == '\0')
STRNCPY(wi_bits, workinfo->bits); STRNCPY(wi_bits, workinfo->bits);
else { 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? /* Did difficulty change?
* Stop at the last workinfo, before the diff * Stop at the last workinfo, before the diff
* changed * 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 */
if (strcmp(wi_bits, workinfo->bits) != 0) { if (strcmp(wi_bits, workinfo->bits) != 0) {
LOGDEBUG("%s() OK shift stops at diff" height = coinbase1height(workinfo->coinbase1);
" change '%s->%s' %"PRId64 if (height > (int32_t)shiftdiffblock) {
"->%"PRId64, LOGDEBUG("%s() OK shift stops at diff"
__func__, wi_bits, " change '%s->%s' %"PRId64
workinfo->bits, prev_wid, "->%"PRId64" height %"PRId32
workinfo->workinfoid); " limit %"PRId64,
marks_wid = prev_wid; __func__, wi_bits,
break; workinfo->bits, prev_wid,
workinfo->workinfoid,
height,
shiftdiffblock);
marks_wid = prev_wid;
break;
}
} }
} }
/* Did we find a pool restart? i.e. a wid skip /* 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)); memset(&ckp, 0, sizeof(ckp));
ckp.loglevel = LOG_NOTICE; 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) { switch(c) {
case 'c': case 'c':
ckp.config = strdup(optarg); ckp.config = strdup(optarg);

5
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.3" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #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 K_ITEM *find_accountbalance(int64_t userid);
extern cmp_t cmp_optioncontrol(K_ITEM *a, K_ITEM *b); 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); 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, 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); extern cmp_t cmp_workinfo(K_ITEM *a, K_ITEM *b);
#define coinbase1height(_cb1) _coinbase1height(_cb1, WHERE_FFL_HERE) #define coinbase1height(_cb1) _coinbase1height(_cb1, WHERE_FFL_HERE)
extern int32_t _coinbase1height(char *coinbase1, WHERE_FFL_ARGS); extern int32_t _coinbase1height(char *coinbase1, WHERE_FFL_ARGS);

3
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); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
// 0 means just the system setting maxrows = sys_setting(BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now);
maxrows = user_sys_setting(0, BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now);
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
APPEND_REALLOC(buf, off, len, "ok."); APPEND_REALLOC(buf, off, len, "ok.");

2
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) * 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 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; OPTIONCONTROL *optioncontrol;
K_ITEM *ua_item, *oc_item; K_ITEM *ua_item, *oc_item;

Loading…
Cancel
Save