From af5eb9e6c6fc1bdcdf0cd714c89332210df583ca Mon Sep 17 00:00:00 2001 From: kanoi Date: Mon, 12 Sep 2016 10:39:43 +1000 Subject: [PATCH] ckdb - make large table create/modify fields, and all workername fields intransient --- src/ckdb.c | 26 +++-- src/ckdb.h | 246 ++++++++++++++++++++++++++++++++++-------- src/ckdb_btc.c | 4 +- src/ckdb_cmd.c | 121 +++++++++++---------- src/ckdb_data.c | 194 +++++++++++++++++++-------------- src/ckdb_dbio.c | 282 ++++++++++++++++++++++++++++++++---------------- 6 files changed, 587 insertions(+), 286 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index fabae6c6..52d89278 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -208,7 +208,8 @@ const char *strpatt = "^[ -<>-~]*$"; const char Transfer[] = "Transfer"; // older version missing field defaults -static TRANSFER auth_1 = { "poolinstance", "", auth_1.svalue, NULL }; +// see end of alloc_storage() +static TRANSFER auth_1 = { "poolinstance", "", NULL, NULL }; K_ITEM auth_poolinstance = { Transfer, NULL, NULL, (void *)(&auth_1) }; static TRANSFER auth_2 = { "preauth", FALSE_STR, auth_2.svalue, NULL }; K_ITEM auth_preauth = { Transfer, NULL, NULL, (void *)(&auth_2) }; @@ -216,8 +217,8 @@ static TRANSFER poolstats_1 = { "elapsed", "0", poolstats_1.svalue, NULL }; K_ITEM poolstats_elapsed = { Transfer, NULL, NULL, (void *)(&poolstats_1) }; static TRANSFER userstats_1 = { "elapsed", "0", userstats_1.svalue, NULL }; K_ITEM userstats_elapsed = { Transfer, NULL, NULL, (void *)(&userstats_1) }; -static TRANSFER userstats_2 = { "workername", "all", userstats_2.svalue, NULL }; -K_ITEM userstats_workername = { Transfer, NULL, NULL, (void *)(&userstats_2) }; +// see end of alloc_storage() +INTRANSIENT *userstats_workername = NULL; static TRANSFER userstats_3 = { "idle", FALSE_STR, userstats_3.svalue, NULL }; K_ITEM userstats_idle = { Transfer, NULL, NULL, (void *)(&userstats_3) }; static TRANSFER userstats_4 = { "eos", TRUE_STR, userstats_4.svalue, NULL }; @@ -2274,6 +2275,11 @@ static void alloc_storage() if (auto_check_deadlocks) check_deadlocks = true; #endif + + // set intransient + auth_1.intransient = get_intransient(auth_1.name, ""); + auth_1.mvalue = auth_1.intransient->str; + userstats_workername = get_intransient("workername", "all"); } static void share_reports() @@ -2292,7 +2298,7 @@ static void share_reports() LOGNOTICE("%s(): %"PRId64"/%s/%"PRId32"/%s/%ld,%ld", __func__, shareerrors->workinfoid, - st = safe_text_nonull(shareerrors->workername), + st = safe_text_nonull(shareerrors->in_workername), shareerrors->errn, shareerrors->error, shareerrors->createdate.tv_sec, @@ -2311,7 +2317,7 @@ static void share_reports() LOGNOTICE("%s(): %"PRId64"/%s/%s/%"PRId32 "/%ld,%ld", __func__, shares->workinfoid, - st = safe_text_nonull(shares->workername), + st = safe_text_nonull(shares->in_workername), shares->nonce, shares->errn, shares->createdate.tv_sec, @@ -4905,7 +4911,7 @@ static void summarise_blocks() // Add up the sharesummaries, abort if any SUMMARY_NEW looksharesummary.workinfoid = wi_finish; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&ss_look); ss_look.data = (void *)(&looksharesummary); @@ -4978,7 +4984,7 @@ static void summarise_blocks() if (WMPROCESSED(workmarkers->status)) { lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = MAXID; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; INIT_MARKERSUMMARY(&ms_look); ms_look.data = (void *)(&lookmarkersummary); ms_item = find_before_in_ktree(markersummary_root, &ms_look, @@ -5264,7 +5270,7 @@ static void make_a_shift_mark() tv_to_buf(&(sharesummary->lastshare), cd_buf2, sizeof(cd_buf2)); LOGDEBUG("%s() last sharesummary %s/%s/%"PRId64"/%s/%s", __func__, sharesummary->complete, - sharesummary->workername, + sharesummary->in_workername, ss_age_wid, cd_buf, cd_buf2); } LOGDEBUG("%s() age sharesummary limit wid %"PRId64, __func__, ss_age_wid); @@ -5488,7 +5494,7 @@ static void make_a_shift_mark() * so doesn't need checking (and doesn't matter) */ looksharesummary.workinfoid = workinfo->workinfoid; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; ss_look.data = (void *)(&looksharesummary); K_RLOCK(sharesummary_free); ss_item = find_before_in_ktree(sharesummary_workinfoid_root, @@ -5507,7 +5513,7 @@ static void make_a_shift_mark() LOGEMERG("%s() ERR unaged sharesummary " "%s/%s/%"PRId64"/%s/%s", __func__, sharesummary->complete, - sharesummary->workername, + sharesummary->in_workername, sharesummary->workinfoid, cd_buf, cd_buf2); return; diff --git a/src/ckdb.h b/src/ckdb.h index 6681e3a7..b5ed6019 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.454" +#define CKDB_VERSION DB_VERSION"-2.500" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -866,6 +866,13 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, char *createinet; \ tv_t expirydate; \ bool pointers +#define HISTORYDATECONTROLIN \ + tv_t createdate; \ + char *in_createby; \ + char *in_createcode; \ + char *in_createinet; \ + tv_t expirydate; \ + bool intrans #define HISTORYDATEINIT(_row, _cd, _by, _code, _inet) do { \ (_row)->createdate.tv_sec = (_cd)->tv_sec; \ @@ -900,6 +907,17 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, (_row)->pointers = (_row)->pointers; \ } while (0) +#define HISTORYDATEINTRANS(_row, _cd, _by, _code, _inet) do { \ + (_row)->createdate.tv_sec = (_cd)->tv_sec; \ + (_row)->createdate.tv_usec = (_cd)->tv_usec; \ + (_row)->in_createby = intransient_str(BYDB, _by); \ + (_row)->in_createcode = intransient_str(CODEDB, _code); \ + (_row)->in_createinet = intransient_str(INETDB, _inet); \ + (_row)->expirydate.tv_sec = default_expiry.tv_sec; \ + (_row)->expirydate.tv_usec = default_expiry.tv_usec; \ + (_row)->intrans = (_row)->intrans; \ + } while (0) + /* Override _row defaults if transfer fields are present * We don't care about the reply so it can be small */ #define HISTORYDATETRANSFER(_root, _row) do { \ @@ -927,6 +945,31 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, } \ } while (0) +#define HISTORYDATETRANSFERIN(_root, _row) do { \ + if (_root) { \ + char __reply[16]; \ + size_t __siz = sizeof(__reply); \ + K_ITEM *__item; \ + TRANSFER *__transfer; \ + __item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createby = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createcode = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createinet = __transfer->intransient->str; \ + } \ + (_row)->intrans = (_row)->intrans; \ + } \ + } while (0) + #define MODIFYDATECONTROL ","CDDB","BYDB","CODEDB","INETDB \ ","MDDB","MBYDB","MCODEDB","MINETDB #define MODIFYDATECOUNT 8 @@ -951,6 +994,16 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, char *modifycode; \ char *modifyinet; \ bool pointers +#define MODIFYDATECONTROLIN \ + tv_t createdate; \ + char *in_createby; \ + char *in_createcode; \ + char *in_createinet; \ + tv_t modifydate; \ + char *in_modifyby; \ + char *in_modifycode; \ + char *in_modifyinet; \ + bool intrans #define MODIFYDATEINIT(_row, _cd, _by, _code, _inet) do { \ (_row)->createdate.tv_sec = (_cd)->tv_sec; \ @@ -996,9 +1049,32 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, (_row)->pointers = (_row)->pointers; \ } while (0) +// Using EMPTY is faster and is OK for in_ fields +#define MODIFYDATEINTRANS(_row, _cd, _by, _code, _inet) do { \ + (_row)->createdate.tv_sec = (_cd)->tv_sec; \ + (_row)->createdate.tv_usec = (_cd)->tv_usec; \ + (_row)->in_createby = intransient_str(BYDB, _by); \ + (_row)->in_createcode = intransient_str(CODEDB, _code); \ + (_row)->in_createinet = intransient_str(INETDB, _inet); \ + DATE_ZERO(&((_row)->modifydate)); \ + (_row)->in_modifyby = EMPTY; \ + (_row)->in_modifycode = EMPTY; \ + (_row)->in_modifyinet = EMPTY; \ + (_row)->intrans = (_row)->intrans; \ + } while (0) + +#define MODIFYUPDATEINTRANS(_row, _cd, _by, _code, _inet) do { \ + (_row)->modifydate.tv_sec = (_cd)->tv_sec; \ + (_row)->modifydate.tv_usec = (_cd)->tv_usec; \ + (_row)->in_modifyby = intransient_str(MBYDB, _by); \ + (_row)->in_modifycode = intransient_str(MCODEDB, _code); \ + (_row)->in_modifyinet = intransient_str(MINETDB, _inet); \ + (_row)->intrans = (_row)->intrans; \ + } while (0) + /* Override _row defaults if transfer fields are present * We don't care about the reply so it can be small - * This is the pointer version - only one required so far */ + * This is the pointer version */ #define MODIFYDATETRANSFER(_list, _root, _row) do { \ if (_root) { \ char __reply[16]; \ @@ -1024,6 +1100,32 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, } \ } while (0) +// Intransient version +#define MODIFYDATETRANSFERIN(_root, _row) do { \ + if (_root) { \ + char __reply[16]; \ + size_t __siz = sizeof(__reply); \ + K_ITEM *__item; \ + TRANSFER *__transfer; \ + __item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createby = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createcode = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createinet = __transfer->intransient->str; \ + } \ + (_row)->intrans = (_row)->intrans; \ + } \ + } while (0) + #define SIMPLEDATECONTROL ","CDDB","BYDB","CODEDB","INETDB #define SIMPLEDATECOUNT 4 #define SIMPLEDATECONTROLFIELDS \ @@ -1038,6 +1140,12 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, char *createcode; \ char *createinet; \ bool pointers +#define SIMPLEDATECONTROLIN \ + tv_t createdate; \ + char *in_createby; \ + char *in_createcode; \ + char *in_createinet; \ + bool intrans #define SIMPLEDATEINIT(_row, _cd, _by, _code, _inet) do { \ (_row)->createdate.tv_sec = (_cd)->tv_sec; \ @@ -1066,6 +1174,15 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, (_row)->pointers = (_row)->pointers; \ } while (0) +#define SIMPLEDATEINTRANS(_row, _cd, _by, _code, _inet) do { \ + (_row)->createdate.tv_sec = (_cd)->tv_sec; \ + (_row)->createdate.tv_usec = (_cd)->tv_usec; \ + (_row)->in_createby = intransient_str(BYDB, _by); \ + (_row)->in_createcode = intransient_str(CODEDB, _code); \ + (_row)->in_createinet = intransient_str(INETDB, _inet); \ + (_row)->intrans = (_row)->intrans; \ + } while (0) + /* Override _row defaults if transfer fields are present * We don't care about the reply so it can be small */ #define SIMPLEDATETRANSFER(_root, _row) do { \ @@ -1091,7 +1208,7 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, (_row)->buffers = (_row)->buffers; \ } while (0) -#define SIMPLEDATEPTRTRANSFER(_list, _root, _row) do { \ +#define SIMPLEDATETRANSFERPTR(_list, _root, _row) do { \ char __reply[16]; \ size_t __siz = sizeof(__reply); \ K_ITEM *__item; \ @@ -1114,6 +1231,29 @@ extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd, (_row)->pointers = (_row)->pointers; \ } while (0) +#define SIMPLEDATETRANSFERIN(_root, _row) do { \ + char __reply[16]; \ + size_t __siz = sizeof(__reply); \ + K_ITEM *__item; \ + TRANSFER *__transfer; \ + __item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createby = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createcode = __transfer->intransient->str; \ + } \ + __item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \ + if (__item) { \ + DATA_TRANSFER(__transfer, __item); \ + (_row)->in_createinet = __transfer->intransient->str; \ + } \ + (_row)->intrans = (_row)->intrans; \ + } while (0) + // IOQUEUE typedef struct ioqueue { char *msg; @@ -1170,6 +1310,19 @@ typedef struct intransient { char *str; } INTRANSIENT; +/* intransient strings are allowed to be EMPTY (and static "") + * but will always be the same RAM for the same non-zero length string */ +#define INTREQ(s1, s2) (s1 == s2 || (*(s1) == '\0' && *(s2) == '\0')) + +/* Some functions assume the string passed is intransient, so you must + * ensure all calls to those functions do pass an intransient string + * e.g. in the case of workername this is solved by simply making all + * workername fields in all tables intransient + * Using stack ram instead of an intransient would lead to having random, + * changing string values in the field + * Using a static (other than EMPTY or static "") would mean that use of + * INTREQ() could return an incorrect result */ + // Items never to be deleted and list never to be culled #define ALLOC_INTRANSIENT 1024 #define LIMIT_INTRANSIENT 0 @@ -1375,7 +1528,7 @@ extern int rep_max_btc_sockd_fd; // HEARTBEATQUEUE typedef struct heartbeatqueue { - char workername[TXT_BIG+1]; + char *in_workername; int32_t difficultydefault; tv_t createdate; } HEARTBEATQUEUE; @@ -1415,7 +1568,7 @@ extern K_ITEM auth_poolinstance; extern K_ITEM auth_preauth; extern K_ITEM poolstats_elapsed; extern K_ITEM userstats_elapsed; -extern K_ITEM userstats_workername; +extern INTRANSIENT *userstats_workername; extern K_ITEM userstats_idle; extern K_ITEM userstats_eos; extern K_ITEM shares_secondaryuserid; @@ -1739,7 +1892,7 @@ extern K_STORE *useratts_store; typedef struct workers { int64_t workerid; int64_t userid; - char workername[TXT_BIG+1]; // includes username + char *in_workername; // includes username int32_t difficultydefault; char idlenotificationenabled[TXT_FLAG+1]; int32_t idlenotificationtime; @@ -1822,7 +1975,7 @@ typedef struct payments { double diffacc; char committxn[TXT_BIG+1]; char commitblockhash[TXT_BIG+1]; - HISTORYDATECONTROLFIELDS; + HISTORYDATECONTROLIN; K_ITEM *old_item; // non-DB field } PAYMENTS; @@ -1977,7 +2130,7 @@ typedef struct workinfo { int64_t reward; int32_t height; // non-DB field double diff_target; // non-DB field - HISTORYDATECONTROLFIELDS; + HISTORYDATECONTROLIN; } WORKINFO; // ~10 hrs @@ -2013,7 +2166,7 @@ extern bool workinfo_age_lock; typedef struct shares { int64_t workinfoid; int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; int32_t clientid; char enonce1[TXT_SML+1]; char nonce2[TXT_BIG+1]; @@ -2079,7 +2232,7 @@ extern int64_t shares_begin; typedef struct shareerrors { int64_t workinfoid; int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; int32_t clientid; int32_t errn; char error[TXT_SML+1]; @@ -2104,7 +2257,7 @@ extern K_STORE *shareerrors_early_store; // SHARESUMMARY typedef struct sharesummary { int64_t userid; - char *workername; + char *in_workername; int64_t workinfoid; double diffacc; double diffsta; @@ -2156,7 +2309,7 @@ typedef struct blocks { char blockhash[TXT_BIG+1]; int64_t workinfoid; int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; int32_t clientid; char enonce1[TXT_SML+1]; char nonce2[TXT_BIG+1]; @@ -2267,7 +2420,7 @@ typedef struct miningpayouts { int64_t userid; double diffacc; int64_t amount; - HISTORYDATECONTROLFIELDS; + HISTORYDATECONTROLIN; K_ITEM *old_item; // non-DB field } MININGPAYOUTS; @@ -2532,7 +2685,7 @@ typedef struct auths { int64_t authid; char poolinstance[TXT_BIG+1]; int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; int32_t clientid; char enonce1[TXT_SML+1]; char useragent[TXT_BIG+1]; @@ -2588,7 +2741,7 @@ extern K_STORE *poolstats_store; typedef struct userstats { char poolinstance[TXT_BIG+1]; int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; int64_t elapsed; double hashrate; double hashrate5m; @@ -2696,7 +2849,7 @@ extern K_STORE *userstats_eos_store; // WORKERSTATUS from various incoming data typedef struct workerstatus { int64_t userid; - char workername[TXT_BIG+1]; + char *in_workername; tv_t last_auth; tv_t last_share; tv_t last_share_acc; @@ -2745,7 +2898,7 @@ extern K_STORE *workerstatus_store; typedef struct markersummary { int64_t markerid; int64_t userid; - char *workername; + char *in_workername; double diffacc; double diffsta; double diffdup; @@ -2763,7 +2916,7 @@ typedef struct markersummary { tv_t firstshareacc; tv_t lastshareacc; double lastdiffacc; - MODIFYDATECONTROLPOINTERS; + MODIFYDATECONTROLIN; } MARKERSUMMARY; #define ALLOC_MARKERSUMMARY 1000 @@ -2841,7 +2994,7 @@ typedef struct keysummary { tv_t firstshareacc; tv_t lastshareacc; double lastdiffacc; - SIMPLEDATECONTROLPOINTERS; + SIMPLEDATECONTROLIN; } KEYSUMMARY; #define ALLOC_KEYSUMMARY 1000 @@ -3068,11 +3221,11 @@ extern void sequence_report(bool lock); extern void free_msgline_data(K_ITEM *item, bool t_lock, bool t_cull); extern void free_users_data(K_ITEM *item); extern void free_workinfo_data(K_ITEM *item); -extern void free_sharesummary_data(K_ITEM *item); +#define free_sharesummary_data(_i) FREE_ITEM(_i) extern void free_payouts_data(K_ITEM *item); extern void free_ips_data(K_ITEM *item); extern void free_optioncontrol_data(K_ITEM *item); -extern void free_markersummary_data(K_ITEM *item); +#define free_markersummary_data(_i) FREE_ITEM(_i) extern void free_keysharesummary_data(K_ITEM *item); extern void free_keysummary_data(K_ITEM *item); extern void free_workmarkers_data(K_ITEM *item); @@ -3187,6 +3340,12 @@ extern K_ITEM *_optional_name(K_TREE *trf_root, char *name, int len, char *patt, _siz, WHERE_FFL_HERE) extern K_ITEM *_require_name(K_TREE *trf_root, char *name, int len, char *patt, char *reply, size_t siz, WHERE_FFL_ARGS); +#define optional_in(_root, _name, _len, _patt, _reply, _siz) \ + _optional_in(_root, _name, _len, _patt, _reply, _siz, \ + WHERE_FFL_HERE) +extern INTRANSIENT *_optional_in(K_TREE *trf_root, char *name, int len, + char *patt, char *reply, size_t siz, + WHERE_FFL_ARGS); #define require_in(_root, _name, _len, _patt, _reply, _siz) \ _require_in(_root, _name, _len, _patt, _reply, \ _siz, WHERE_FFL_HERE) @@ -3303,7 +3462,7 @@ extern void zero_sharesummary(SHARESUMMARY *row); _find_sharesummary(KANO, EMPTY, _workinfoid, true) #define POOL_SS(_row) do { \ (_row)->userid = KANO; \ - (_row)->workername = strdup(EMPTY); \ + (_row)->in_workername = EMPTY; \ } while (0) extern K_ITEM *_find_sharesummary(int64_t userid, char *workername, int64_t workinfoid, bool pool); @@ -3389,7 +3548,7 @@ extern K_ITEM *find_markersummary_userid(int64_t userid, char *workername, _find_markersummary(_markerid, 0, KANO, EMPTY, true) #define POOL_MS(_row) do { \ (_row)->userid = KANO; \ - (_row)->workername = EMPTY; \ + (_row)->in_workername = EMPTY; \ } while (0) extern K_ITEM *_find_markersummary(int64_t markerid, int64_t workinfoid, int64_t userid, char *workername, bool pool); @@ -3537,7 +3696,7 @@ extern int64_t workinfo_add(PGconn *conn, char *workinfoidstr, K_TREE *trf_root); extern bool workinfo_fill(PGconn *conn); extern bool shares_add(PGconn *conn, char *workinfoid, char *username, - char *workername, char *clientid, char *errn, + INTRANSIENT *in_workername, char *clientid, char *errn, char *enonce1, char *nonce2, char *nonce, char *diff, char *sdiff, char *secondaryuserid, char *ntime, char *address, char *agent, char *by, char *code, @@ -3545,9 +3704,10 @@ extern bool shares_add(PGconn *conn, char *workinfoid, char *username, extern bool shares_db(PGconn *conn, K_ITEM *s_item); extern bool shares_fill(PGconn *conn); extern bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, - char *workername, char *clientid, char *errn, - char *error, char *secondaryuserid, char *by, - char *code, char *inet, tv_t *cd, K_TREE *trf_root); + INTRANSIENT *in_workername, char *clientid, + char *errn, char *error, char *secondaryuserid, + char *by, char *code, char *inet, tv_t *cd, + K_TREE *trf_root); extern bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); @@ -3566,10 +3726,11 @@ extern bool blocks_stats(PGconn *conn, int32_t height, char *blockhash, char *by, char *code, char *inet, tv_t *cd); extern bool blocks_add(PGconn *conn, int32_t height, char *blockhash, char *confirmed, char *info, char *workinfoid, - char *username, char *workername, char *clientid, - char *enonce1, char *nonce2, char *nonce, char *reward, - char *by, char *code, char *inet, tv_t *cd, - bool igndup, char *id, K_TREE *trf_root); + char *username, INTRANSIENT *in_workername, + char *clientid, char *enonce1, char *nonce2, + char *nonce, char *reward, char *by, char *code, + char *inet, tv_t *cd, bool igndup, char *id, + K_TREE *trf_root); extern bool blocks_fill(PGconn *conn); extern void miningpayouts_add_ram(bool ok, K_ITEM *mp_item, K_ITEM *old_mp_item, tv_t *cd); @@ -3593,9 +3754,9 @@ extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root) extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root); #define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root) extern bool auths_add(PGconn *conn, char *poolinstance, char *username, - char *workername, char *clientid, char *enonce1, - char *useragent, char *preauth, char *by, char *code, - char *inet, tv_t *cd, K_TREE *trf_root, + INTRANSIENT *in_workername, char *clientid, + char *enonce1, char *useragent, char *preauth, char *by, + char *code, char *inet, tv_t *cd, K_TREE *trf_root, bool addressuser, USERS **users, WORKERS **workers, int *event, bool reload_data); extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, @@ -3607,15 +3768,16 @@ extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, extern bool poolstats_fill(PGconn *conn); extern bool userstats_add_db(PGconn *conn, USERSTATS *row); extern bool userstats_add(char *poolinstance, char *elapsed, char *username, - char *workername, char *hashrate, char *hashrate5m, - char *hashrate1hr, char *hashrate24hr, bool idle, - bool eos, char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root); + INTRANSIENT *in_workername, char *hashrate, + char *hashrate5m, char *hashrate1hr, + char *hashrate24hr, bool idle, bool eos, char *by, + char *code, char *inet, tv_t *cd, K_TREE *trf_root); extern bool workerstats_add(char *poolinstance, char *elapsed, char *username, - char *workername, char *hashrate, char *hashrate5m, - char *hashrate1hr, char *hashrate24hr, bool idle, - char *instances, char *by, char *code, char *inet, - tv_t *cd, K_TREE *trf_root); + INTRANSIENT *in_workername, char *hashrate, + char *hashrate5m, char *hashrate1hr, + char *hashrate24hr, bool idle, char *instances, + char *by, char *code, char *inet, tv_t *cd, + K_TREE *trf_root); extern bool userstats_fill(PGconn *conn); extern bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); diff --git a/src/ckdb_btc.c b/src/ckdb_btc.c index caea9e78..6047401b 100644 --- a/src/ckdb_btc.c +++ b/src/ckdb_btc.c @@ -354,7 +354,7 @@ bool btc_orphancheck(BLOCKS *blocks) ok = blocks_add(NULL, blocks->height, blocks->blockhash, BLOCKS_ORPHAN_STR, EMPTY, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by_default, (char *)__func__, inet_default, &now, false, id_default, NULL); @@ -426,7 +426,7 @@ void btc_blockstatus(BLOCKS *blocks) ok = blocks_add(NULL, blocks->height, blocks->blockhash, BLOCKS_42_STR, EMPTY, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by_default, (char *)__func__, inet_default, &now, false, id_default, NULL); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 807e1205..91331bfb 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -942,7 +942,7 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now, K_WUNLOCK(heartbeatqueue_free); DATA_HEARTBEATQUEUE(heartbeatqueue, hq_item); - STRNCPY(heartbeatqueue->workername, workers->workername); + heartbeatqueue->in_workername = workers->in_workername; heartbeatqueue->difficultydefault = workers->difficultydefault; copy_tv(&(heartbeatqueue->createdate), now); @@ -1108,9 +1108,10 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, // log to logfile - K_ITEM *i_poolinstance, *i_elapsed, *i_username, *i_workername; + K_ITEM *i_poolinstance, *i_elapsed, *i_username; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; K_ITEM *i_eos, *i_idle; + INTRANSIENT *in_workername; bool ok = false, idle, eos; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1132,9 +1133,9 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, if (!i_username) return strdup(reply); - i_workername = optional_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) - i_workername = &userstats_workername; + in_workername = optional_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) + in_workername = userstats_workername; i_hashrate = require_name(trf_root, "hashrate", 1, NULL, reply, siz); if (!i_hashrate) @@ -1167,7 +1168,7 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, ok = userstats_add(transfer_data(i_poolinstance), transfer_data(i_elapsed), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_hashrate), transfer_data(i_hashrate5m), transfer_data(i_hashrate1hr), @@ -1193,9 +1194,10 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, // log to logfile - K_ITEM *i_poolinstance, *i_elapsed, *i_username, *i_workername; + K_ITEM *i_poolinstance, *i_elapsed, *i_username; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; K_ITEM *i_idle, *i_instances; + INTRANSIENT *in_workername; bool ok = false, idle; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1217,8 +1219,8 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, if (!i_username) return strdup(reply); - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_hashrate = require_name(trf_root, "hashrate", 1, NULL, reply, siz); @@ -1248,7 +1250,7 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, ok = workerstats_add(transfer_data(i_poolinstance), transfer_data(i_elapsed), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_hashrate), transfer_data(i_hashrate5m), transfer_data(i_hashrate1hr), @@ -1350,7 +1352,7 @@ redo: snprintf(tmp, sizeof(tmp), "reward:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); - str_to_buf(blocks->workername, reply, sizeof(reply)); + str_to_buf(blocks->in_workername, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "workername:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -1589,7 +1591,7 @@ static char *cmd_blockstatus(PGconn *conn, char *cmd, char *id, tv_t *now, ok = blocks_add(conn, height, blocks->blockhash, BLOCKS_ORPHAN_STR, info, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by, code, inet, now, false, id, trf_root); @@ -1630,7 +1632,7 @@ static char *cmd_blockstatus(PGconn *conn, char *cmd, char *id, tv_t *now, ok = blocks_add(conn, height, blocks->blockhash, BLOCKS_REJECT_STR, info, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by, code, inet, now, false, id, trf_root); @@ -1659,7 +1661,7 @@ static char *cmd_blockstatus(PGconn *conn, char *cmd, char *id, tv_t *now, ok = blocks_add(conn, height, blocks->blockhash, BLOCKS_CONFIRM_STR, info, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by, code, inet, now, false, id, trf_root); @@ -1877,7 +1879,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users) // Add up all user's worker stats to be divided into payout percentages lookworkers.userid = users->userid; - lookworkers.workername[0] = '\0'; + lookworkers.in_workername = EMPTY; DATE_ZERO(&(lookworkers.expirydate)); w_look.data = (void *)(&lookworkers); K_RLOCK(workers_free); @@ -1888,7 +1890,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users) if (CURRENT(&(workers->expirydate))) { K_RLOCK(workerstatus_free); ws_item = find_workerstatus(true, users->userid, - workers->workername); + workers->in_workername); if (ws_item) { DATA_WORKERSTATUS(workerstatus, ws_item); t_diffacc += workerstatus->block_diffacc; @@ -1911,7 +1913,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users) * just cmp to last 'unused us_item' userid+worker * then step it forward to be the next ready 'unused' */ K_RLOCK(userstats_free); - us_item = find_userstats(users->userid, workers->workername); + us_item = find_userstats(users->userid, workers->in_workername); if (us_item) { DATA_USERSTATS(userstats, us_item); if (tvdiff(now, &(userstats->statsdate)) < USERSTATS_PER_S) { @@ -2157,7 +2159,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, INIT_WORKERS(&w_look); lookworkers.userid = users->userid; - lookworkers.workername[0] = '\0'; + lookworkers.in_workername = EMPTY; DATE_ZERO(&(lookworkers.expirydate)); w_look.data = (void *)(&lookworkers); K_RLOCK(workers_free); @@ -2169,7 +2171,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, if (CURRENT(&(workers->expirydate))) { K_RLOCK(workerstatus_free); ws_item = find_workerstatus(true, users->userid, - workers->workername); + workers->in_workername); if (ws_item) { DATA_WORKERSTATUS(workerstatus, ws_item); // good or bad - either means active @@ -2179,7 +2181,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, K_RUNLOCK(workerstatus_free); if (tvdiff(now, &last_share) < oldworkers) { - str_to_buf(workers->workername, reply, sizeof(reply)); + str_to_buf(workers->in_workername, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "workername:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -2257,7 +2259,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, * just cmp to last 'unused us_item' userid+worker * then step it forward to be the next ready 'unused' */ K_RLOCK(userstats_free); - us_item = find_userstats(users->userid, workers->workername); + us_item = find_userstats(users->userid, workers->in_workername); if (us_item) { DATA_USERSTATS(userstats, us_item); if (tvdiff(now, &(userstats->statsdate)) < USERSTATS_PER_S) { @@ -2427,7 +2429,7 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, userstats_u->userid = userstats->userid; /* Remember the first workername for if we ever * get the missing user LOGERR message below */ - STRNCPY(userstats_u->workername, userstats->workername); + userstats_u->in_workername = userstats->in_workername; userstats_u->hashrate5m = userstats->hashrate5m; userstats_u->hashrate1hr = userstats->hashrate1hr; userstats_u->instances = userstats->instances; @@ -2460,7 +2462,7 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, LOGERR("%s() userstats, but not users, " "ignored %"PRId64"/%s", __func__, userstats_u->userid, - userstats_u->workername); + userstats_u->in_workername); } else { DATA_USERS(users, u_item); str_to_buf(users->username, reply, sizeof(reply)); @@ -2625,9 +2627,10 @@ wiconf: snprintf(reply, siz, "ok.%"PRId64, workinfoid); return strdup(reply); } else if (strcasecmp(cmd, STR_SHARES) == 0) { - K_ITEM *i_workinfoid, *i_username, *i_workername, *i_clientid, *i_errn; + K_ITEM *i_workinfoid, *i_username, *i_clientid, *i_errn; K_ITEM *i_enonce1, *i_nonce2, *i_nonce, *i_diff, *i_sdiff; K_ITEM *i_secondaryuserid, *i_ntime, *i_address, *i_agent; + INTRANSIENT *in_workername; char *address, *agent; bool ok; @@ -2675,8 +2678,8 @@ wiconf: if (!i_username) return strdup(reply); - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_clientid = require_name(trf_root, "clientid", 1, NULL, reply, siz); @@ -2726,7 +2729,7 @@ wiconf: ok = shares_add(conn, transfer_data(i_workinfoid), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_clientid), transfer_data(i_errn), transfer_data(i_enonce1), @@ -2758,8 +2761,9 @@ sconf: snprintf(reply, siz, "ok.added %s", transfer_data(i_nonce)); return strdup(reply); } else if (strcasecmp(cmd, STR_SHAREERRORS) == 0) { - K_ITEM *i_workinfoid, *i_username, *i_workername, *i_clientid, *i_errn; + K_ITEM *i_workinfoid, *i_username, *i_clientid, *i_errn; K_ITEM *i_error, *i_secondaryuserid; + INTRANSIENT *in_workername; bool ok; // not summarised in keysummaries @@ -2789,8 +2793,8 @@ sconf: goto seconf; } - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_clientid = require_name(trf_root, "clientid", 1, NULL, reply, siz); @@ -2812,7 +2816,7 @@ sconf: ok = shareerrors_add(conn, transfer_data(i_workinfoid), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_clientid), transfer_data(i_errn), transfer_data(i_error), @@ -2899,7 +2903,8 @@ static char *cmd_blocks_do(PGconn *conn, char *cmd, int32_t height, char *id, char reply[1024] = ""; size_t siz = sizeof(reply); K_ITEM *i_blockhash, *i_confirmed, *i_workinfoid, *i_username; - K_ITEM *i_workername, *i_clientid, *i_enonce1, *i_nonce2, *i_nonce, *i_reward; + K_ITEM *i_clientid, *i_enonce1, *i_nonce2, *i_nonce, *i_reward; + INTRANSIENT *in_workername; TRANSFER *transfer; char *msg; bool ok; @@ -2926,8 +2931,8 @@ static char *cmd_blocks_do(PGconn *conn, char *cmd, int32_t height, char *id, if (!i_username) return strdup(reply); - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_clientid = require_name(trf_root, "clientid", 1, NULL, reply, siz); @@ -2957,7 +2962,7 @@ static char *cmd_blocks_do(PGconn *conn, char *cmd, int32_t height, char *id, EMPTY, transfer_data(i_workinfoid), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_nonce2), @@ -2972,7 +2977,7 @@ static char *cmd_blocks_do(PGconn *conn, char *cmd, int32_t height, char *id, transfer_data(i_blockhash), transfer_data(i_confirmed), EMPTY, - EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, NULL, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, by, code, inet, cd, igndup, id, trf_root); @@ -3036,8 +3041,9 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; + K_ITEM *i_poolinstance, *i_username, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item; + INTRANSIENT *in_workername; USERS *users = NULL; char *username; WORKERS *workers = NULL; @@ -3074,8 +3080,8 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, return strdup(reply); username = transfer_data(i_username); - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_clientid = require_name(trf_root, "clientid", 1, NULL, reply, siz); @@ -3116,7 +3122,7 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, if (ok) { ok = auths_add(conn, transfer_data(i_poolinstance), username, - transfer_data(i_workername), + in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_useragent), @@ -3160,7 +3166,7 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, "%s{\"workername\":\"%s\"," "\"difficultydefault\":%"PRId32"}", first ? EMPTY : ",", - workers->workername, + workers->in_workername, workers->difficultydefault); APPEND_REALLOC(buf, off, len, reply); first = false; @@ -3194,8 +3200,9 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; + K_ITEM *i_poolinstance, *i_username, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item; + INTRANSIENT *in_workername; USERS *users = NULL; WORKERS *workers = NULL; size_t len, off; @@ -3229,8 +3236,8 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, if (!i_username) return strdup(reply); - i_workername = require_name(trf_root, "workername", 1, NULL, reply, siz); - if (!i_workername) + in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); + if (!in_workername) return strdup(reply); i_clientid = require_name(trf_root, "clientid", 1, NULL, reply, siz); @@ -3251,7 +3258,7 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, ok = auths_add(conn, transfer_data(i_poolinstance), transfer_data(i_username), - transfer_data(i_workername), + in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_useragent), @@ -3294,7 +3301,7 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, "%s{\"workername\":\"%s\"," "\"difficultydefault\":%"PRId32"}", first ? EMPTY : ",", - workers->workername, + workers->in_workername, workers->difficultydefault); APPEND_REALLOC(buf, off, len, reply); first = false; @@ -3363,7 +3370,7 @@ static char *cmd_heartbeat(__maybe_unused PGconn *conn, char *cmd, char *id, "\"difficultydefault\":%d," "\""CDTRF"\":\"%ld,%ld\"}", first ? "" : ",", - heartbeatqueue->workername, + heartbeatqueue->in_workername, heartbeatqueue->difficultydefault, heartbeatqueue->createdate.tv_sec, heartbeatqueue->createdate.tv_usec); @@ -3625,7 +3632,7 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id, * Use 'before' in case there is (unexpectedly) a userstats * with an empty workername */ lookuserstats.userid = users->userid+1; - STRNCPY(lookuserstats.workername, EMPTY); + lookuserstats.in_workername = EMPTY; INIT_USERSTATS(&look); look.data = (void *)(&lookuserstats); K_RLOCK(userstats_free); @@ -4452,7 +4459,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, } LOGDEBUG("%s(): block %"PRId32"/%"PRId64"/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, blocks->reward); + blocks->in_workername, blocks->confirmed, blocks->reward); switch (blocks->confirmed[0]) { case BLOCKS_NEW: block_extra = "Can't be paid out yet"; @@ -4499,7 +4506,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, looksharesummary.workinfoid = block_workinfoid; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&ss_look); ss_look.data = (void *)(&looksharesummary); K_WLOCK(miningpayouts_free); @@ -4591,7 +4598,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, wm_count++; lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = MAXID; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; INIT_MARKERSUMMARY(&ms_look); ms_look.data = (void *)(&lookmarkersummary); ms_item = find_before_in_ktree(markersummary_root, @@ -4667,7 +4674,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "marks_status=%s%c", marks_status, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); - snprintf(tmp, sizeof(tmp), "workername=%s%c", blocks->workername, FLDSEP); + snprintf(tmp, sizeof(tmp), "workername=%s%c", blocks->in_workername, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "nonce=%s%c", blocks->nonce, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -4890,7 +4897,7 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, } LOGDEBUG("%s(): block %"PRId32"/%"PRId64"/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, blocks->reward); + blocks->in_workername, blocks->confirmed, blocks->reward); switch (blocks->confirmed[0]) { case BLOCKS_NEW: block_extra = "Can't be paid out yet"; @@ -4962,7 +4969,7 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "marks_status=%s%c", marks_status, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); - snprintf(tmp, sizeof(tmp), "workername=%s%c", blocks->workername, FLDSEP); + snprintf(tmp, sizeof(tmp), "workername=%s%c", blocks->in_workername, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "nonce=%s%c", blocks->nonce, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -5677,14 +5684,14 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, markersummary.markerid = wm->markerid; markersummary.userid = users->userid; - markersummary.workername = EMPTY; + markersummary.in_workername = EMPTY; K_RLOCK(markersummary_free); ms_item = find_after_in_ktree(markersummary_root, &ms_look, ms_ctx); DATA_MARKERSUMMARY_NULL(ms, ms_item); while (ms_item && ms->markerid == wm->markerid && ms->userid == users->userid) { - work = worker_offset(ms->workername); + work = worker_offset(ms->in_workername); for (want = 0; workm[want].worker; want++) { if ((want == where_all) || (workm[want].match && strncmp(work, workm[want].worker, workm[want].len) == 0) || @@ -7570,7 +7577,7 @@ static char *cmd_query(__maybe_unused PGconn *conn, char *cmd, char *id, INIT_SHARES(&s_look); lookshares.workinfoid = selwid; lookshares.userid = -1; - lookshares.workername[0] = '\0'; + lookshares.in_workername = EMPTY; DATE_ZERO(&(lookshares.createdate)); s_look.data = (void *)(&lookshares); found = false; diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 06f4ca60..89d9a723 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -91,15 +91,6 @@ void free_ips_data(K_ITEM *item) FREENULL(ips->description); } -void free_sharesummary_data(K_ITEM *item) -{ - SHARESUMMARY *sharesummary; - - DATA_SHARESUMMARY(sharesummary, item); - LIST_MEM_SUB(sharesummary_free, sharesummary->workername); - FREENULL(sharesummary->workername); -} - void free_optioncontrol_data(K_ITEM *item) { OPTIONCONTROL *optioncontrol; @@ -109,21 +100,6 @@ void free_optioncontrol_data(K_ITEM *item) FREENULL(optioncontrol->optionvalue); } -void free_markersummary_data(K_ITEM *item) -{ - MARKERSUMMARY *markersummary; - - DATA_MARKERSUMMARY(markersummary, item); - LIST_MEM_SUB(markersummary_free, markersummary->workername); - FREENULL(markersummary->workername); - SET_CREATEBY(markersummary_free, markersummary->createby, EMPTY); - SET_CREATECODE(markersummary_free, markersummary->createcode, EMPTY); - SET_CREATEINET(markersummary_free, markersummary->createinet, EMPTY); - SET_MODIFYBY(markersummary_free, markersummary->modifyby, EMPTY); - SET_MODIFYCODE(markersummary_free, markersummary->modifycode, EMPTY); - SET_MODIFYINET(markersummary_free, markersummary->modifyinet, EMPTY); -} - void free_keysharesummary_data(K_ITEM *item) { KEYSHARESUMMARY *keysharesummary; @@ -140,9 +116,6 @@ void free_keysummary_data(K_ITEM *item) DATA_KEYSUMMARY(keysummary, item); LIST_MEM_SUB(keysummary_free, keysummary->key); FREENULL(keysummary->key); - SET_CREATEBY(keysummary_free, keysummary->createby, EMPTY); - SET_CREATECODE(keysummary_free, keysummary->createcode, EMPTY); - SET_CREATEINET(keysummary_free, keysummary->createinet, EMPTY); } void free_workmarkers_data(K_ITEM *item) @@ -1021,6 +994,63 @@ K_ITEM *_require_name(K_TREE *trf_root, char *name, int len, char *patt, return item; } +INTRANSIENT *_optional_in(K_TREE *trf_root, char *name, int len, char *patt, + char *reply, size_t siz, WHERE_FFL_ARGS) +{ + INTRANSIENT *in; + TRANSFER *trf; + K_ITEM *item; + char *mvalue; + regex_t re; + size_t dlen; + int ret; + + reply[0] = '\0'; + + item = find_transfer(trf_root, name); + if (!item) + return NULL; + + DATA_TRANSFER(trf, item); + if (!(in = trf->intransient)) { + LOGERR("%s(): failed, field '%s' is not intransient %s():%d", + __func__, name, func, line); + snprintf(reply, siz, "failed.transient %s", name); + return NULL; + } + + mvalue = trf->mvalue; + if (mvalue) + dlen = strlen(mvalue); + else + dlen = 0; + if (!mvalue || (int)dlen < len) { + if (!mvalue) { + LOGERR("%s(): field '%s' NULL (%d:%d) from %s():%d", + __func__, name, (int)dlen, len, func, line); + } else + snprintf(reply, siz, "failed.short %s", name); + return NULL; + } + + if (patt) { + if (regcomp(&re, patt, REG_NOSUB) != 0) { + snprintf(reply, siz, "failed.REG %s", name); + return NULL; + } + + ret = regexec(&re, mvalue, (size_t)0, NULL, 0); + regfree(&re); + + if (ret != 0) { + snprintf(reply, siz, "failed.invalid %s", name); + return NULL; + } + } + + return in; +} + INTRANSIENT *_require_in(K_TREE *trf_root, char *name, int len, char *patt, char *reply, size_t siz, WHERE_FFL_ARGS) { @@ -1098,7 +1128,7 @@ cmp_t cmp_workerstatus(K_ITEM *a, K_ITEM *b) DATA_WORKERSTATUS(wb, b); cmp_t c = CMP_BIGINT(wa->userid, wb->userid); if (c == 0) - c = CMP_STR(wa->workername, wb->workername); + c = CMP_STR(wa->in_workername, wb->in_workername); return c; } @@ -1112,7 +1142,7 @@ K_ITEM *find_workerstatus(bool gotlock, int64_t userid, char *workername) K_ITEM look, *find; workerstatus.userid = userid; - STRNCPY(workerstatus.workername, workername); + workerstatus.in_workername = workername; INIT_WORKERSTATUS(&look); look.data = (void *)(&workerstatus); @@ -1133,6 +1163,8 @@ K_ITEM *find_workerstatus(bool gotlock, int64_t userid, char *workername) * to add_worker() (if the add_worker() fails) * This has 2 sets of file/func/line to allow 2 levels of traceback * in the log + * + * WARNING: workername must from intransient */ K_ITEM *_find_create_workerstatus(bool gotlock, bool alertcreate, int64_t userid, char *workername, @@ -1174,7 +1206,7 @@ K_ITEM *_find_create_workerstatus(bool gotlock, bool alertcreate, bzero(row, sizeof(*row)); row->userid = userid; - STRNCPY(row->workername, workername); + row->in_workername = workername; add_to_ktree(workerstatus_root, ws_item); k_add_head(workerstatus_store, ws_item); @@ -1252,7 +1284,7 @@ void workerstatus_ready() // This is the last share datestamp ms_item = find_markersummary_userid(workerstatus->userid, - workerstatus->workername, + workerstatus->in_workername, NULL); if (ms_item) { DATA_MARKERSUMMARY(markersummary, ms_item); @@ -1271,7 +1303,7 @@ void workerstatus_ready() } ss_item = find_last_sharesummary(workerstatus->userid, - workerstatus->workername); + workerstatus->in_workername); if (ss_item) { DATA_SHARESUMMARY(sharesummary, ss_item); if (tv_newer(&(workerstatus->last_share), @@ -1302,7 +1334,7 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, if (auths) { item = find_create_workerstatus(false, false, auths->userid, - auths->workername, false, + auths->in_workername, false, file, func, line); if (item) { DATA_WORKERSTATUS(row, item); @@ -1324,7 +1356,7 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, pool.shareinv++; } item = find_create_workerstatus(false, true, shares->userid, - shares->workername, false, + shares->in_workername, false, file, func, line); if (item) { DATA_WORKERSTATUS(row, item); @@ -1393,7 +1425,7 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares, if (startup_complete && userstats) { item = find_create_workerstatus(false, true, userstats->userid, - userstats->workername, false, + userstats->in_workername, false, file, func, line); if (item) { DATA_WORKERSTATUS(row, item); @@ -1783,7 +1815,7 @@ cmp_t cmp_workers(K_ITEM *a, K_ITEM *b) DATA_WORKERS(wb, b); cmp_t c = CMP_BIGINT(wa->userid, wb->userid); if (c == 0) { - c = CMP_STR(wa->workername, wb->workername); + c = CMP_STR(wa->in_workername, wb->in_workername); if (c == 0) c = CMP_TV(wb->expirydate, wa->expirydate); } @@ -1797,7 +1829,7 @@ K_ITEM *find_workers(bool gotlock, int64_t userid, char *workername) K_ITEM look, *w_item; workers.userid = userid; - STRNCPY(workers.workername, workername); + workers.in_workername = workername; workers.expirydate.tv_sec = default_expiry.tv_sec; workers.expirydate.tv_usec = default_expiry.tv_usec; @@ -1822,7 +1854,7 @@ K_ITEM *first_workers(int64_t userid, K_TREE_CTX *ctx) ctx = ctx0; workers.userid = userid; - workers.workername[0] = '\0'; + workers.in_workername = EMPTY; DATE_ZERO(&(workers.expirydate)); INIT_WORKERS(&look); @@ -2559,7 +2591,7 @@ static void discard_shares(int64_t *shares_tot, int64_t *shares_dumped, lookshares.workinfoid = workinfoid; lookshares.userid = userid; - strcpy(lookshares.workername, workername); + lookshares.in_workername = workername; DATE_ZERO(&(lookshares.createdate)); s_look.data = (void *)(&lookshares); @@ -2573,7 +2605,7 @@ static void discard_shares(int64_t *shares_tot, int64_t *shares_dumped, if (userid != DISCARD_ALL) { if (shares->userid != userid || - strcmp(shares->workername, workername) != 0) + !INTREQ(shares->in_workername, workername)) break; } @@ -2605,7 +2637,7 @@ static void discard_shares(int64_t *shares_tot, int64_t *shares_dumped, "%"PRId64"/%"PRId64"/%s/%s%.0f", shares->workinfoid, shares->userid, - shares->workername, + shares->in_workername, (shares->errn == SE_NONE) ? "" : "*", shares->diff); } @@ -2700,7 +2732,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, // Find the first matching sharesummary looksharesummary.workinfoid = workinfoid; looksharesummary.userid = -1; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; ss_look.data = (void *)(&looksharesummary); K_RLOCK(sharesummary_free); @@ -2725,7 +2757,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, LOGERR("%s(): Duplicate %s found during confirm %"PRId64"/%s/%"PRId64, __func__, __func__, sharesummary->userid, - sharesummary->workername, + sharesummary->in_workername, sharesummary->workinfoid); } } @@ -2738,7 +2770,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, ss_failed++; LOGERR("%s(): Failed to age sharesummary %"PRId64"/%s/%"PRId64, __func__, sharesummary->userid, - sharesummary->workername, + sharesummary->in_workername, sharesummary->workinfoid); ok = false; } else { @@ -2757,7 +2789,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, // Discard the shares either way discard_shares(&shares_tot, &shares_dumped, &diff_tot, skipupdate, workinfoid, sharesummary->userid, - sharesummary->workername); + sharesummary->in_workername); K_RLOCK(sharesummary_free); ss_item = next_in_ktree(ss_ctx); @@ -2916,7 +2948,7 @@ cmp_t cmp_shares(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(sa->userid, sb->userid); if (c == 0) { - c = CMP_STR(sa->workername, sb->workername); + c = CMP_STR(sa->in_workername, sb->in_workername); if (c == 0) { c = CMP_TV(sa->createdate, sb->createdate); if (c == 0) { @@ -2945,7 +2977,7 @@ cmp_t cmp_shares_db(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(sa->userid, sb->userid); if (c == 0) { - c = CMP_STR(sa->workername, sb->workername); + c = CMP_STR(sa->in_workername, sb->in_workername); if (c == 0) { c = CMP_STR(sa->enonce1, sb->enonce1); if (c == 0) { @@ -2992,7 +3024,7 @@ void dsp_sharesummary(K_ITEM *item, FILE *stream) DATA_SHARESUMMARY(s, item); fprintf(stream, " uid=%"PRId64" wn='%s' wid=%"PRId64" " "da=%f ds=%f ss=%f c='%s'\n", - s->userid, s->workername, s->workinfoid, + s->userid, s->in_workername, s->workinfoid, s->diffacc, s->diffsta, s->sharesta, s->complete); } @@ -3006,7 +3038,7 @@ cmp_t cmp_sharesummary(K_ITEM *a, K_ITEM *b) DATA_SHARESUMMARY(sb, b); cmp_t c = CMP_BIGINT(sa->userid, sb->userid); if (c == 0) { - c = CMP_STR(sa->workername, sb->workername); + c = CMP_STR(sa->in_workername, sb->in_workername); if (c == 0) c = CMP_BIGINT(sa->workinfoid, sb->workinfoid); } @@ -3023,7 +3055,7 @@ cmp_t cmp_sharesummary_workinfoid(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(sa->userid, sb->userid); if (c == 0) - c = CMP_STR(sa->workername, sb->workername); + c = CMP_STR(sa->in_workername, sb->in_workername); } return c; } @@ -3052,7 +3084,7 @@ K_ITEM *_find_sharesummary(int64_t userid, char *workername, int64_t workinfoid, K_ITEM look; sharesummary.userid = userid; - sharesummary.workername = workername; + sharesummary.in_workername = workername; sharesummary.workinfoid = workinfoid; INIT_SHARESUMMARY(&look); @@ -3071,7 +3103,7 @@ K_ITEM *find_last_sharesummary(int64_t userid, char *workername) K_ITEM look, *item; look_sharesummary.userid = userid; - look_sharesummary.workername = workername; + look_sharesummary.in_workername = workername; look_sharesummary.workinfoid = MAXID; INIT_SHARESUMMARY(&look); @@ -3080,7 +3112,7 @@ K_ITEM *find_last_sharesummary(int64_t userid, char *workername) if (item) { DATA_SHARESUMMARY(sharesummary, item); if (sharesummary->userid != userid || - strcmp(sharesummary->workername, workername) != 0) + !INTREQ(sharesummary->in_workername, workername)) item = NULL; } return item; @@ -3285,7 +3317,7 @@ void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) * Unaged keysharesummaries will have the same workinfoids */ looksharesummary.workinfoid = prev_found; looksharesummary.userid = -1; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&look); look.data = (void *)(&looksharesummary); @@ -3485,7 +3517,7 @@ void dsp_blocks(K_ITEM *item, FILE *stream) fprintf(stream, " hi=%d hash='%.16s' conf=%s uid=%"PRId64 " w='%s' sconf=%s cd=%s ed=%s\n", b->height, hash_dsp, b->confirmed, b->userid, - b->workername, b->statsconfirmed, + b->in_workername, b->statsconfirmed, createdate_buf, expirydate_buf); } } @@ -3631,7 +3663,7 @@ void set_block_share_counters() if (sharesummary->workinfoid <= pool.workinfoid) { // Skip back to the next worker looksharesummary.userid = sharesummary->userid; - looksharesummary.workername = sharesummary->workername; + looksharesummary.in_workername = sharesummary->in_workername; looksharesummary.workinfoid = -1; ss_look.data = (void *)(&looksharesummary); ss_item = find_before_in_ktree(sharesummary_root, @@ -3644,13 +3676,13 @@ void set_block_share_counters() * so this will only be once per user/workername */ if (!ws_item || sharesummary->userid != workerstatus->userid || - strcmp(sharesummary->workername, workerstatus->workername)) { + !INTREQ(sharesummary->in_workername, workerstatus->in_workername)) { /* Trigger a console error if it is missing since it * should already exist, however, it is simplest to * create it and keep going */ ws_item = find_create_workerstatus(true, true, sharesummary->userid, - sharesummary->workername, + sharesummary->in_workername, false, __FILE__, __func__, __LINE__); DATA_WORKERSTATUS(workerstatus, ws_item); @@ -3709,7 +3741,7 @@ void set_block_share_counters() lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = MAXID; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; ms_look.data = (void *)(&lookmarkersummary); ms_item = find_before_in_ktree(markersummary_root, &ms_look, ctx_ms); @@ -3723,13 +3755,13 @@ void set_block_share_counters() * so this will only be once per user/workername */ if (!ws_item || markersummary->userid != workerstatus->userid || - strcmp(markersummary->workername, workerstatus->workername)) { + !INTREQ(markersummary->in_workername, workerstatus->in_workername)) { /* Trigger a console error if it is missing since it * should already exist, however, it is simplest to * create it and keep going */ ws_item = find_create_workerstatus(true, true, markersummary->userid, - markersummary->workername, + markersummary->in_workername, false, __FILE__, __func__, __LINE__); DATA_WORKERSTATUS(workerstatus, ws_item); @@ -4500,7 +4532,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGDEBUG("%s(): block %"PRId32"/%"PRId64"/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, blocks->reward); + blocks->in_workername, blocks->confirmed, blocks->reward); switch (blocks->confirmed[0]) { case BLOCKS_NEW: @@ -4509,7 +4541,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGERR("%s(): can't process block %"PRId32"/%" PRId64"/%s/%"PRId64" status: %s/%s", __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->reward, + blocks->in_workername, blocks->reward, blocks->confirmed, blocks_confirmed(blocks->confirmed)); goto oku; @@ -4519,7 +4551,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGEMERG("%s(): missing block workinfoid %"PRId32"/%"PRId64 "/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, + blocks->in_workername, blocks->confirmed, blocks->reward); goto oku; } @@ -4554,7 +4586,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGERR("%s(): invalid diff_want %.1f, block %"PRId32"/%" PRId64"/%s/%s/%"PRId64, __func__, diff_want, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, blocks->reward); + blocks->in_workername, blocks->confirmed, blocks->reward); goto oku; } @@ -4580,7 +4612,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) looksharesummary.workinfoid = blocks->workinfoid; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&ss_look); ss_look.data = (void *)(&looksharesummary); K_WLOCK(miningpayouts_free); @@ -4611,7 +4643,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGERR("%s(): sharesummary not ready %" PRId64"/%s/%"PRId64"/%s. allow_aged=%s", __func__, sharesummary->userid, - sharesummary->workername, + sharesummary->in_workername, sharesummary->workinfoid, sharesummary->complete, TFSTR(allow_aged)); @@ -4652,7 +4684,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGERR("%s(): sharesummary2 not ready %" PRId64"/%s/%"PRId64"/%s. allow_aged=%s", __func__, sharesummary->userid, - sharesummary->workername, + sharesummary->in_workername, sharesummary->workinfoid, sharesummary->complete, TFSTR(allow_aged)); @@ -4696,7 +4728,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) wm_count++; lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = MAXID; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; INIT_MARKERSUMMARY(&ms_look); ms_look.data = (void *)(&lookmarkersummary); ms_item = find_before_in_ktree(markersummary_root, @@ -4747,7 +4779,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) "block %"PRId32"/%"PRId64"/%s/%s/%"PRId64 " beginwi=%"PRId64" ss=%"PRId64" diff=%.1f", __func__, wm_count, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, blocks->reward, + blocks->in_workername, blocks->confirmed, blocks->reward, begin_workinfoid, ss_count, total_diff); goto shazbot; } @@ -4757,7 +4789,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGERR("%s(): total share diff zero before block %"PRId32 "/%"PRId64"/%s/%s/%"PRId64, __func__, blocks->height, blocks->workinfoid, - blocks->workername, blocks->confirmed, + blocks->in_workername, blocks->confirmed, blocks->reward); goto shazbot; } @@ -4767,7 +4799,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) LOGEMERG("%s(): missing begin workinfo record %"PRId64 " payout of block %"PRId32"/%"PRId64"/%s/%s/%"PRId64, __func__, begin_workinfoid, blocks->height, - blocks->workinfoid, blocks->workername, + blocks->workinfoid, blocks->in_workername, blocks->confirmed, blocks->reward); goto shazbot; } @@ -6162,7 +6194,7 @@ void dsp_userstats(K_ITEM *item, FILE *stream) tv_to_buf(&(u->createdate), createdate_buf, sizeof(createdate_buf)); fprintf(stream, " pi='%s' uid=%"PRId64" w='%s' e=%"PRId64" Hs=%f " "Hs5m=%f Hs1hr=%f Hs24hr=%f sl=%s sc=%d sd=%s cd=%s\n", - u->poolinstance, u->userid, u->workername, + u->poolinstance, u->userid, u->in_workername, u->elapsed, u->hashrate, u->hashrate5m, u->hashrate1hr, u->hashrate24hr, u->summarylevel, u->summarycount, statsdate_buf, createdate_buf); @@ -6177,7 +6209,7 @@ cmp_t cmp_userstats(K_ITEM *a, K_ITEM *b) DATA_USERSTATS(ub, b); cmp_t c = CMP_BIGINT(ua->userid, ub->userid); if (c == 0) - c = CMP_STR(ua->workername, ub->workername); + c = CMP_STR(ua->in_workername, ub->in_workername); return c; } @@ -6189,7 +6221,7 @@ K_ITEM *find_userstats(int64_t userid, char *workername) K_ITEM look; userstats.userid = userid; - STRNCPY(userstats.workername, workername); + userstats.in_workername = workername; INIT_USERSTATS(&look); look.data = (void *)(&userstats); @@ -6207,7 +6239,7 @@ void dsp_markersummary(K_ITEM *item, FILE *stream) fprintf(stream, " markerid=%"PRId64" userid=%"PRId64 " worker='%s' " "diffacc=%f shares=%"PRId64 " errs=%"PRId64" lastdiff=%f\n", - ms->markerid, ms->userid, ms->workername, + ms->markerid, ms->userid, ms->in_workername, ms->diffacc, ms->sharecount, ms->errorcount, ms->lastdiffacc); } @@ -6223,7 +6255,7 @@ cmp_t cmp_markersummary(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(ma->userid, mb->userid); if (c == 0) - c = CMP_STR(ma->workername, mb->workername); + c = CMP_STR(ma->in_workername, mb->in_workername); } return c; } @@ -6236,7 +6268,7 @@ cmp_t cmp_markersummary_userid(K_ITEM *a, K_ITEM *b) DATA_MARKERSUMMARY(mb, b); cmp_t c = CMP_BIGINT(ma->userid, mb->userid); if (c == 0) { - c = CMP_STR(ma->workername, mb->workername); + c = CMP_STR(ma->in_workername, mb->in_workername); if (c == 0) c = CMP_TV(ma->lastshare, mb->lastshare); } @@ -6255,7 +6287,7 @@ K_ITEM *find_markersummary_userid(int64_t userid, char *workername, ctx = ctx0; markersummary.userid = userid; - markersummary.workername = workername; + markersummary.in_workername = workername; markersummary.lastshare.tv_sec = DATE_S_EOT; INIT_MARKERSUMMARY(&look); @@ -6263,7 +6295,7 @@ K_ITEM *find_markersummary_userid(int64_t userid, char *workername, ms_item = find_before_in_ktree(markersummary_userid_root, &look, ctx); if (ms_item) { DATA_MARKERSUMMARY(ms, ms_item); - if (ms->userid != userid || strcmp(ms->workername, workername)) + if (ms->userid != userid || !INTREQ(ms->in_workername, workername)) ms_item = NULL; } return ms_item; @@ -6293,7 +6325,7 @@ K_ITEM *_find_markersummary(int64_t markerid, int64_t workinfoid, if (markerid != 0) { markersummary.markerid = markerid; markersummary.userid = userid; - markersummary.workername = workername; + markersummary.in_workername = workername; INIT_MARKERSUMMARY(&look); look.data = (void *)(&markersummary); diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index de7db918..81522ac1 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -62,6 +62,32 @@ char *pqerrmsg(PGconn *conn) if (!_ok) \ break; \ TXT_TO_TVDB(EDDB, _fld, (_data)->expirydate); \ + (_data)->buffers = (_data)->buffers; \ + } while (0) + +#define HISTORYDATEIN(_res, _row, _data, _ok) do { \ + char *_fld; \ + PQ_GET_FLD(_res, _row, CDDB, _fld, _ok); \ + if (!_ok) \ + break; \ + TXT_TO_TVDB(CDDB, _fld, (_data)->createdate); \ + PQ_GET_FLD(_res, _row, BYDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createby = intransient_str(BYDB, _fld); \ + PQ_GET_FLD(_res, _row, CODEDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createcode = intransient_str(CODEDB, _fld); \ + PQ_GET_FLD(_res, _row, INETDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createinet = intransient_str(INETDB, _fld); \ + PQ_GET_FLD(_res, _row, EDDB, _fld, _ok); \ + if (!_ok) \ + break; \ + TXT_TO_TVDB(EDDB, _fld, (_data)->expirydate); \ + (_data)->intrans = (_data)->intrans; \ } while (0) #define HISTORYDATEPARAMS(_params, _his_pos, _row) do { \ @@ -72,6 +98,14 @@ char *pqerrmsg(PGconn *conn) _params[_his_pos++] = tv_to_buf(&(_row->expirydate), NULL, 0); \ } while (0) +#define HISTORYDATEPARAMSIN(_params, _his_pos, _row) do { \ + _params[_his_pos++] = tv_to_buf(&(_row->createdate), NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createby, NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createcode, NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createinet, NULL, 0); \ + _params[_his_pos++] = tv_to_buf(&(_row->expirydate), NULL, 0); \ + } while (0) + // MODIFY FIELDS #define MODIFYDATEFLDPOINTERS(_list, _res, _row, _data, _ok) do { \ char *_fld; \ @@ -107,6 +141,44 @@ char *pqerrmsg(PGconn *conn) if (!_ok) \ break; \ SET_MODIFYINET(_list, (_data)->modifyinet, _fld); \ + (_data)->pointers = (_data)->pointers; \ + } while (0) + +#define MODIFYDATEIN(_res, _row, _data, _ok) do { \ + char *_fld; \ + PQ_GET_FLD(_res, _row, CDDB, _fld, _ok); \ + if (!_ok) \ + break; \ + TXT_TO_TVDB(CDDB, _fld, (_data)->createdate); \ + PQ_GET_FLD(_res, _row, BYDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createby = intransient_str(BYDB, _fld); \ + PQ_GET_FLD(_res, _row, CODEDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createcode = intransient_str(CODEDB, _fld); \ + PQ_GET_FLD(_res, _row, INETDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_createinet = intransient_str(INETDB, _fld); \ + PQ_GET_FLD(_res, _row, MDDB, _fld, _ok); \ + if (!_ok) \ + break; \ + TXT_TO_TVDB(MDDB, _fld, (_data)->modifydate); \ + PQ_GET_FLD(_res, _row, MBYDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_modifyby = intransient_str(MBYDB, _fld); \ + PQ_GET_FLD(_res, _row, MCODEDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_modifycode = intransient_str(MCODEDB, _fld); \ + PQ_GET_FLD(_res, _row, MINETDB, _fld, _ok); \ + if (!_ok) \ + break; \ + (_data)->in_modifyinet = intransient_str(MINETDB, _fld); \ + (_data)->intrans = (_data)->intrans; \ } while (0) #define MODIFYDATEPARAMS(_params, _mod_pos, _row) do { \ @@ -120,6 +192,17 @@ char *pqerrmsg(PGconn *conn) _params[_mod_pos++] = str_to_buf(_row->modifyinet, NULL, 0); \ } while (0) +#define MODIFYDATEPARAMSIN(_params, _mod_pos, _row) do { \ + _params[_mod_pos++] = tv_to_buf(&(_row->createdate), NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_createby, NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_createcode, NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_createinet, NULL, 0); \ + _params[_mod_pos++] = tv_to_buf(&(_row->modifydate), NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_modifyby, NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_modifycode, NULL, 0); \ + _params[_mod_pos++] = str_to_buf(_row->in_modifyinet, NULL, 0); \ + } while (0) + #define MODIFYUPDATEPARAMS(_params, _mod_pos, _row) do { \ _params[_mod_pos++] = tv_to_buf(&(_row->modifydate), NULL, 0); \ _params[_mod_pos++] = str_to_buf(_row->modifyby, NULL, 0); \ @@ -146,6 +229,7 @@ char *pqerrmsg(PGconn *conn) if (!_ok) \ break; \ TXT_TO_STR(INETDB, _fld, (_data)->createinet); \ + (_data)->buffers = (_data)->buffers; \ } while (0) #define SIMPLEDATEPARAMS(_params, _his_pos, _row) do { \ @@ -155,6 +239,13 @@ char *pqerrmsg(PGconn *conn) _params[_his_pos++] = str_to_buf(_row->createinet, NULL, 0); \ } while (0) +#define SIMPLEDATEPARAMSIN(_params, _his_pos, _row) do { \ + _params[_his_pos++] = tv_to_buf(&(_row->createdate), NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createby, NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createcode, NULL, 0); \ + _params[_his_pos++] = str_to_buf(_row->in_createinet, NULL, 0); \ + } while (0) + // For easy parameter constant strings #define PQPARAM1 "$1" #define PQPARAM2 "$1,$2" @@ -1389,6 +1480,7 @@ bool useratts_fill(PGconn *conn) return ok; } +// WARNING: workername must be intransient K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws, char *difficultydefault, char *idlenotificationenabled, char *idlenotificationtime, char *by, char *code, @@ -1438,7 +1530,7 @@ K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws, goto unitem; row->userid = userid; - STRNCPY(row->workername, workername); + row->in_workername = workername; if (difficultydefault && *difficultydefault) { diffdef = atoi(difficultydefault); // If out of the range, set it in the range @@ -1485,7 +1577,7 @@ K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, bool add_ws, par = 0; params[par++] = bigint_to_buf(row->workerid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->workername, NULL, 0); + params[par++] = str_to_buf(row->in_workername, NULL, 0); params[par++] = int_to_buf(row->difficultydefault, NULL, 0); params[par++] = str_to_buf(row->idlenotificationenabled, NULL, 0); params[par++] = int_to_buf(row->idlenotificationtime, NULL, 0); @@ -1650,7 +1742,7 @@ bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, par = 0; params[par++] = bigint_to_buf(row->workerid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->workername, NULL, 0); + params[par++] = str_to_buf(row->in_workername, NULL, 0); params[par++] = int_to_buf(row->difficultydefault, NULL, 0); params[par++] = str_to_buf(row->idlenotificationenabled, NULL, 0); params[par++] = int_to_buf(row->idlenotificationtime, NULL, 0); @@ -1765,7 +1857,7 @@ bool workers_fill(PGconn *conn) PQ_GET_FLD(res, i, "workername", field, ok); if (!ok) break; - TXT_TO_STR("workername", field, row->workername); + row->in_workername = intransient_str("workername", field); PQ_GET_FLD(res, i, "difficultydefault", field, ok); if (!ok) @@ -1803,7 +1895,7 @@ bool workers_fill(PGconn *conn) // Make sure a workerstatus exists for each worker find_create_workerstatus(false, false, row->userid, - row->workername, true, + row->in_workername, true, __FILE__, __func__, __LINE__); tick(); n++; @@ -2274,8 +2366,8 @@ bool payments_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item, if (add) { LOGDEBUG("%s(): adding new", __func__); - HISTORYDATEINIT(row, cd, by, code, inet); - HISTORYDATETRANSFER(trf_root, row); + HISTORYDATEINTRANS(row, cd, by, code, inet); + HISTORYDATETRANSFERIN(trf_root, row); par = 0; params[par++] = bigint_to_buf(row->paymentid, NULL, 0); @@ -2289,7 +2381,7 @@ bool payments_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item, params[par++] = double_to_buf(row->diffacc, NULL, 0); params[par++] = str_to_buf(row->committxn, NULL, 0); params[par++] = str_to_buf(row->commitblockhash, NULL, 0); - HISTORYDATEPARAMS(params, par, row); + HISTORYDATEPARAMSIN(params, par, row); PARCHK(par, params); ins = "insert into payments " @@ -2447,7 +2539,7 @@ bool payments_fill(PGconn *conn) break; TXT_TO_STR("commitblockhash", field, row->commitblockhash); - HISTORYDATEFLDS(res, i, row, ok); + HISTORYDATEIN(res, i, row, ok); if (!ok) break; @@ -3170,8 +3262,8 @@ int64_t workinfo_add(PGconn *conn, char *workinfoidstr, TXT_TO_BIGINT("reward", reward, row->reward); pool.reward = row->reward; - HISTORYDATEINIT(row, cd, by, code, inet); - HISTORYDATETRANSFER(trf_root, row); + HISTORYDATEINTRANS(row, cd, by, code, inet); + HISTORYDATETRANSFERIN(trf_root, row); K_WLOCK(workinfo_free); if (find_in_ktree(workinfo_root, item, ctx)) { @@ -3203,7 +3295,7 @@ int64_t workinfo_add(PGconn *conn, char *workinfoidstr, params[par++] = str_to_buf(row->in_bits, NULL, 0); params[par++] = str_to_buf(row->ntime, NULL, 0); params[par++] = bigint_to_buf(row->reward, NULL, 0); - HISTORYDATEPARAMS(params, par, row); + HISTORYDATEPARAMSIN(params, par, row); PARCHK(par, params); ins = "insert into workinfo " @@ -3441,7 +3533,7 @@ bool workinfo_fill(PGconn *conn) TXT_TO_BIGINT("reward", field, row->reward); pool.reward = row->reward; - HISTORYDATEFLDS(res, i, row, ok); + HISTORYDATEIN(res, i, row, ok); if (!ok) break; @@ -3553,20 +3645,20 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_ITEM *wi_item, (sta == NULL) ? "ok" : sta, 100.0 * shares->sdiff / workinfo->diff_target, shares->sdiff, workinfo->diff_target, - st = safe_text_nonull(shares->workername), + st = safe_text_nonull(shares->in_workername), pool.diffacc, est, pct); FREENULL(st); } } w_item = new_default_worker(conn, false, shares->userid, - shares->workername, shares->createby, + shares->in_workername, shares->createby, shares->createcode, shares->createinet, &(shares->createdate), trf_root); if (!w_item) { LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld", __func__, shares->userid, - st = safe_text_nonull(shares->workername), + st = safe_text_nonull(shares->in_workername), shares->createdate.tv_sec, shares->createdate.tv_usec); FREENULL(st); return false; @@ -3582,7 +3674,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_ITEM *wi_item, LOGDEBUG("%s(): workmarker exists for wid %"PRId64 " %"PRId64"/%s/%ld,%ld", __func__, shares->workinfoid, shares->userid, - st = safe_text_nonull(shares->workername), + st = safe_text_nonull(shares->in_workername), shares->createdate.tv_sec, shares->createdate.tv_usec); FREENULL(st); @@ -3590,7 +3682,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_ITEM *wi_item, } K_RLOCK(sharesummary_free); - ss_item = find_sharesummary(shares->userid, shares->workername, + ss_item = find_sharesummary(shares->userid, shares->in_workername, shares->workinfoid); if (ss_item) { DATA_SHARESUMMARY(sharesummary, ss_item); @@ -3601,7 +3693,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_ITEM *wi_item, "%"PRId64" %"PRId64"/%s/%ld,%ld", __func__, complete, shares->workinfoid, shares->userid, - st = safe_text_nonull(shares->workername), + st = safe_text_nonull(shares->in_workername), shares->createdate.tv_sec, shares->createdate.tv_usec); FREENULL(st); @@ -3711,7 +3803,7 @@ keep: " Early share procured", __func__, failed ? "***ESM " : EMPTY, early_shares->workinfoid, - st = safe_text_nonull(early_shares->workername), + st = safe_text_nonull(early_shares->in_workername), early_shares->createdate.tv_sec, early_shares->createdate.tv_usec, cd_buf, early_shares->oldcount, early_shares->redo); @@ -3728,7 +3820,7 @@ discard: " Early share discarded!%s", __func__, failed ? "***ESM " : EMPTY, early_shares->workinfoid, - st = safe_text_nonull(early_shares->workername), + st = safe_text_nonull(early_shares->in_workername), early_shares->createdate.tv_sec, early_shares->createdate.tv_usec, cd_buf, early_shares->oldcount, early_shares->redo, why); @@ -3746,11 +3838,12 @@ static void shareerrors_process_early(PGconn *conn, int64_t good_wid, tv_t *good_cd, K_TREE *trf_root); // DB Shares are stored by the summariser to ensure the reload is correct -bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername, - char *clientid, char *errn, char *enonce1, char *nonce2, - char *nonce, char *diff, char *sdiff, char *secondaryuserid, - char *ntime, char *address, char *agent, char *by, char *code, - char *inet, tv_t *cd, K_TREE *trf_root) +bool shares_add(PGconn *conn, char *workinfoid, char *username, + INTRANSIENT *in_workername, char *clientid, char *errn, + char *enonce1, char *nonce2, char *nonce, char *diff, + char *sdiff, char *secondaryuserid, char *ntime, char *address, + char *agent, char *by, char *code, char *inet, tv_t *cd, + K_TREE *trf_root) { K_TREE_CTX ctx[1]; K_ITEM *s_item = NULL, *s2_item = NULL, *u_item, *wi_item, *tmp_item; @@ -3764,7 +3857,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld", __func__, - workinfoid, st = safe_text_nonull(workername), nonce, + workinfoid, st = safe_text_nonull(in_workername->str), nonce, errn, cd->tv_sec, cd->tv_usec); FREENULL(st); @@ -3799,7 +3892,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername shares->userid = users->userid; TXT_TO_BIGINT("workinfoid", workinfoid, shares->workinfoid); - STRNCPY(shares->workername, workername); + shares->in_workername = in_workername->str; TXT_TO_INT("clientid", clientid, shares->clientid); TXT_TO_INT("errn", errn, shares->errn); STRNCPY(shares->enonce1, enonce1); @@ -3843,7 +3936,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername LOGMSG(sta, "%s() %"PRId64"/%s/%ld,%ld %s no workinfo! " "Early share queued!", __func__, shares->workinfoid, - st = safe_text_nonull(workername), + st = safe_text_nonull(in_workername->str), cd->tv_sec, cd->tv_usec, cd_buf); FREENULL(st); shares->redo = 0; @@ -3874,7 +3967,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername LOGWARNING("%s() duplicate DB share discarded: " "%"PRId64"/%s/%"PRId32"/%s/%.0f/%"PRId32"/%ld,%ld %s", __func__, shares->workinfoid, - st = safe_text_nonull(workername), + st = safe_text_nonull(in_workername->str), shares->clientid, shares->nonce, shares->sdiff, shares->errn, cd->tv_sec, cd->tv_usec, cd_buf); @@ -3910,7 +4003,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername LOGWARNING("%s() duplicate DB share discarded: " "%"PRId64"/%s/%"PRId32"/%s/%.0f/%"PRId32"/%ld,%ld %s", __func__, shares->workinfoid, - st = safe_text_nonull(workername), + st = safe_text_nonull(in_workername->str), shares->clientid, shares->nonce, shares->sdiff, shares->errn, cd->tv_sec, cd->tv_usec, cd_buf); @@ -3951,7 +4044,7 @@ bool shares_db(PGconn *conn, K_ITEM *s_item) par = 0; params[par++] = bigint_to_buf(row->workinfoid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->workername, NULL, 0); + params[par++] = str_to_buf(row->in_workername, NULL, 0); params[par++] = int_to_buf(row->clientid, NULL, 0); params[par++] = str_to_buf(row->enonce1, NULL, 0); params[par++] = str_to_buf(row->nonce2, NULL, 0); @@ -4141,7 +4234,7 @@ bool shares_fill(PGconn *conn) PQ_GET_FLD(res, i, "workername", field, ok); if (!ok) break; - TXT_TO_STR("workername", field, row->workername); + row->in_workername = intransient_str("workername", field); PQ_GET_FLD(res, i, "clientid", field, ok); if (!ok) @@ -4274,7 +4367,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors, LOGDEBUG("%s() add", __func__); w_item = new_default_worker(conn, false, shareerrors->userid, - shareerrors->workername, + shareerrors->in_workername, shareerrors->createby, shareerrors->createcode, shareerrors->createinet, @@ -4282,7 +4375,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors, if (!w_item) { LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld", __func__, shareerrors->userid, - st = safe_text_nonull(shareerrors->workername), + st = safe_text_nonull(shareerrors->in_workername), shareerrors->createdate.tv_sec, shareerrors->createdate.tv_usec); FREENULL(st); @@ -4301,7 +4394,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors, " %"PRId64"/%s/%ld,%ld", __func__, shareerrors->workinfoid, shareerrors->userid, - st = safe_text_nonull(shareerrors->workername), + st = safe_text_nonull(shareerrors->in_workername), shareerrors->createdate.tv_sec, shareerrors->createdate.tv_usec); FREENULL(st); @@ -4310,7 +4403,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors, K_RLOCK(sharesummary_free); ss_item = find_sharesummary(shareerrors->userid, - shareerrors->workername, + shareerrors->in_workername, shareerrors->workinfoid); if (ss_item) { DATA_SHARESUMMARY(sharesummary, ss_item); @@ -4322,7 +4415,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors, __func__, complete, shareerrors->workinfoid, shareerrors->userid, - st = safe_text_nonull(shareerrors->workername), + st = safe_text_nonull(shareerrors->in_workername), shareerrors->createdate.tv_sec, shareerrors->createdate.tv_usec); FREENULL(st); @@ -4424,7 +4517,7 @@ keep: " Early shareerror procured", __func__, failed ? "***ESM " : EMPTY, early_shareerrors->workinfoid, - st = safe_text_nonull(early_shareerrors->workername), + st = safe_text_nonull(early_shareerrors->in_workername), early_shareerrors->createdate.tv_sec, early_shareerrors->createdate.tv_usec, cd_buf, early_shareerrors->oldcount, early_shareerrors->redo); @@ -4441,7 +4534,7 @@ discard: " Early shareerror discarded!%s", __func__, failed ? "***ESM " : EMPTY, early_shareerrors->workinfoid, - st = safe_text_nonull(early_shareerrors->workername), + st = safe_text_nonull(early_shareerrors->in_workername), early_shareerrors->createdate.tv_sec, early_shareerrors->createdate.tv_usec, cd_buf, early_shareerrors->oldcount, early_shareerrors->redo, why); @@ -4457,7 +4550,7 @@ out: // Memory (and log file) only bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, - char *workername, char *clientid, char *errn, + INTRANSIENT *in_workername, char *clientid, char *errn, char *error, char *secondaryuserid, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) { @@ -4470,7 +4563,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld", __func__, - workinfoid, st = safe_text_nonull(workername), errn, + workinfoid, st = safe_text_nonull(in_workername->str), errn, error, cd->tv_sec, cd->tv_usec); FREENULL(st); @@ -4497,7 +4590,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, shareerrors->userid = users->userid; TXT_TO_BIGINT("workinfoid", workinfoid, shareerrors->workinfoid); - STRNCPY(shareerrors->workername, workername); + shareerrors->in_workername = in_workername->str; TXT_TO_INT("clientid", clientid, shareerrors->clientid); TXT_TO_INT("errn", errn, shareerrors->errn); STRNCPY(shareerrors->error, error); @@ -4527,7 +4620,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, LOGMSG(sta, "%s() %"PRId64"/%s/%ld,%ld %s no workinfo! " "Early shareerror queued!", __func__, shareerrors->workinfoid, - st = safe_text_nonull(workername), + st = safe_text_nonull(in_workername->str), cd->tv_sec, cd->tv_usec, cd_buf); FREENULL(st); shareerrors->redo = 0; @@ -4686,7 +4779,7 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, * and assume keysummaries are the same */ lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = 0; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; INIT_MARKERSUMMARY(&ms_look); ms_look.data = (void *)(&lookmarkersummary); @@ -4712,7 +4805,7 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, looksharesummary.workinfoid = workmarkers->workinfoidend; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&ss_look); ss_look.data = (void *)(&looksharesummary); @@ -4734,10 +4827,10 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, // Find/create the markersummary only once per worker change if (!ms_item || markersummary->userid != sharesummary->userid || - strcmp(markersummary->workername, sharesummary->workername) != 0) { + !INTREQ(markersummary->in_workername, sharesummary->in_workername)) { lookmarkersummary.markerid = workmarkers->markerid; lookmarkersummary.userid = sharesummary->userid; - lookmarkersummary.workername = sharesummary->workername; + lookmarkersummary.in_workername = sharesummary->in_workername; ms_look.data = (void *)(&lookmarkersummary); ms_item = find_in_ktree_nolock(ms_root, &ms_look, ms_ctx); @@ -4750,15 +4843,13 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, bzero(markersummary, sizeof(*markersummary)); markersummary->markerid = workmarkers->markerid; markersummary->userid = sharesummary->userid; - DUP_POINTER(markersummary_free, - markersummary->workername, - sharesummary->workername); + markersummary->in_workername = sharesummary->in_workername; add_to_ktree_nolock(ms_root, ms_item); LOGDEBUG("%s() new ms %"PRId64"/%"PRId64"/%s", shortname, markersummary->markerid, markersummary->userid, - st = safe_text(markersummary->workername)); + st = safe_text(markersummary->in_workername)); FREENULL(st); } else { DATA_MARKERSUMMARY(markersummary, ms_item); @@ -4813,7 +4904,7 @@ dokey: // Discard the sharesummaries looksharesummary.workinfoid = workmarkers->workinfoidend; looksharesummary.userid = MAXID; - looksharesummary.workername = EMPTY; + looksharesummary.in_workername = EMPTY; INIT_SHARESUMMARY(&ss_look); ss_look.data = (void *)(&looksharesummary); @@ -5228,7 +5319,7 @@ bool delete_markersummaries(PGconn *conn, WORKMARKERS *wm) lookmarkersummary.markerid = wm->markerid; lookmarkersummary.userid = 0; - lookmarkersummary.workername = EMPTY; + lookmarkersummary.in_workername = EMPTY; ms_count = diffacc = shareacc = 0; ms_item = NULL; @@ -5515,7 +5606,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, tv_t *cd, WHERE_FFL_PASS); } userid = s_row->userid; - workername = s_row->workername; + workername = s_row->in_workername; workinfoid = s_row->workinfoid; address = s_row->address; agent = s_row->agent; @@ -5526,7 +5617,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, tv_t *cd, WHERE_FFL_PASS); } userid = e_row->userid; - workername = e_row->workername; + workername = e_row->in_workername; workinfoid = e_row->workinfoid; } @@ -5560,8 +5651,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, tv_t *cd, DATA_SHARESUMMARY(row, ss_item); bzero(row, sizeof(*row)); row->userid = userid; - DUP_POINTER(sharesummary_free, row->workername, - workername); + row->in_workername = workername; row->workinfoid = workinfoid; } @@ -5673,7 +5763,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, tv_t *cd, LOGDEBUG("%s(): updating sharesummary not '%c'" " %"PRId64"/%s/%"PRId64"/%s", __func__, SUMMARY_NEW, row->userid, - st = safe_text_nonull(row->workername), + st = safe_text_nonull(row->in_workername), row->workinfoid, row->complete); FREENULL(st); } @@ -5883,7 +5973,7 @@ unparam: bool blocks_add(PGconn *conn, int32_t height, char *blockhash, char *confirmed, char *info, char *workinfoid, - char *username, char *workername, char *clientid, + char *username, INTRANSIENT *in_workername, char *clientid, char *enonce1, char *nonce2, char *nonce, char *reward, char *by, char *code, char *inet, tv_t *cd, bool igndup, char *id, K_TREE *trf_root) @@ -5902,9 +5992,15 @@ bool blocks_add(PGconn *conn, int32_t height, char *blockhash, bool ok = false, update_old = false; int n, par = 0; char *want = NULL, *st = NULL; + char *workername; LOGDEBUG("%s(): add", __func__); + if (in_workername) + workername = in_workername->str; + else + workername = EMPTY; + K_WLOCK(blocks_free); b_item = k_unlink_head(blocks_free); K_WUNLOCK(blocks_free); @@ -5955,7 +6051,7 @@ bool blocks_add(PGconn *conn, int32_t height, char *blockhash, STRNCPY(row->confirmed, confirmed); STRNCPY(row->info, info); TXT_TO_BIGINT("workinfoid", workinfoid, row->workinfoid); - STRNCPY(row->workername, workername); + row->in_workername = workername; TXT_TO_INT("clientid", clientid, row->clientid); STRNCPY(row->enonce1, enonce1); STRNCPY(row->nonce2, nonce2); @@ -5977,7 +6073,7 @@ bool blocks_add(PGconn *conn, int32_t height, char *blockhash, params[par++] = str_to_buf(row->blockhash, NULL, 0); params[par++] = bigint_to_buf(row->workinfoid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->workername, NULL, 0); + params[par++] = str_to_buf(row->in_workername, NULL, 0); params[par++] = int_to_buf(row->clientid, NULL, 0); params[par++] = str_to_buf(row->enonce1, NULL, 0); params[par++] = str_to_buf(row->nonce2, NULL, 0); @@ -6298,7 +6394,7 @@ flail: snprintf(tmp, sizeof(tmp), " Reward: %f, Worker: %s, ShareEst: %.1f %s%sUTC:%s", BTC_TO_D(row->reward), - st = safe_text_nonull(row->workername), + st = safe_text_nonull(row->in_workername), pool.diffacc, est, pct, cd_buf); FREENULL(st); if (pool.workinfoid < row->workinfoid) { @@ -6397,7 +6493,7 @@ bool blocks_fill(PGconn *conn) PQ_GET_FLD(res, i, "workername", field, ok); if (!ok) break; - TXT_TO_STR("workername", field, row->workername); + row->in_workername = intransient_str("workername", field); PQ_GET_FLD(res, i, "clientid", field, ok); if (!ok) @@ -6605,15 +6701,15 @@ bool miningpayouts_add(PGconn *conn, bool add, K_ITEM *mp_item, if (add) { LOGDEBUG("%s(): adding new", __func__); - HISTORYDATEINIT(row, cd, by, code, inet); - HISTORYDATETRANSFER(trf_root, row); + HISTORYDATEINTRANS(row, cd, by, code, inet); + HISTORYDATETRANSFERIN(trf_root, row); par = 0; params[par++] = bigint_to_buf(row->payoutid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); params[par++] = double_to_buf(row->diffacc, NULL, 0); params[par++] = bigint_to_buf(row->amount, NULL, 0); - HISTORYDATEPARAMS(params, par, row); + HISTORYDATEPARAMSIN(params, par, row); PARCHK(par, params); ins = "insert into miningpayouts " @@ -6744,7 +6840,7 @@ bool miningpayouts_fill(PGconn *conn) break; TXT_TO_BIGINT("amount", field, row->amount); - HISTORYDATEFLDS(res, i, row, ok); + HISTORYDATEIN(res, i, row, ok); if (!ok) break; @@ -7688,7 +7784,7 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des, // TODO: discard them from RAM bool auths_add(PGconn *conn, char *poolinstance, char *username, - char *workername, char *clientid, char *enonce1, + INTRANSIENT *in_workername, char *clientid, char *enonce1, char *useragent, char *preauth, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, bool addressuser, USERS **users, WORKERS **workers, @@ -7738,7 +7834,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username, STRNCPY(row->poolinstance, poolinstance); row->userid = (*users)->userid; // since update=false, a dup will be ok and do nothing when igndup=true - w_item = new_worker(conn, false, row->userid, workername, + w_item = new_worker(conn, false, row->userid, in_workername->str, DIFFICULTYDEFAULT_DEF_STR, IDLENOTIFICATIONENABLED_DEF, IDLENOTIFICATIONTIME_DEF_STR, @@ -7747,7 +7843,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username, goto unitem; DATA_WORKERS(*workers, w_item); - STRNCPY(row->workername, workername); + row->in_workername = in_workername->str; TXT_TO_INT("clientid", clientid, row->clientid); STRNCPY(row->enonce1, enonce1); STRNCPY(row->useragent, useragent); @@ -7764,8 +7860,8 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username, // Shouldn't actually be possible unless twice in the logs tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s(): Duplicate auths ignored %s/%s/%s", - __func__, poolinstance, st = safe_text_nonull(workername), - cd_buf); + __func__, poolinstance, + st = safe_text_nonull(in_workername->str), cd_buf); FREENULL(st); /* Let them mine, that's what matters :) @@ -8080,10 +8176,9 @@ clean: // To RAM bool userstats_add(char *poolinstance, char *elapsed, char *username, - char *workername, char *hashrate, char *hashrate5m, - char *hashrate1hr, char *hashrate24hr, bool idle, - bool eos, char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root) + INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, + char *hashrate1hr, char *hashrate24hr, bool idle, bool eos, + char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) { K_ITEM *us_item, *u_item, *us_match, *us_next; USERSTATS *row, *match, *next; @@ -8114,7 +8209,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, } DATA_USERS(users, u_item); row->userid = users->userid; - TXT_TO_STR("workername", workername, row->workername); + row->in_workername = in_workername->str; TXT_TO_DOUBLE("hashrate", hashrate, row->hashrate); TXT_TO_DOUBLE("hashrate5m", hashrate5m, row->hashrate5m); TXT_TO_DOUBLE("hashrate1hr", hashrate1hr, row->hashrate1hr); @@ -8187,10 +8282,10 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, // To RAM bool workerstats_add(char *poolinstance, char *elapsed, char *username, - char *workername, char *hashrate, char *hashrate5m, - char *hashrate1hr, char *hashrate24hr, bool idle, - char *instances, char *by, char *code, char *inet, - tv_t *cd, K_TREE *trf_root) + INTRANSIENT *in_workername, char *hashrate, + char *hashrate5m, char *hashrate1hr, char *hashrate24hr, + bool idle, char *instances, char *by, char *code, + char *inet, tv_t *cd, K_TREE *trf_root) { K_ITEM *us_item, *u_item, *us_match; USERSTATS *row, *match; @@ -8216,14 +8311,14 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username, LOGERR("%s(): unknown user '%s' (worker=%s)", __func__, usr = safe_text_nonull(username), - wrk = safe_text_nonull(workername)); + wrk = safe_text_nonull(in_workername->str)); FREENULL(usr); FREENULL(wrk); return false; } DATA_USERS(users, u_item); row->userid = users->userid; - TXT_TO_STR("workername", workername, row->workername); + row->in_workername = in_workername->str; TXT_TO_DOUBLE("hashrate", hashrate, row->hashrate); TXT_TO_DOUBLE("hashrate5m", hashrate5m, row->hashrate5m); TXT_TO_DOUBLE("hashrate1hr", hashrate1hr, row->hashrate1hr); @@ -8279,13 +8374,13 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code, DATA_MARKERSUMMARY(row, ms_item); - MODIFYDATEPOINTERS(markersummary_free, row, cd, by, code, inet); - MODIFYDATETRANSFER(markersummary_free, trf_root, row); + MODIFYDATEINTRANS(row, cd, by, code, inet); + MODIFYDATETRANSFERIN(trf_root, row); par = 0; params[par++] = bigint_to_buf(row->markerid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->workername, NULL, 0); + params[par++] = str_to_buf(row->in_workername, NULL, 0); params[par++] = double_to_buf(row->diffacc, NULL, 0); params[par++] = double_to_buf(row->diffsta, NULL, 0); params[par++] = double_to_buf(row->diffdup, NULL, 0); @@ -8303,7 +8398,7 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code, params[par++] = tv_to_buf(&(row->firstshareacc), NULL, 0); params[par++] = tv_to_buf(&(row->lastshareacc), NULL, 0); params[par++] = double_to_buf(row->lastdiffacc, NULL, 0); - MODIFYDATEPARAMS(params, par, row); + MODIFYDATEPARAMSIN(params, par, row); PARCHK(par, params); ins = "insert into markersummary " @@ -8315,7 +8410,7 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code, LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f", __func__, row->markerid, row->userid, - st = safe_text_nonull(row->workername), + st = safe_text_nonull(row->in_workername), row->diffacc); FREENULL(st); @@ -8525,8 +8620,7 @@ bool markersummary_fill(PGconn *conn) PQ_GET_FLD(res, i, "workername", field, ok); if (!ok) break; - TXT_TO_PTR("workername", field, row->workername); - LIST_MEM_ADD(markersummary_free, row->workername); + row->in_workername = intransient_str("workername", field); PQ_GET_FLD(res, i, "diffacc", field, ok); if (!ok) @@ -8613,7 +8707,7 @@ bool markersummary_fill(PGconn *conn) break; TXT_TO_DOUBLE("lastdiffacc", field, row->lastdiffacc); - MODIFYDATEFLDPOINTERS(markersummary_free, res, i, row, ok); + MODIFYDATEIN(res, i, row, ok); if (!ok) break; @@ -8713,7 +8807,7 @@ bool keysummary_add(PGconn *conn, K_ITEM *ks_item, char *by, char *code, DATA_KEYSUMMARY(row, ks_item); - SIMPLEDATEPOINTERS(markersummary_free, row, cd, by, code, inet); + SIMPLEDATEINTRANS(row, cd, by, code, inet); par = 0; params[par++] = bigint_to_buf(row->markerid, NULL, 0); @@ -8736,7 +8830,7 @@ bool keysummary_add(PGconn *conn, K_ITEM *ks_item, char *by, char *code, params[par++] = tv_to_buf(&(row->firstshareacc), NULL, 0); params[par++] = tv_to_buf(&(row->lastshareacc), NULL, 0); params[par++] = double_to_buf(row->lastdiffacc, NULL, 0); - SIMPLEDATEPARAMS(params, par, row); + SIMPLEDATEPARAMSIN(params, par, row); PARCHK(par, params); ins = "insert into keysummary "