From 71de6d635b18df9140cccc6f3621b11710b24cd5 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 22 Sep 2015 04:21:08 +0200 Subject: [PATCH] db: save blocks worker id for worker stats Note: need database change! --- sql/2015-09-20-blocks_worker.sql | 4 ++++ stratum/client_submit.cpp | 4 ++-- stratum/share.cpp | 9 +++++---- stratum/share.h | 3 ++- web/yaamp/core/backend/blocks.php | 18 ++++++++++++++++-- web/yaamp/core/backend/clear.php | 2 +- web/yaamp/modules/site/worker_results.php | 15 +++++++++++++-- 7 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 sql/2015-09-20-blocks_worker.sql diff --git a/sql/2015-09-20-blocks_worker.sql b/sql/2015-09-20-blocks_worker.sql new file mode 100644 index 0000000..13d514d --- /dev/null +++ b/sql/2015-09-20-blocks_worker.sql @@ -0,0 +1,4 @@ +-- Recent additions to add after db init (.gz) + +ALTER TABLE `blocks` ADD `workerid` INT(11) NULL AFTER `userid`; + diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index f030ebf..98e1855 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -189,7 +189,7 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL { debuglog("*** ACCEPTED %s %d\n", coind_aux->name, coind_aux->height+1); - block_add(client->userid, coind_aux->id, coind_aux->height, target_to_diff(coin_target_aux), + block_add(client->userid, client->workerid, coind_aux->id, coind_aux->height, target_to_diff(coin_target_aux), target_to_diff(hash_int), coind_aux->aux.hash, ""); } @@ -248,7 +248,7 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL strcpy(hash1, submitvalues->hash_hex); } - block_add(client->userid, coind->id, templ->height, + block_add(client->userid, client->workerid, coind->id, templ->height, target_to_diff(coin_target), target_to_diff(hash_int), hash1, submitvalues->hash_be); diff --git a/stratum/share.cpp b/stratum/share.cpp index f4c7149..c8ea49f 100644 --- a/stratum/share.cpp +++ b/stratum/share.cpp @@ -167,7 +167,7 @@ void share_prune(YAAMP_DB *db) void block_prune(YAAMP_DB *db) { int count = 0; - char buffer[128*1024] = "insert into blocks (height, blockhash, coin_id, userid, category, difficulty, difficulty_user, time, algo) values "; + char buffer[128*1024] = "insert into blocks (height, blockhash, coin_id, userid, workerid, category, difficulty, difficulty_user, time, algo) values "; g_list_block.Enter(); for(CLI li = g_list_block.first; li; li = li->next) @@ -186,8 +186,8 @@ void block_prune(YAAMP_DB *db) } if(count) strcat(buffer, ","); - sprintf(buffer+strlen(buffer), "(%d, '%s', %d, %d, 'new', %f, %f, %d, '%s')", - block->height, block->hash, block->coinid, block->userid, + sprintf(buffer+strlen(buffer), "(%d, '%s', %d, %d, %d, 'new', %f, %f, %d, '%s')", + block->height, block->hash, block->coinid, block->userid, block->workerid, block->difficulty, block->difficulty_user, (int)block->created, g_stratum_algo); object_delete(block); @@ -198,13 +198,14 @@ void block_prune(YAAMP_DB *db) if(count) db_query(db, buffer); } -void block_add(int userid, int coinid, int height, double difficulty, double difficulty_user, const char *hash1, const char *hash2) +void block_add(int userid, int workerid, int coinid, int height, double difficulty, double difficulty_user, const char *hash1, const char *hash2) { YAAMP_BLOCK *block = new YAAMP_BLOCK; memset(block, 0, sizeof(YAAMP_BLOCK)); block->created = time(NULL); block->userid = userid; + block->workerid = workerid; block->coinid = coinid; block->height = height; block->difficulty = difficulty; diff --git a/stratum/share.h b/stratum/share.h index f5ad19c..bf01107 100644 --- a/stratum/share.h +++ b/stratum/share.h @@ -58,6 +58,7 @@ public: bool confirmed; int userid; + int workerid; int coinid; int height; @@ -95,7 +96,7 @@ inline void submit_delete(YAAMP_OBJECT *object) void block_prune(YAAMP_DB *db); -void block_add(int userid, int coinid, int height, double difficulty, double difficulty_user, const char *hash1, const char *hash2); +void block_add(int userid, int workerid, int coinid, int height, double difficulty, double difficulty_user, const char *hash1, const char *hash2); void block_confirm(int coinid, const char *hash); YAAMP_SUBMIT *submit_add(int remoteid, double difficulty); diff --git a/web/yaamp/core/backend/blocks.php b/web/yaamp/core/backend/blocks.php index ebde18f..685d468 100644 --- a/web/yaamp/core/backend/blocks.php +++ b/web/yaamp/core/backend/blocks.php @@ -113,11 +113,25 @@ function BackendBlockFind1($coinid = NULL) $db_block->amount = $tx['details'][0]['amount']; $db_block->confirmations = $tx['confirmations']; $db_block->price = $coin->price; + + // save worker to compute blocs found per worker (current workers stats) + // now made directly in stratum - require DB update 2015-09-20 + if (empty($db_block->workerid) && $db_block->userid > 0) { + $db_block->workerid = (int) dboscalar( + "SELECT workerid FROM shares WHERE userid=:user AND coinid=:coin AND valid=1 AND time <= :time ". + "ORDER BY difficulty DESC LIMIT 1", array( + ':user' => $db_block->userid, + ':coin' => $db_block->coin_id, + ':time' => $db_block->time + )); + if (!$db_block->workerid) $db_block->workerid = NULL; + } + if (!$db_block->save()) debuglog(__FUNCTION__.": unable to insert block!"); if($db_block->category != 'orphan') - BackendBlockNew($coin, $db_block); + BackendBlockNew($coin, $db_block); // will drop shares } } @@ -255,7 +269,7 @@ function BackendBlockFind2($coinid = NULL) } // masternode earnings... - if ($transaction['amount'] == 0 && $transaction['generated']) { + if (empty($db_block->userid) && $transaction['amount'] == 0 && $transaction['generated']) { $db_block->algo = 'MN'; $tx = $remote->getrawtransaction($transaction['txid'], 1); diff --git a/web/yaamp/core/backend/clear.php b/web/yaamp/core/backend/clear.php index 76b2a36..0e64849 100644 --- a/web/yaamp/core/backend/clear.php +++ b/web/yaamp/core/backend/clear.php @@ -8,7 +8,7 @@ function BackendClearEarnings($coinid = NULL) $delay = time() - (int) YAAMP_PAYMENTS_FREQ; else $delay = time() - (YAAMP_PAYMENTS_FREQ / 2); - $total_cleared = 0; + $total_cleared = 0.0; $sqlFilter = $coinid ? " AND coinid=".intval($coinid) : ''; diff --git a/web/yaamp/modules/site/worker_results.php b/web/yaamp/modules/site/worker_results.php index 5889dfc..050b063 100644 --- a/web/yaamp/modules/site/worker_results.php +++ b/web/yaamp/modules/site/worker_results.php @@ -19,6 +19,7 @@ echo "Diff"; echo "Shares"; echo "Bad"; echo "%"; +echo "Found"; echo ""; echo ""; echo ""; @@ -83,10 +84,20 @@ foreach($workers as $worker) } echo ""; + $worker_blocs = dboscalar("SELECT COUNT(id) as blocs FROM blocks WHERE workerid=:worker AND algo=:algo", array( + ':worker'=> $worker->id, + ':algo'=> $algo + )); + $user_blocs = dboscalar("SELECT COUNT(id) as blocs FROM blocks WHERE userid=:user AND algo=:algo + AND time > (SELECT min(time) FROM workers WHERE algo=:algo)", array( + ':user'=> $worker->userid, + ':algo'=> $algo + )); echo ''.number_format($percent,1,'.','').'%'; - echo "$name"; - echo ""; + echo ''.$worker_blocs.' / '.$user_blocs.''; + echo ''.$name.''; + echo ''; } echo "";