|
|
@ -815,7 +815,7 @@ cmp_t cmp_workerstatus(K_ITEM *a, K_ITEM *b) |
|
|
|
/* TODO: replace a lot of the code for all data types that codes finds,
|
|
|
|
/* TODO: replace a lot of the code for all data types that codes finds,
|
|
|
|
* each with specific functions for finding, to centralise the finds, |
|
|
|
* each with specific functions for finding, to centralise the finds, |
|
|
|
* with passed ctx's */ |
|
|
|
* with passed ctx's */ |
|
|
|
K_ITEM *get_workerstatus(int64_t userid, char *workername) |
|
|
|
K_ITEM *get_workerstatus(bool lock, int64_t userid, char *workername) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WORKERSTATUS workerstatus; |
|
|
|
WORKERSTATUS workerstatus; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
@ -826,8 +826,10 @@ K_ITEM *get_workerstatus(int64_t userid, char *workername) |
|
|
|
|
|
|
|
|
|
|
|
INIT_WORKERSTATUS(&look); |
|
|
|
INIT_WORKERSTATUS(&look); |
|
|
|
look.data = (void *)(&workerstatus); |
|
|
|
look.data = (void *)(&workerstatus); |
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_RLOCK(workerstatus_free); |
|
|
|
K_RLOCK(workerstatus_free); |
|
|
|
find = find_in_ktree(workerstatus_root, &look, ctx); |
|
|
|
find = find_in_ktree(workerstatus_root, &look, ctx); |
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_RUNLOCK(workerstatus_free); |
|
|
|
K_RUNLOCK(workerstatus_free); |
|
|
|
return find; |
|
|
|
return find; |
|
|
|
} |
|
|
|
} |
|
|
@ -839,7 +841,7 @@ K_ITEM *get_workerstatus(int64_t userid, char *workername) |
|
|
|
* This has 2 sets of file/func/line to allow 2 levels of traceback |
|
|
|
* This has 2 sets of file/func/line to allow 2 levels of traceback |
|
|
|
* to see why it happened |
|
|
|
* to see why it happened |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, |
|
|
|
K_ITEM *_find_create_workerstatus(bool lock, int64_t userid, char *workername, |
|
|
|
bool create, const char *file2, |
|
|
|
bool create, const char *file2, |
|
|
|
const char *func2, const int line2, |
|
|
|
const char *func2, const int line2, |
|
|
|
WHERE_FFL_ARGS) |
|
|
|
WHERE_FFL_ARGS) |
|
|
@ -849,7 +851,7 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, |
|
|
|
bool ws_err = false, w_err = false; |
|
|
|
bool ws_err = false, w_err = false; |
|
|
|
tv_t now; |
|
|
|
tv_t now; |
|
|
|
|
|
|
|
|
|
|
|
ws_item = get_workerstatus(userid, workername); |
|
|
|
ws_item = get_workerstatus(lock, userid, workername); |
|
|
|
if (!ws_item) { |
|
|
|
if (!ws_item) { |
|
|
|
if (!create) { |
|
|
|
if (!create) { |
|
|
|
ws_err = true; |
|
|
|
ws_err = true; |
|
|
@ -858,7 +860,8 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, |
|
|
|
if (!w_item) { |
|
|
|
if (!w_item) { |
|
|
|
w_err = true; |
|
|
|
w_err = true; |
|
|
|
setnow(&now); |
|
|
|
setnow(&now); |
|
|
|
w_item = workers_add(NULL, userid, workername, |
|
|
|
w_item = workers_add(NULL, lock, userid, |
|
|
|
|
|
|
|
workername, |
|
|
|
NULL, NULL, NULL, |
|
|
|
NULL, NULL, NULL, |
|
|
|
by_default, |
|
|
|
by_default, |
|
|
|
(char *)__func__, |
|
|
|
(char *)__func__, |
|
|
@ -867,6 +870,7 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_WLOCK(workerstatus_free); |
|
|
|
K_WLOCK(workerstatus_free); |
|
|
|
ws_item = k_unlink_head(workerstatus_free); |
|
|
|
ws_item = k_unlink_head(workerstatus_free); |
|
|
|
|
|
|
|
|
|
|
@ -878,6 +882,7 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, |
|
|
|
|
|
|
|
|
|
|
|
add_to_ktree(workerstatus_root, ws_item); |
|
|
|
add_to_ktree(workerstatus_root, ws_item); |
|
|
|
k_add_head(workerstatus_store, ws_item); |
|
|
|
k_add_head(workerstatus_store, ws_item); |
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_WUNLOCK(workerstatus_free); |
|
|
|
K_WUNLOCK(workerstatus_free); |
|
|
|
|
|
|
|
|
|
|
|
if (ws_err) { |
|
|
|
if (ws_err) { |
|
|
@ -946,12 +951,10 @@ void workerstatus_ready() |
|
|
|
while (ws_item) { |
|
|
|
while (ws_item) { |
|
|
|
DATA_WORKERSTATUS(workerstatus, ws_item); |
|
|
|
DATA_WORKERSTATUS(workerstatus, ws_item); |
|
|
|
|
|
|
|
|
|
|
|
K_RLOCK(markersummary_free); |
|
|
|
|
|
|
|
// This is the last share datestamp
|
|
|
|
// This is the last share datestamp
|
|
|
|
ms_item = find_markersummary_userid(workerstatus->userid, |
|
|
|
ms_item = find_markersummary_userid(workerstatus->userid, |
|
|
|
workerstatus->workername, |
|
|
|
workerstatus->workername, |
|
|
|
NULL); |
|
|
|
NULL); |
|
|
|
K_RUNLOCK(markersummary_free); |
|
|
|
|
|
|
|
if (ms_item) { |
|
|
|
if (ms_item) { |
|
|
|
DATA_MARKERSUMMARY(markersummary, ms_item); |
|
|
|
DATA_MARKERSUMMARY(markersummary, ms_item); |
|
|
|
if (tv_newer(&(workerstatus->last_share), |
|
|
|
if (tv_newer(&(workerstatus->last_share), |
|
|
@ -968,10 +971,8 @@ void workerstatus_ready() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
K_RLOCK(sharesummary_free); |
|
|
|
|
|
|
|
ss_item = find_last_sharesummary(workerstatus->userid, |
|
|
|
ss_item = find_last_sharesummary(workerstatus->userid, |
|
|
|
workerstatus->workername); |
|
|
|
workerstatus->workername); |
|
|
|
K_RUNLOCK(sharesummary_free); |
|
|
|
|
|
|
|
if (ss_item) { |
|
|
|
if (ss_item) { |
|
|
|
DATA_SHARESUMMARY(sharesummary, ss_item); |
|
|
|
DATA_SHARESUMMARY(sharesummary, ss_item); |
|
|
|
if (tv_newer(&(workerstatus->last_share), |
|
|
|
if (tv_newer(&(workerstatus->last_share), |
|
|
@ -1001,7 +1002,7 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, |
|
|
|
K_ITEM *item; |
|
|
|
K_ITEM *item; |
|
|
|
|
|
|
|
|
|
|
|
if (auths) { |
|
|
|
if (auths) { |
|
|
|
item = find_workerstatus(auths->userid, auths->workername, |
|
|
|
item = find_workerstatus(true, auths->userid, auths->workername, |
|
|
|
file, func, line); |
|
|
|
file, func, line); |
|
|
|
if (item) { |
|
|
|
if (item) { |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
@ -1022,7 +1023,8 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, |
|
|
|
pool.diffinv += shares->diff; |
|
|
|
pool.diffinv += shares->diff; |
|
|
|
pool.shareinv++; |
|
|
|
pool.shareinv++; |
|
|
|
} |
|
|
|
} |
|
|
|
item = find_workerstatus(shares->userid, shares->workername, |
|
|
|
item = find_workerstatus(true, shares->userid, |
|
|
|
|
|
|
|
shares->workername, |
|
|
|
file, func, line); |
|
|
|
file, func, line); |
|
|
|
if (item) { |
|
|
|
if (item) { |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
@ -1090,7 +1092,8 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (startup_complete && userstats) { |
|
|
|
if (startup_complete && userstats) { |
|
|
|
item = find_workerstatus(userstats->userid, userstats->workername, |
|
|
|
item = find_workerstatus(true, userstats->userid, |
|
|
|
|
|
|
|
userstats->workername, |
|
|
|
file, func, line); |
|
|
|
file, func, line); |
|
|
|
if (item) { |
|
|
|
if (item) { |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
|
DATA_WORKERSTATUS(row, item); |
|
|
@ -1535,7 +1538,7 @@ K_ITEM *new_worker(PGconn *conn, bool update, int64_t userid, char *workername, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: limit how many?
|
|
|
|
// TODO: limit how many?
|
|
|
|
item = workers_add(conn, userid, workername, diffdef, |
|
|
|
item = workers_add(conn, true, userid, workername, diffdef, |
|
|
|
idlenotificationenabled, idlenotificationtime, |
|
|
|
idlenotificationenabled, idlenotificationtime, |
|
|
|
by, code, inet, cd, trf_root); |
|
|
|
by, code, inet, cd, trf_root); |
|
|
|
} |
|
|
|
} |
|
|
@ -2748,12 +2751,13 @@ const char *blocks_confirmed(char *confirmed) |
|
|
|
return blocks_unknown; |
|
|
|
return blocks_unknown; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void zero_on_new_block() |
|
|
|
void zero_on_new_block(bool lock) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WORKERSTATUS *workerstatus; |
|
|
|
WORKERSTATUS *workerstatus; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_ITEM *ws_item; |
|
|
|
K_ITEM *ws_item; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_WLOCK(workerstatus_free); |
|
|
|
K_WLOCK(workerstatus_free); |
|
|
|
pool.diffacc = pool.diffinv = pool.shareacc = |
|
|
|
pool.diffacc = pool.diffinv = pool.shareacc = |
|
|
|
pool.shareinv = pool.best_sdiff = 0; |
|
|
|
pool.shareinv = pool.best_sdiff = 0; |
|
|
@ -2768,12 +2772,11 @@ void zero_on_new_block() |
|
|
|
workerstatus->block_sharehi = workerstatus->block_sharerej = 0.0; |
|
|
|
workerstatus->block_sharehi = workerstatus->block_sharerej = 0.0; |
|
|
|
ws_item = next_in_ktree(ctx); |
|
|
|
ws_item = next_in_ktree(ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (lock) |
|
|
|
K_WUNLOCK(workerstatus_free); |
|
|
|
K_WUNLOCK(workerstatus_free); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Currently only used at the end of the startup
|
|
|
|
// Currently only used at the end of the startup
|
|
|
|
* Will need to add locking if it's used, later, after startup completes */ |
|
|
|
|
|
|
|
void set_block_share_counters() |
|
|
|
void set_block_share_counters() |
|
|
|
{ |
|
|
|
{ |
|
|
|
K_TREE_CTX ctx[1], ctx_ms[1]; |
|
|
|
K_TREE_CTX ctx[1], ctx_ms[1]; |
|
|
@ -2788,13 +2791,12 @@ void set_block_share_counters() |
|
|
|
INIT_SHARESUMMARY(&ss_look); |
|
|
|
INIT_SHARESUMMARY(&ss_look); |
|
|
|
INIT_MARKERSUMMARY(&ms_look); |
|
|
|
INIT_MARKERSUMMARY(&ms_look); |
|
|
|
|
|
|
|
|
|
|
|
zero_on_new_block(); |
|
|
|
zero_on_new_block(false); |
|
|
|
|
|
|
|
|
|
|
|
ws_item = NULL; |
|
|
|
ws_item = NULL; |
|
|
|
/* From the end backwards so we can skip the workinfoid's we don't
|
|
|
|
/* From the end backwards so we can skip the workinfoid's we don't
|
|
|
|
* want by jumping back to just before the current worker when the |
|
|
|
* want by jumping back to just before the current worker when the |
|
|
|
* workinfoid goes below the limit */ |
|
|
|
* workinfoid goes below the limit */ |
|
|
|
K_RLOCK(sharesummary_free); |
|
|
|
|
|
|
|
ss_item = last_in_ktree(sharesummary_root, ctx); |
|
|
|
ss_item = last_in_ktree(sharesummary_root, ctx); |
|
|
|
while (ss_item) { |
|
|
|
while (ss_item) { |
|
|
|
DATA_SHARESUMMARY(sharesummary, ss_item); |
|
|
|
DATA_SHARESUMMARY(sharesummary, ss_item); |
|
|
@ -2819,16 +2821,14 @@ void set_block_share_counters() |
|
|
|
* since it should always exist |
|
|
|
* since it should always exist |
|
|
|
* However, it is simplest to simply create it |
|
|
|
* However, it is simplest to simply create it |
|
|
|
* and keep going */ |
|
|
|
* and keep going */ |
|
|
|
K_RUNLOCK(sharesummary_free); |
|
|
|
ws_item = find_workerstatus(false, sharesummary->userid, |
|
|
|
ws_item = find_workerstatus(sharesummary->userid, |
|
|
|
|
|
|
|
sharesummary->workername, |
|
|
|
sharesummary->workername, |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
if (!ws_item) { |
|
|
|
if (!ws_item) { |
|
|
|
ws_item = find_create_workerstatus(sharesummary->userid, |
|
|
|
ws_item = find_create_workerstatus(false, sharesummary->userid, |
|
|
|
sharesummary->workername, |
|
|
|
sharesummary->workername, |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
} |
|
|
|
} |
|
|
|
K_RLOCK(sharesummary_free); |
|
|
|
|
|
|
|
DATA_WORKERSTATUS(workerstatus, ws_item); |
|
|
|
DATA_WORKERSTATUS(workerstatus, ws_item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2857,7 +2857,6 @@ void set_block_share_counters() |
|
|
|
|
|
|
|
|
|
|
|
ss_item = prev_in_ktree(ctx); |
|
|
|
ss_item = prev_in_ktree(ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
K_RUNLOCK(sharesummary_free); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGWARNING("%s(): Updating block markersummary counters...", __func__); |
|
|
|
LOGWARNING("%s(): Updating block markersummary counters...", __func__); |
|
|
|
|
|
|
|
|
|
|
@ -2905,11 +2904,11 @@ void set_block_share_counters() |
|
|
|
* since it should always exist |
|
|
|
* since it should always exist |
|
|
|
* However, it is simplest to simply create it |
|
|
|
* However, it is simplest to simply create it |
|
|
|
* and keep going */ |
|
|
|
* and keep going */ |
|
|
|
ws_item = find_workerstatus(markersummary->userid, |
|
|
|
ws_item = find_workerstatus(false, markersummary->userid, |
|
|
|
markersummary->workername, |
|
|
|
markersummary->workername, |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
if (!ws_item) { |
|
|
|
if (!ws_item) { |
|
|
|
ws_item = find_create_workerstatus(markersummary->userid, |
|
|
|
ws_item = find_create_workerstatus(false, markersummary->userid, |
|
|
|
markersummary->workername, |
|
|
|
markersummary->workername, |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
__FILE__, __func__, __LINE__); |
|
|
|
} |
|
|
|
} |
|
|
|