Browse Source

ckdb/ckp - add reward count to shifts table

master
kanoi 9 years ago
parent
commit
df5c372557
  1. 2
      pool/page_shifts.php
  2. 7
      src/ckdb.c
  3. 6
      src/ckdb.h
  4. 12
      src/ckdb_cmd.c
  5. 75
      src/ckdb_data.c
  6. 18
      src/ckdb_dbio.c

2
pool/page_shifts.php

@ -14,6 +14,7 @@ function doshifts($data, $user)
$pg .= "<td class=dr>Avg Hs</td>"; $pg .= "<td class=dr>Avg Hs</td>";
$pg .= "<td class=dr>Shares</td>"; $pg .= "<td class=dr>Shares</td>";
$pg .= "<td class=dr>Avg Share</td>"; $pg .= "<td class=dr>Avg Share</td>";
$pg .= "<td class=dr>Rewards</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
if (($ans['STATUS'] != 'ok') || !isset($ans['prefix_all'])) if (($ans['STATUS'] != 'ok') || !isset($ans['prefix_all']))
@ -66,6 +67,7 @@ function doshifts($data, $user)
else else
$avgsh = 0; $avgsh = 0;
$pg .= '<td class=dr>'.number_format($avgsh, 2).'</td>'; $pg .= '<td class=dr>'.number_format($avgsh, 2).'</td>';
$pg .= '<td class=dr>'.$ans['rewards:'.$i].'</td>';
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
} }

7
src/ckdb.c

@ -776,8 +776,6 @@ static bool getdata3()
goto sukamudai; goto sukamudai;
if (!(ok = miningpayouts_fill(conn)) || everyone_die) if (!(ok = miningpayouts_fill(conn)) || everyone_die)
goto sukamudai; goto sukamudai;
if (!(ok = payouts_fill(conn)) || everyone_die)
goto sukamudai;
} }
if (!(ok = workinfo_fill(conn)) || everyone_die) if (!(ok = workinfo_fill(conn)) || everyone_die)
goto sukamudai; goto sukamudai;
@ -786,6 +784,11 @@ static bool getdata3()
/* must be after workinfo */ /* must be after workinfo */
if (!(ok = workmarkers_fill(conn)) || everyone_die) if (!(ok = workmarkers_fill(conn)) || everyone_die)
goto sukamudai; goto sukamudai;
if (!confirm_sharesummary) {
/* must be after workmarkers */
if (!(ok = payouts_fill(conn)) || everyone_die)
goto sukamudai;
}
if (!(ok = markersummary_fill(conn)) || everyone_die) if (!(ok = markersummary_fill(conn)) || everyone_die)
goto sukamudai; goto sukamudai;
if (!confirm_sharesummary && !everyone_die) if (!confirm_sharesummary && !everyone_die)

6
src/ckdb.h

