From 5837652c58e614add1215b8b18d23fbfeeba8d13 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 9 Sep 2014 22:11:05 +1000 Subject: [PATCH 1/6] php - add address and 1.5% to pplns --- pool/page_pplns.php | 28 +++++++++++++++++++++++++++- src/ckdb.c | 32 +++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/pool/page_pplns.php b/pool/page_pplns.php index 42f47acc..475569ea 100644 --- a/pool/page_pplns.php +++ b/pool/page_pplns.php @@ -90,6 +90,8 @@ Block: $pg .= '%'; $pg .= 'Base BTC'; $pg .= 'Avg Hashrate'; + $pg .= 'BTC -1.5%'; + $pg .= 'Address'; $pg .= "\n"; $diffacc_total = $ans['diffacc_total']; @@ -98,12 +100,18 @@ Block: $reward = $ans['block_reward'] / pow(10,8); $elapsed = $ans['pplns_elapsed']; $count = $ans['rows']; + $tot_btc = 0; + $tot_pay = 0; for ($i = 0; $i < $count; $i++) { $diffacc_user = $ans['diffacc_user:'.$i]; $diffacc_percent = number_format(100.0 * $diffacc_user / $diffacc_total, 2).'%'; - $diffacc_btc = number_format($reward * $diffacc_user / $diffacc_total, 8); + $base_btc = $reward * $diffacc_user / $diffacc_total; + $diffacc_btc = number_format($base_btc, 8); $avg_hash = number_format($diffacc_user / $elapsed * pow(2,32), 0); + $pay_btc = $base_btc * 0.985; + $dsp_btc = number_format($pay_btc, 8); + $payaddress = $ans['payaddress:'.$i]; if (($i % 2) == 0) $row = 'even'; @@ -116,8 +124,26 @@ Block: $pg .= "$diffacc_percent"; $pg .= "$diffacc_btc"; $pg .= "$avg_hash"; + $pg .= "$dsp_btc"; + $pg .= "$payaddress"; $pg .= "\n"; + + $tot_btc += $base_btc; + $tot_pay += $pay_btc; } + if (($i % 2) == 0) + $row = 'even'; + else + $row = 'odd'; + + $pg .= ""; + $pg .= ''; + $pg .= "".number_format($tot_btc,8).""; + $pg .= ''; + $pg .= ''.number_format($pay_btc,8).''; + $pg .= ''; + $pg .= "\n"; + $pg .= "\n"; } diff --git a/src/ckdb.c b/src/ckdb.c index 80492eba..d71634c6 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -47,7 +47,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9" -#define CKDB_VERSION DB_VERSION"-0.273" +#define CKDB_VERSION DB_VERSION"-0.275" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -10012,18 +10012,28 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, u_item = find_userid(miningpayouts->userid); K_RUNLOCK(users_free); if (u_item) { + K_ITEM *pa_item; + PAYMENTADDRESSES *pa; + char *payaddress; + + pa_item = find_paymentaddresses(miningpayouts->userid); + if (pa_item) { + DATA_PAYMENTADDRESSES(pa, pa_item); + payaddress = pa->payaddress; + } else + payaddress = "none"; + DATA_USERS(users, u_item); snprintf(tmp, sizeof(tmp), - "user:%d=%s%c", - rows, - users->username, - FLDSEP); + "user:%d=%s%cpayaddress:%d=%s%c", + rows, users->username, FLDSEP, + rows, payaddress, FLDSEP); + } else { snprintf(tmp, sizeof(tmp), - "user:%d=%"PRId64"%c", - rows, - miningpayouts->userid, - FLDSEP); + "user:%d=%"PRId64"%cpayaddress:%d=none%c", + rows, miningpayouts->userid, FLDSEP, + rows, FLDSEP); } APPEND_REALLOC(buf, off, len, tmp); @@ -10038,9 +10048,9 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, rows++; } snprintf(tmp, sizeof(tmp), - "rows=%d%c,flds=%s%c", + "rows=%d%cflds=%s%c", rows, FLDSEP, - "user,diffacc_user", FLDSEP); + "user,diffacc_user,payaddress", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s%c", From fae6ff96ec4ef9a0ef055ca8b66c32a5cb9fa082 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 9 Sep 2014 22:34:29 +1000 Subject: [PATCH 2/6] php - pplns correct total --- pool/page_pplns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/page_pplns.php b/pool/page_pplns.php index 475569ea..610f00c4 100644 --- a/pool/page_pplns.php +++ b/pool/page_pplns.php @@ -140,7 +140,7 @@ Block: $pg .= ''; $pg .= "".number_format($tot_btc,8).""; $pg .= ''; - $pg .= ''.number_format($pay_btc,8).''; + $pg .= ''.number_format($tot_pay,8).''; $pg .= ''; $pg .= "\n"; From e2d1dba22a0cabacadd6f67f44b43b842ba8079c Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Sep 2014 08:22:20 +1000 Subject: [PATCH 3/6] ckdb - set all dbload to abort early on shutdown --- src/ckdb.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index d71634c6..26e16ac2 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -47,7 +47,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9" -#define CKDB_VERSION DB_VERSION"-0.275" +#define CKDB_VERSION DB_VERSION"-0.276" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -2915,6 +2915,11 @@ static bool users_fill(PGconn *conn) item = k_unlink_head(users_free); DATA_USERS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "userid", field, ok); if (!ok) break; @@ -3363,6 +3368,11 @@ static bool workers_fill(PGconn *conn) item = k_unlink_head(workers_free); DATA_WORKERS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "userid", field, ok); if (!ok) break; @@ -3652,6 +3662,11 @@ static bool paymentaddresses_fill(PGconn *conn) item = k_unlink_head(paymentaddresses_free); DATA_PAYMENTADDRESSES(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "paymentaddressid", field, ok); if (!ok) break; @@ -3759,6 +3774,11 @@ static bool payments_fill(PGconn *conn) item = k_unlink_head(payments_free); DATA_PAYMENTS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "userid", field, ok); if (!ok) break; @@ -4383,7 +4403,7 @@ static bool workinfo_fill(PGconn *conn) // TODO: select the data based on sharesummary since old data isn't needed // however, the ageing rules for workinfo will decide that also - // keep the last block + current? + // keep the last block + current? Rules will depend on payout scheme also sel = "select " // "workinfoid,poolinstance,transactiontree,merklehash,prevhash," "workinfoid,poolinstance,merklehash,prevhash," @@ -4417,6 +4437,11 @@ static bool workinfo_fill(PGconn *conn) item = k_unlink_head(workinfo_free); DATA_WORKINFO(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "workinfoid", field, ok); if (!ok) break; @@ -5229,6 +5254,11 @@ static bool sharesummary_fill(PGconn *conn) item = k_unlink_head(sharesummary_free); DATA_SHARESUMMARY(row, item); + if (everyone_die) { + ok = false; + break; + } + row->inserted = true; PQ_GET_FLD(res, i, "userid", field, ok); @@ -6045,6 +6075,11 @@ static bool blocks_fill(PGconn *conn) item = k_unlink_head(blocks_free); DATA_BLOCKS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "height", field, ok); if (!ok) break; @@ -6320,6 +6355,11 @@ static bool miningpayouts_fill(PGconn *conn) item = k_unlink_head(miningpayouts_free); DATA_MININGPAYOUTS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "miningpayoutid", field, ok); if (!ok) break; @@ -6582,6 +6622,11 @@ static bool auths_fill(PGconn *conn) item = k_unlink_head(auths_free); DATA_AUTHS(row, item); + if (everyone_die) { + ok = false; + break; + } + PQ_GET_FLD(res, i, "authid", field, ok); if (!ok) break; @@ -6817,6 +6862,11 @@ static bool poolstats_fill(PGconn *conn) item = k_unlink_head(poolstats_free); DATA_POOLSTATS(row, item); + if (everyone_die) { + ok = false; + break; + } + row->stored = true; PQ_GET_FLD(res, i, "poolinstance", field, ok); @@ -7260,6 +7310,11 @@ static bool userstats_fill(PGconn *conn) item = k_unlink_head(userstats_free); DATA_USERSTATS(row, item); + if (everyone_die) { + ok = false; + break; + } + // Not a DB field row->poolinstance[0] = '\0'; From 396d9d6a80daf6f37f341993baf04e4f34130ac3 Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Sep 2014 17:09:35 +1000 Subject: [PATCH 4/6] sql - script to show the diffacc of a block for verification --- sql/bs.sql | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sql/bs.sql diff --git a/sql/bs.sql b/sql/bs.sql new file mode 100644 index 00000000..9c948f20 --- /dev/null +++ b/sql/bs.sql @@ -0,0 +1,44 @@ +SET SESSION AUTHORIZATION 'postgres'; + +DO $$ +DECLARE + hi INT; + hi0 INT; + wi BIGINT; + wi0 BIGINT; + ssc INT; + da BIGINT; +BEGIN + hi := 318177; + + -- This will randomly choose between multiple blocks of the same height + -- if we happen to orphan ourselves + select workinfoid from blocks where height = hi + and expirydate > '6666-06-01' into wi; + IF NOT found THEN + RAISE EXCEPTION 'Block % not found', hi; + END IF; + + select max(height) from blocks where height < hi into hi0; + IF found THEN + wi0 := -1; + ELSE + select workinfoid from blocks where height = hi0 + and expirydate > '6666-06-01' into Wi0; + END IF; + + RAISE WARNING 'Block: %(%)', hi, wi; + RAISE WARNING 'Previous block: %(%)', hi0, wi0; + + select count(*) from sharesummary where workinfoid > wi0 + and workinfoid <= wi and complete = 'n' into ssc; + + IF ssc > 0 THEN + RAISE EXCEPTION 'Unaged sharesummary records: %', ssc; + ELSE + select sum(diffacc) from sharesummary where workinfoid > wi0 + and workinfoid <= wi into da; + + RAISE WARNING 'diffacc: %', da; + END IF; +END $$; From f22357df94aba433b90f3fa4ac222edfe233d47d Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Sep 2014 17:14:21 +1000 Subject: [PATCH 5/6] sql - reverse incorrect logic from no starting block --- sql/bs.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/bs.sql b/sql/bs.sql index 9c948f20..5c701067 100644 --- a/sql/bs.sql +++ b/sql/bs.sql @@ -20,7 +20,7 @@ BEGIN END IF; select max(height) from blocks where height < hi into hi0; - IF found THEN + IF NOT found THEN wi0 := -1; ELSE select workinfoid from blocks where height = hi0 From a3ccc289ffbd4de5677c059e44c6e8bc68e7fa23 Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Sep 2014 17:41:39 +1000 Subject: [PATCH 6/6] sql - format the diffacc with commas --- sql/bs.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/bs.sql b/sql/bs.sql index 5c701067..4d526cc0 100644 --- a/sql/bs.sql +++ b/sql/bs.sql @@ -39,6 +39,6 @@ BEGIN select sum(diffacc) from sharesummary where workinfoid > wi0 and workinfoid <= wi into da; - RAISE WARNING 'diffacc: %', da; + RAISE WARNING 'diffacc: %', to_char(da::bigint, 'FM999,999,999,999,999,990'); END IF; END $$;