db: save blocks worker id for worker stats

Note: need database change!
This commit is contained in:
Tanguy Pruvot 2015-09-22 04:21:08 +02:00
parent 294da52732
commit 71de6d635b
7 changed files with 43 additions and 12 deletions

View file

@ -0,0 +1,4 @@
-- Recent additions to add after db init (.gz)
ALTER TABLE `blocks` ADD `workerid` INT(11) NULL AFTER `userid`;

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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) : '';

View file

@ -19,6 +19,7 @@ echo "<th>Diff</th>";
echo "<th>Shares</th>";
echo "<th>Bad</th>";
echo "<th>%</th>";
echo "<th>Found</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead><tbody>";
@ -83,10 +84,20 @@ foreach($workers as $worker)
}
echo "</td>";
$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 '<td>'.number_format($percent,1,'.','').'%</td>';
echo "<td>$name</td>";
echo "</tr>";
echo '<td>'.$worker_blocs.' / '.$user_blocs.'</td>';
echo '<td>'.$name.'</td>';
echo '</tr>';
}
echo "</tbody></table>";