@ -1901,6 +1901,9 @@ typedef struct workmarkers {
int64_t workinfoidstart; int64_t workinfoidstart;
char *description; char *description;
char status[TXT_FLAG+1]; char status[TXT_FLAG+1];
int rewards; // non-DB field
double pps_value; // non-DB field
double rewarded; // non-DB field
HISTORYDATECONTROLFIELDS; HISTORYDATECONTROLFIELDS;
} WORKMARKERS; } WORKMARKERS;
@ -2343,11 +2346,12 @@ extern bool make_markersummaries(bool msg, char *by, char *code, char *inet,
extern void dsp_workmarkers(K_ITEM *item, FILE *stream); extern void dsp_workmarkers(K_ITEM *item, FILE *stream);
extern cmp_t cmp_workmarkers(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_workmarkers(K_ITEM *a, K_ITEM *b);
extern cmp_t cmp_workmarkers_workinfoid(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_workmarkers_workinfoid(K_ITEM *a, K_ITEM *b);
extern K_ITEM *find_workmarkers(int64_t workinfoid, bool anystatus, char status); extern K_ITEM *find_workmarkers(int64_t workinfoid, bool anystatus, char status, K_TREE_CTX *ctx);
extern K_ITEM *find_workmarkerid(int64_t markerid, bool anystatus, char status); extern K_ITEM *find_workmarkerid(int64_t markerid, bool anystatus, char status);
extern bool workmarkers_generate(PGconn *conn, char *err, size_t siz, extern bool workmarkers_generate(PGconn *conn, char *err, size_t siz,
char *by, char *code, char *inet, tv_t *cd, char *by, char *code, char *inet, tv_t *cd,
K_TREE *trf_root, bool none_error); K_TREE *trf_root, bool none_error);
extern bool reward_shifts(PAYOUTS *payouts, bool lock, int delta);
extern cmp_t cmp_marks(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_marks(K_ITEM *a, K_ITEM *b);
extern K_ITEM *find_marks(int64_t workinfoid); extern K_ITEM *find_marks(int64_t workinfoid);
extern const char *marks_marktype(char *marktype); extern const char *marks_marktype(char *marktype);

12
src/ckdb_cmd.c

@ -4789,6 +4789,8 @@ static char *cmd_payouts(PGconn *conn, char *cmd, char *id, tv_t *now,
snprintf(reply, siz, "failed payout %"PRId64, payoutid); snprintf(reply, siz, "failed payout %"PRId64, payoutid);
return strdup(reply); return strdup(reply);
} }
// Original wasn't generated, so reward it
reward_shifts(payouts2, true, 1);
DATA_PAYOUTS(payouts2, p2_item); DATA_PAYOUTS(payouts2, p2_item);
DATA_PAYOUTS(old_payouts2, old_p2_item); DATA_PAYOUTS(old_payouts2, old_p2_item);
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
@ -4858,6 +4860,8 @@ static char *cmd_payouts(PGconn *conn, char *cmd, char *id, tv_t *now,
snprintf(reply, siz, "failed payout %"PRId64, payoutid); snprintf(reply, siz, "failed payout %"PRId64, payoutid);
return strdup(reply); return strdup(reply);
} }
// Original was generated, so undo the reward
reward_shifts(payouts2, true, -1);
DATA_PAYOUTS(payouts2, p2_item); DATA_PAYOUTS(payouts2, p2_item);
DATA_PAYOUTS(old_payouts2, old_p2_item); DATA_PAYOUTS(old_payouts2, old_p2_item);
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
@ -4875,6 +4879,7 @@ static char *cmd_payouts(PGconn *conn, char *cmd, char *id, tv_t *now,
return strdup(reply); return strdup(reply);
TXT_TO_BIGINT("payoutid", transfer_data(i_payoutid), payoutid); TXT_TO_BIGINT("payoutid", transfer_data(i_payoutid), payoutid);
// payouts_full_expire updates the shift rewards
p_item = payouts_full_expire(conn, payoutid, now, true); p_item = payouts_full_expire(conn, payoutid, now, true);
if (!p_item) { if (!p_item) {
snprintf(reply, siz, "failed payout %"PRId64, payoutid); snprintf(reply, siz, "failed payout %"PRId64, payoutid);
@ -4911,6 +4916,7 @@ static char *cmd_payouts(PGconn *conn, char *cmd, char *id, tv_t *now,
return strdup(reply); return strdup(reply);
TXT_TO_CTV("addrdate", transfer_data(i_addrdate), addrdate); TXT_TO_CTV("addrdate", transfer_data(i_addrdate), addrdate);
// process_pplns updates the shift rewards
if (addrdate.tv_sec == 0) if (addrdate.tv_sec == 0)
ok = process_pplns(height, blockhash, NULL); ok = process_pplns(height, blockhash, NULL);
else else
@ -5355,6 +5361,10 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id,
rows, reply, FLDSEP); rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "rewards:%d=%d%c",
rows, wm->rewards, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
rows++; rows++;
// Setup for next shift // Setup for next shift
@ -5394,7 +5404,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id,
* other workers start >= 0 and finish <= rows-1 */ * other workers start >= 0 and finish <= rows-1 */
snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c", snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c",
rows, FLDSEP, rows, FLDSEP,
"markerid,shift,start,end", FLDSEP); "markerid,shift,start,end,rewards", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "arn=%s", "Shifts"); snprintf(tmp, sizeof(tmp), "arn=%s", "Shifts");

75
src/ckdb_data.c

@ -2070,7 +2070,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code,
} }
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);
wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED); wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED, NULL);
K_RUNLOCK(workmarkers_free); K_RUNLOCK(workmarkers_free);
// Should never happen? // Should never happen?
if (wm_item && !reloading) { if (wm_item && !reloading) {
@ -3589,7 +3589,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
* block - so abort * block - so abort
* The fix is to create the marks and summaries needed via * The fix is to create the marks and summaries needed via
* cmd_marks() then manually trigger the payout generation * cmd_marks() then manually trigger the payout generation
* TODO: via cmd_payouts() ... which isn't available yet */ * via cmd_payouts() */
LOGEMERG("%s(): payout had < 1 (%"PRId64") workmarkers for " LOGEMERG("%s(): payout had < 1 (%"PRId64") workmarkers for "
"block %"PRId32"/%"PRId64"/%s/%s/%"PRId64 "block %"PRId32"/%"PRId64"/%s/%s/%"PRId64
" beginwi=%"PRId64" ss=%"PRId64" diff=%.1f", " beginwi=%"PRId64" ss=%"PRId64" diff=%.1f",
@ -3810,20 +3810,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
pa_item = pa_item->next; pa_item = pa_item->next;
} }
} else { } else {
/* Address user or normal user without a paymentaddress /* Address user or normal user without a paymentaddress */
* TODO: user table needs a flag to say which it is ... if (users->userbits & USER_ADDRESS) {
* for now use a simple test */
bool gotaddr = false;
size_t len;
switch (users->username[0]) {
case '1':
case '3':
len = strlen(users->username);
if (len >= ADDR_MIN_LEN && len <= ADDR_MAX_LEN)
gotaddr = true;
}
if (gotaddr) {
K_WLOCK(payments_free); K_WLOCK(payments_free);
pay_item = k_unlink_head(payments_free); pay_item = k_unlink_head(payments_free);
K_WUNLOCK(payments_free); K_WUNLOCK(payments_free);
@ -3906,6 +3894,9 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
ss_count, wm_count, ms_count, usercount, diff_times, ss_count, wm_count, ms_count, usercount, diff_times,
diff_add, cd_buf); diff_add, cd_buf);
/* At this point the payout is complete, but it just hasn't been
* flagged complete yet in the DB */
K_WLOCK(payouts_free); K_WLOCK(payouts_free);
p2_item = k_unlink_head(payouts_free); p2_item = k_unlink_head(payouts_free);
K_WUNLOCK(payouts_free); K_WUNLOCK(payouts_free);
@ -3931,13 +3922,20 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
ok = payouts_add(conn, true, p2_item, &old_p2_item, (char *)by_default, ok = payouts_add(conn, true, p2_item, &old_p2_item, (char *)by_default,
(char *)__func__, (char *)inet_default, &now, NULL, (char *)__func__, (char *)inet_default, &now, NULL,
false); false);
if (!ok) { if (!ok) {
/* All that's required is to mark the payout GENERATED
* since it already exists in the DB and in RAM, thus a manual
* cmd_payouts 'generated' is all that's needed to fix it */
LOGEMERG("%s(): payout %"PRId64" for block %"PRId32"/%s " LOGEMERG("%s(): payout %"PRId64" for block %"PRId32"/%s "
"NOT set generated - it needs to be set manually", "NOT set generated - it needs to be set manually",
__func__, payouts->payoutid, blocks->height, __func__, payouts->payoutid, blocks->height,
blocks->blockhash); blocks->blockhash);
} }
// Flag each shift as rewarded
reward_shifts(payouts2, true, 1);
CKPQDisco(&conn, conned); CKPQDisco(&conn, conned);
goto oku; goto oku;
@ -4146,7 +4144,7 @@ K_ITEM *_find_markersummary(int64_t markerid, int64_t workinfoid,
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
if (markerid == 0) { if (markerid == 0) {
wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED); wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED, NULL);
if (wm_item) { if (wm_item) {
DATA_WORKMARKERS(wm, wm_item); DATA_WORKMARKERS(wm, wm_item);
markerid = wm->markerid; markerid = wm->markerid;
@ -4277,12 +4275,15 @@ cmp_t cmp_workmarkers_workinfoid(K_ITEM *a, K_ITEM *b)
return c; return c;
} }
K_ITEM *find_workmarkers(int64_t workinfoid, bool anystatus, char status) K_ITEM *find_workmarkers(int64_t workinfoid, bool anystatus, char status, K_TREE_CTX *ctx)
{ {
WORKMARKERS workmarkers, *wm; WORKMARKERS workmarkers, *wm;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx0[1];
K_ITEM look, *wm_item; K_ITEM look, *wm_item;
if (ctx == NULL)
ctx = ctx0;
workmarkers.expirydate.tv_sec = default_expiry.tv_sec; workmarkers.expirydate.tv_sec = default_expiry.tv_sec;
workmarkers.expirydate.tv_usec = default_expiry.tv_usec; workmarkers.expirydate.tv_usec = default_expiry.tv_usec;
workmarkers.workinfoidend = workinfoid-1; workmarkers.workinfoidend = workinfoid-1;
@ -4401,7 +4402,8 @@ static bool gen_workmarkers(PGconn *conn, MARKS *stt, bool after, MARKS *fin,
* sort order and matching errors */ * sort order and matching errors */
if (wi_fin->workinfoid >= wi_stt->workinfoid) { if (wi_fin->workinfoid >= wi_stt->workinfoid) {
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);
old_wm_item = find_workmarkers(wi_fin->workinfoid, true, '\0'); old_wm_item = find_workmarkers(wi_fin->workinfoid, true, '\0',
NULL);
K_RUNLOCK(workmarkers_free); K_RUNLOCK(workmarkers_free);
DATA_WORKMARKERS_NULL(old_wm, old_wm_item); DATA_WORKMARKERS_NULL(old_wm, old_wm_item);
if (old_wm_item && (WMREADY(old_wm->status) || if (old_wm_item && (WMREADY(old_wm->status) ||
@ -4580,6 +4582,39 @@ bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by,
return true; return true;
} }
// delta = 1 or -1 i.e. reward or undo reward
bool reward_shifts(PAYOUTS *payouts, bool lock, int delta)
{
// TODO: PPS calculations
K_TREE_CTX ctx[1];
K_ITEM *wm_item;
WORKMARKERS *wm;
bool did_one = false;
if (lock)
K_WLOCK(workmarkers_free);
wm_item = find_workmarkers(payouts->workinfoidstart, false,
MARKER_PROCESSED, ctx);
while (wm_item) {
DATA_WORKMARKERS(wm, wm_item);
if (wm->workinfoidstart > payouts->workinfoidend)
break;
/* The status doesn't matter since we want the rewards passed
* onto the PROCESSED status if it isn't already processed */
if (CURRENT(&(wm->expirydate))) {
wm->rewards += delta;
did_one = true;
}
wm_item = next_in_ktree(ctx);
}
if (lock)
K_WUNLOCK(workmarkers_free);
return did_one;
}
// order by expirydate asc,workinfoid asc // order by expirydate asc,workinfoid asc
// TODO: add poolinstance // TODO: add poolinstance
cmp_t cmp_marks(K_ITEM *a, K_ITEM *b) cmp_t cmp_marks(K_ITEM *a, K_ITEM *b)

18
src/ckdb_dbio.c

@ -2959,7 +2959,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
if (reloading && !confirm_sharesummary) { if (reloading && !confirm_sharesummary) {
// We only need to know if the workmarker is processed // We only need to know if the workmarker is processed
wm_item = find_workmarkers(shares->workinfoid, false, wm_item = find_workmarkers(shares->workinfoid, false,
MARKER_PROCESSED); MARKER_PROCESSED, NULL);
if (wm_item) { if (wm_item) {
LOGDEBUG("%s(): workmarker exists for wid %"PRId64 LOGDEBUG("%s(): workmarker exists for wid %"PRId64
" %"PRId64"/%s/%ld,%ld", " %"PRId64"/%s/%ld,%ld",
@ -3260,7 +3260,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
if (reloading && !confirm_sharesummary) { if (reloading && !confirm_sharesummary) {
// We only need to know if the workmarker is processed // We only need to know if the workmarker is processed
wm_item = find_workmarkers(shareerrors->workinfoid, false, wm_item = find_workmarkers(shareerrors->workinfoid, false,
MARKER_PROCESSED); MARKER_PROCESSED, NULL);
if (wm_item) { if (wm_item) {
LOGDEBUG("%s(): workmarker exists for wid %"PRId64 LOGDEBUG("%s(): workmarker exists for wid %"PRId64
" %"PRId64"/%s/%ld,%ld", " %"PRId64"/%s/%ld,%ld",
@ -4024,7 +4024,8 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
} }
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);
wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED); wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED,
NULL);
K_RUNLOCK(workmarkers_free); K_RUNLOCK(workmarkers_free);
if (wm_item) { if (wm_item) {
DATA_WORKMARKERS(wm, wm_item); DATA_WORKMARKERS(wm, wm_item);
@ -5465,6 +5466,12 @@ K_ITEM *payouts_full_expire(PGconn *conn, int64_t payoutid, tv_t *now, bool lock
DATA_PAYMENTS_NULL(payments, pm_item); DATA_PAYMENTS_NULL(payments, pm_item);
} }
if (PAYGENERATED(payouts->status)) {
// Original was generated, so undo the reward
reward_shifts(payouts, true, -1);
}
ok = true; ok = true;
matane: matane:
if (begun) if (begun)
@ -5613,6 +5620,9 @@ bool payouts_fill(PGconn *conn)
payouts_id_root = add_to_ktree(payouts_id_root, item, cmp_payouts_id); payouts_id_root = add_to_ktree(payouts_id_root, item, cmp_payouts_id);
k_add_head(payouts_store, item); k_add_head(payouts_store, item);
if (CURRENT(&(row->expirydate)) && PAYGENERATED(row->status))
reward_shifts(row, false, 1);
tick(); tick();
} }
if (!ok) { if (!ok) {
@ -6517,7 +6527,7 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add,
if (markerid == 0) { if (markerid == 0) {
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);
old_wm_item = find_workmarkers(workinfoidend, true, '\0'); old_wm_item = find_workmarkers(workinfoidend, true, '\0', NULL);
K_RUNLOCK(workmarkers_free); K_RUNLOCK(workmarkers_free);
} else { } else {
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);

Loading…
Cancel
Save