commit
71162d0d67
@ -35,24 +35,39 @@ $aAllBlocks = $block->getAllUnconfirmed(max($config['network_confirmations'],$co
|
||||
|
||||
$header = false;
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
!$header ? $log->logInfo("ID\tHeight\tBlockhash\tConfirmations") : $header = true;
|
||||
$strLogMask = "| %10.10s | %10.10s | %-64.64s | %5.5s | %5.5s | %-8.8s";
|
||||
$aBlockInfo = $bitcoin->getblock($aBlock['blockhash']);
|
||||
// Fetch this blocks transaction details to find orphan blocks
|
||||
$aTxDetails = $bitcoin->gettransaction($aBlockInfo['tx'][0]);
|
||||
$log->logInfo($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']);
|
||||
if ($aTxDetails['details'][0]['category'] == 'orphan') {
|
||||
// We have an orphaned block, we need to invalidate all transactions for this one
|
||||
if ($block->setConfirmations($aBlock['id'], -1)) {
|
||||
$log->logInfo(" Block marked as orphan");
|
||||
$status = 'ORPHAN';
|
||||
} else {
|
||||
$status = 'ERROR';
|
||||
$log->logError(" Block became orphaned but unable to update database entries");
|
||||
}
|
||||
if (!$header) {
|
||||
$log->logInfo(sprintf($strLogMask, 'ID', 'Height', 'Blockhash', 'Old', 'New', 'Status'));
|
||||
$header = true;
|
||||
}
|
||||
$log->logInfo(sprintf($strLogMask, $aBlock['id'], $aBlock['height'], $aBlock['blockhash'], $aBlock['confirmations'], $aBlockInfo['confirmations'], $status));
|
||||
continue;
|
||||
}
|
||||
if ($aBlock['confirmations'] == $aBlockInfo['confirmations']) {
|
||||
$log->logDebug(' No update needed');
|
||||
} else if (!$block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) {
|
||||
$log->logError(' Failed to update block confirmations: ' . $block->getCronMessage());
|
||||
continue;
|
||||
} else {
|
||||
if (!$block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) {
|
||||
$log->logError(' Failed to update block confirmations: ' . $block->getCronMessage());
|
||||
$status = 'ERROR';
|
||||
} else {
|
||||
$status = 'UPDATED';
|
||||
}
|
||||
if (!$header) {
|
||||
$log->logInfo(sprintf($strLogMask, 'ID', 'Height', 'Blockhash', 'Old', 'New', 'Status'));
|
||||
$header = true;
|
||||
}
|
||||
$log->logInfo(sprintf($strLogMask, $aBlock['id'], $aBlock['height'], $aBlock['blockhash'], $aBlock['confirmations'], $aBlockInfo['confirmations'], $status));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ chdir(dirname(__FILE__));
|
||||
// Include all settings and classes
|
||||
require_once('shared.inc.php');
|
||||
|
||||
|
||||
// Fetch our last block found from the DB as a starting point
|
||||
$aLastBlock = @$block->getLast();
|
||||
$strLastBlockHash = $aLastBlock['blockhash'];
|
||||
@ -47,18 +48,19 @@ if (empty($aTransactions['transactions'])) {
|
||||
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
||||
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
||||
// Table header, printe once if we found a block
|
||||
!$header ? $log->logInfo("Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime") : $header = true;
|
||||
$strLogMask = "| %-20.20s | %15.15s | %10.10s | %13.13s | %25.25s | %18.18s |";
|
||||
// Loop through our unaccounted blocks
|
||||
if (!$header) {
|
||||
$log->logInfo('Starting RPC block detecion, blocks are stored in Database');
|
||||
$log->logInfo(sprintf($strLogMask, 'Blockhash', 'Height', 'Amount', 'Confirmations', 'Difficulty', 'Time'));
|
||||
$header = true;
|
||||
}
|
||||
|
||||
$aBlockRPCInfo = $bitcoin->getblock($aData['blockhash']);
|
||||
$config['reward_type'] == 'block' ? $aData['amount'] = $aData['amount'] : $aData['amount'] = $config['reward'];
|
||||
$aData['height'] = $aBlockRPCInfo['height'];
|
||||
$aData['difficulty'] = $aBlockRPCInfo['difficulty'];
|
||||
$log->logInfo(substr($aData['blockhash'], 0, 15) . "...\t" .
|
||||
$aData['height'] . "\t" .
|
||||
$aData['amount'] . "\t" .
|
||||
$aData['confirmations'] . "\t\t" .
|
||||
$aData['difficulty'] . "\t" .
|
||||
strftime("%Y-%m-%d %H:%M:%S", $aData['time']));
|
||||
$log->logInfo(sprintf($strLogMask, substr($aData['blockhash'], 0, 17)."...", $aData['height'], $aData['amount'], $aData['confirmations'], $aData['difficulty'], strftime("%Y-%m-%d %H:%M:%S", $aData['time'])));
|
||||
if ( ! empty($aBlockRPCInfo['flags']) && preg_match('/proof-of-stake/', $aBlockRPCInfo['flags']) ) {
|
||||
$log->logInfo("Block above with height " . $aData['height'] . " not added to database, proof-of-stake block!");
|
||||
continue;
|
||||
@ -75,8 +77,10 @@ $aAllBlocks = $block->getAllUnsetShareId('ASC');
|
||||
if (empty($aAllBlocks)) {
|
||||
$log->logDebug('No new blocks without share_id found in database');
|
||||
} else {
|
||||
$log->logInfo('Starting block share detection, this may take a while');
|
||||
$strLogMask = "| %8.8s | %10.10s | %15.15s | %10.10s | %25.25s | %-15.15s | %-15.15s | %18.18s |";
|
||||
// Loop through our unaccounted blocks
|
||||
$log->logInfo("Block ID\tHeight\t\tAmount\tShare ID\tShares\tFinder\tWorker\t\tType");
|
||||
$log->logInfo(sprintf($strLogMask, 'Block ID', 'Height', 'Amount', 'Share ID', 'Shares', 'Finder', 'Worker', 'Type'));
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
if (empty($aBlock['share_id'])) {
|
||||
// Fetch share information
|
||||
@ -124,16 +128,8 @@ if (empty($aAllBlocks)) {
|
||||
$monitoring->endCronjob($cron_name, 'E0005', 0, true);
|
||||
}
|
||||
|
||||
$log->logInfo(
|
||||
$aBlock['id'] . "\t\t"
|
||||
. $aBlock['height'] . "\t\t"
|
||||
. $aBlock['amount'] . "\t"
|
||||
. $iCurrentUpstreamId . "\t\t"
|
||||
. $iRoundShares . "\t"
|
||||
. "[$iAccountId] " . $user->getUserName($iAccountId) . "\t"
|
||||
. $iWorker . "\t"
|
||||
. $share->share_type
|
||||
);
|
||||
// Print formatted row
|
||||
$log->logInfo(sprintf($strLogMask, $aBlock['id'], $aBlock['height'], $aBlock['amount'], $iCurrentUpstreamId, $iRoundShares, "[$iAccountId] " . $user->getUserName($iAccountId), $iWorker, $share->share_type));
|
||||
|
||||
// Store new information
|
||||
if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId))
|
||||
|
||||
@ -38,6 +38,7 @@ if (empty($aAllBlocks)) {
|
||||
$monitoring->endCronjob($cron_name, 'E0011', 0, true, false);
|
||||
}
|
||||
|
||||
$log->logDebug('Starting PPLNS payout process');
|
||||
$count = 0;
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// If we have unaccounted blocks without share_ids, they might not have been inserted yet
|
||||
@ -77,29 +78,31 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
$config['reward_type'] == 'block' ? $dReward = $aBlock['amount'] : $dReward = $config['reward'];
|
||||
$aRoundAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']);
|
||||
|
||||
$log->logInfo('Target: ' . $pplns_target . '; Shares: ' . $iRoundShares . '; Height: ' . $aBlock['height'] . '; Amount: ' . $aBlock['amount'] . '; Found by ID: ' . $aBlock['account_id']);
|
||||
$strLogMask = "| %20.20s | %20.20s | %8.8s | %10.10s | %15.15s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'PPLNS Target', 'Actual Shares', 'Height', 'Amount', 'Finder'));
|
||||
$log->logInfo(sprintf($strLogMask, $pplns_target, $iRoundShares, $aBlock['height'], $aBlock['amount'], $user->getUsername($aBlock['account_id'])));
|
||||
|
||||
if ($iRoundShares >= $pplns_target) {
|
||||
$log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares");
|
||||
$log->logDebug(" Matching or exceeding PPLNS target of $pplns_target with $iRoundShares");
|
||||
$iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']);
|
||||
// We need to go one ID lower due to `id >` or we won't match if minimum share ID == $aBlock['share_id']
|
||||
$aAccountShares = $share->getSharesForAccounts($iMinimumShareId - 1, $aBlock['share_id']);
|
||||
if (empty($aAccountShares)) {
|
||||
$log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height'] . ', Block ID: ' . $aBlock['id']);
|
||||
$log->logFatal(" No shares found for this block, aborted! Block Height : " . $aBlock['height'] . ', Block ID: ' . $aBlock['id']);
|
||||
$monitoring->endCronjob($cron_name, 'E0013', 1, true);
|
||||
}
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
$iNewRoundShares += $aData['valid'];
|
||||
}
|
||||
$log->logInfo('Adjusting round to PPLNS target of ' . $pplns_target . ' shares used ' . $iNewRoundShares);
|
||||
$log->logInfo(' Adjusting round to PPLNS target of ' . $pplns_target . ' shares used ' . $iNewRoundShares);
|
||||
$iRoundShares = $iNewRoundShares;
|
||||
} else {
|
||||
$log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares");
|
||||
$log->logDebug(" Not able to match PPLNS target of $pplns_target with $iRoundShares");
|
||||
// We need to fill up with archived shares
|
||||
// Grab the full current round shares since we didn't match target
|
||||
$aAccountShares = $aRoundAccountShares;
|
||||
if (empty($aAccountShares)) {
|
||||
$log->logFatal("No shares found for this block, aborted! Block height: " . $aBlock['height'] . ', Block ID:' . $aBlock['id']);
|
||||
$log->logFatal(" No shares found for this block, aborted! Block height: " . $aBlock['height'] . ', Block ID:' . $aBlock['id']);
|
||||
$monitoring->endCronjob($cron_name, 'E0013', 1, true);
|
||||
}
|
||||
|
||||
@ -112,27 +115,31 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// Add archived shares to users current shares, if we have any in archive
|
||||
if (is_array($aArchiveShares)) {
|
||||
$log->logDebug('Found shares in archive to match PPLNS target, calculating per-user shares');
|
||||
$strLogMask = "| %-20.20s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s |";
|
||||
$log->logDebug(sprintf($strLogMask, 'Username', 'Round Valid', 'Archive Valid', 'Total Valid', 'Round Invalid', 'Archive Invalid', 'Total Invalid'));
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
if (array_key_exists($aData['username'], $aArchiveShares)) {
|
||||
$log->logDebug('Found user ' . $aData['username'] . ' in archived shares');
|
||||
$log->logDebug(' valid : ' . $aAccountShares[$key]['valid'] . ' + ' . $aArchiveShares[$aData['username']]['valid'] . ' = ' . ($aAccountShares[$key]['valid'] + $aArchiveShares[$aData['username']]['valid']) );
|
||||
$log->logDebug(' invalid : ' . $aAccountShares[$key]['invalid'] . ' + ' . $aArchiveShares[$aData['username']]['invalid'] . ' = ' . ($aAccountShares[$key]['invalid'] + $aArchiveShares[$aData['username']]['invalid']) );
|
||||
$log->logDebug(sprintf($strLogMask, $aData['username'],
|
||||
$aAccountShares[$key]['valid'], $aArchiveShares[$aData['username']]['valid'], ($aAccountShares[$key]['valid'] + $aArchiveShares[$aData['username']]['valid']),
|
||||
$aAccountShares[$key]['invalid'], $aArchiveShares[$aData['username']]['invalid'], ($aAccountShares[$key]['invalid'] + $aArchiveShares[$aData['username']]['invalid']))
|
||||
);
|
||||
$aAccountShares[$key]['valid'] += $aArchiveShares[$aData['username']]['valid'];
|
||||
$aAccountShares[$key]['invalid'] += $aArchiveShares[$aData['username']]['invalid'];
|
||||
}
|
||||
}
|
||||
// reverse payout
|
||||
if ($config['pplns']['reverse_payout']) {
|
||||
$log->logDebug('Reverse payout enabled, adding shelved shares for all users');
|
||||
$aSharesData = NULL;
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
$aSharesData[$aData['username']] = $aData;
|
||||
}
|
||||
// Add users from archive not in current round
|
||||
$strLogMask = "| %-20.20s | %15.15s | %15.15s |";
|
||||
$log->logDebug(sprintf($strLogMask, 'Username', 'Shelved Valid', 'Shelved Invalid'));
|
||||
foreach($aArchiveShares as $key => $aArchData) {
|
||||
if (!array_key_exists($aArchData['account'], $aSharesData)) {
|
||||
$log->logDebug('Adding user ' . $aArchData['account'] . ' to round shares');
|
||||
$log->logDebug(' valid : ' . $aArchData['valid']);
|
||||
$log->logDebug(' invalid : ' . $aArchData['invalid']);
|
||||
$log->logDebug(sprintf($strLogMask, $aArchData['account'], $aArchData['valid'], $aArchData['invalid']));
|
||||
$aArchData['username'] = $aArchData['account'];
|
||||
$aSharesData[$aArchData['account']] = $aArchData;
|
||||
}
|
||||
@ -174,7 +181,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
}
|
||||
|
||||
// Table header for account shares
|
||||
$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee");
|
||||
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
|
||||
|
||||
// Loop through all accounts that have found shares for this round
|
||||
foreach ($aTotalAccountShares as $key => $aData) {
|
||||
@ -200,14 +208,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
|
||||
|
||||
// Verbose output of this users calculations
|
||||
$log->logInfo($aData['id'] . "\t" .
|
||||
$aData['username'] . "\t" .
|
||||
$aData['pplns_valid'] . "\t" .
|
||||
$aData['pplns_invalid'] . "\t" .
|
||||
number_format($aData['percentage'], 8) . "\t" .
|
||||
number_format($aData['payout'], 8) . "\t" .
|
||||
number_format($aData['donation'], 8) . "\t" .
|
||||
number_format($aData['fee'], 8));
|
||||
$log->logInfo(
|
||||
sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'],
|
||||
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)
|
||||
)
|
||||
);
|
||||
|
||||
// Add new credit transaction
|
||||
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
|
||||
|
||||
@ -31,7 +31,7 @@ if ($config['payout_system'] != 'pps') {
|
||||
$log->logInfo("\tPlease activate this cron in configuration via payout_system = pps\n");
|
||||
exit(0);
|
||||
}
|
||||
$log->logInfo("Starting PPS Payout...");
|
||||
$log->logDebug('Starting PPS Payout');
|
||||
|
||||
// Fetch all transactions since our last block
|
||||
if ( $bitcoin->can_connect() === true ){
|
||||
@ -46,43 +46,37 @@ if ( $bitcoin->can_connect() === true ){
|
||||
// We support some dynamic reward targets but fall back to our fixed value
|
||||
// Re-calculate after each run due to re-targets in this loop
|
||||
// We don't use the classes implementation just in case people start mucking around with it
|
||||
$strRewardType = $config['pps']['reward']['type'];
|
||||
if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > 0) {
|
||||
$pps_reward = round($block->getAvgBlockReward($config['pps']['blockavg']['blockcount']));
|
||||
$log->logInfo("\tPPS reward using block average, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty);
|
||||
} else {
|
||||
if ($config['pps']['reward']['type'] == 'block') {
|
||||
if ($aLastBlock = $block->getLast()) {
|
||||
$pps_reward = $aLastBlock['amount'];
|
||||
$log->logInfo("\tPPS value (Last Block): " . $pps_reward);
|
||||
} else {
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
$strRewardType = 'fixed';
|
||||
}
|
||||
} else {
|
||||
$pps_reward = $config['pps']['reward']['default'];
|
||||
$log->logInfo("\tPPS value (Default): " . $pps_reward);
|
||||
}
|
||||
}
|
||||
|
||||
// Per-share value to be paid out to users
|
||||
$pps_value = round($pps_reward / (pow(2, $config['target_bits']) * $dDifficulty), 12);
|
||||
$log->logInfo("\tPPS value: " . $pps_value);
|
||||
|
||||
// Find our last share accounted and last inserted share for PPS calculations
|
||||
|
||||
if (!$iPreviousShareId = $setting->getValue('pps_last_share_id')) {
|
||||
$log->logError("Failed to fetch Previous Share ID. This is okay on your first run or when without any shares. ERROR: " . $setting->getCronError());
|
||||
$iPreviousShareId = 0;
|
||||
}
|
||||
$log->logInfo("\tPPS last paid out share ID: " . $iPreviousShareId);
|
||||
|
||||
if (!$iLastShareId = $share->getLastInsertedShareId()) {
|
||||
$log->logError("Failed to fetch Last Inserted PPS Share ID. ERROR: " . $share->getCronError());
|
||||
}
|
||||
$log->logInfo("\tPPS last inserted share ID: " . $iLastShareId);
|
||||
|
||||
if ($iPreviousShareId >= $iLastShareId) {
|
||||
$log->logInfo('Not enough shares to account for, aborting until next run');
|
||||
$log->logInfo('No new shares to account for. Exiting until next run.');
|
||||
$monitoring->endCronjob($cron_name, 'E0080', 0, true, false);
|
||||
}
|
||||
|
||||
@ -94,10 +88,14 @@ if (!$aAccountShares = $share->getSharesForAccounts($iPreviousShareId, $iLastSha
|
||||
$log->logInfo("\tQuery Completed...");
|
||||
|
||||
if (!empty($aAccountShares)) {
|
||||
// Info for this payout
|
||||
$log->logInfo("\tPPS reward type: " . $config['pps']['reward']['type'] . ", amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty . "\tPPS value: " . $pps_value);
|
||||
$log->logInfo("\tRunning through accounts to process shares...");
|
||||
$log->logInfo("\tID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee");
|
||||
// Runtime information for this payout
|
||||
$log->logInfo('Runtime information for this payout');
|
||||
$strLogMask = "| %-15.15s | %15.15s | %15.15s | %15.15s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'PPS reward type', 'Reward Base', 'Difficulty', 'PPS Value'));
|
||||
$log->logInfo(sprintf($strLogMask, $strRewardType, $pps_reward, $dDifficulty, $pps_value));
|
||||
$log->logInfo('Per-user payout information');
|
||||
$strLogMask = "| %8.8s | %25.25s | %15.15s | %15.15s | %18.18s | %18.18s | %18.18s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'User ID', 'Username', 'Invalid', 'Valid', ' * PPS Value', ' = Payout', 'Donation', 'Fee'));
|
||||
}
|
||||
|
||||
foreach ($aAccountShares as $aData) {
|
||||
@ -109,7 +107,7 @@ foreach ($aAccountShares as $aData) {
|
||||
|
||||
// MPOS uses a base difficulty setting to avoid showing weightened shares
|
||||
// Since we need weightened shares here, we go back to the proper value for payouts
|
||||
$aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 8);
|
||||
$aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 12);
|
||||
|
||||
// Defaults
|
||||
$aData['fee' ] = 0;
|
||||
@ -117,18 +115,14 @@ foreach ($aAccountShares as $aData) {
|
||||
|
||||
// Calculate block fees
|
||||
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
|
||||
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
|
||||
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 12);
|
||||
// Calculate donation amount
|
||||
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
|
||||
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 12);
|
||||
|
||||
$log->logInfo($aData['id'] . "\t" .
|
||||
$aData['username'] . "\t" .
|
||||
$aData['invalid'] . "\t" .
|
||||
$aData['valid'] * pow(2, ($config['difficulty'] - 16)) . "\t*\t" .
|
||||
number_format($pps_value, 12) . "\t=\t" .
|
||||
number_format($aData['payout'], 8) . "\t" .
|
||||
number_format($aData['donation'], 8) . "\t" .
|
||||
number_format($aData['fee'], 8));
|
||||
$log->logInfo(sprintf(
|
||||
$strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'] * pow(2, ($config['difficulty'] - 16)),
|
||||
number_format($pps_value, 12), number_format($aData['payout'], 12), number_format($aData['donation'], 12), number_format($aData['fee'], 12)
|
||||
));
|
||||
|
||||
// Add new credit transaction
|
||||
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit_PPS'))
|
||||
@ -144,13 +138,13 @@ foreach ($aAccountShares as $aData) {
|
||||
}
|
||||
|
||||
// Store our last inserted ID for the next run
|
||||
$log->logInfo("\tFetching Last Share ID...");
|
||||
$log->logInfo("\tStoring last paid share ID...");
|
||||
if (!$setting->setValue('pps_last_share_id', $iLastShareId)) {
|
||||
$log->logError("Failed to fetch Last Share ID. ERROR: " . $setting->getCronError());
|
||||
$log->logError("Failed to store last paid share ID. ERROR: " . $setting->getCronError());
|
||||
}
|
||||
|
||||
// Fetch all unaccounted blocks
|
||||
$log->logInfo("\tFetching unaccounted blocks.");
|
||||
$log->logInfo("\tFetching unaccounted blocks for round closure");
|
||||
if ($aAllBlocks = $block->getAllUnaccounted('ASC')) {
|
||||
// Go through blocks and archive/delete shares that have been accounted for
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
@ -158,11 +152,8 @@ if ($aAllBlocks = $block->getAllUnaccounted('ASC')) {
|
||||
$log->logInfo("\tProcess each block for Previous Share ID.");
|
||||
$iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0;
|
||||
if (!is_numeric($aBlock['share_id'])) {
|
||||
$log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
|
||||
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
|
||||
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
$log->logError("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
|
||||
$monitoring->endCronjob($cron_name, 'E0062', 0, true);
|
||||
}
|
||||
// Per account statistics
|
||||
$log->logInfo("\tRefresh user statistics...");
|
||||
|
||||
@ -40,7 +40,8 @@ if (empty($aAllBlocks)) {
|
||||
|
||||
$count = 0;
|
||||
// Table header for account shares
|
||||
$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee");
|
||||
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// If we have unaccounted blocks without share_ids, they might not have been inserted yet
|
||||
if (!$aBlock['share_id']) {
|
||||
@ -94,14 +95,10 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
|
||||
|
||||
// Verbose output of this users calculations
|
||||
$log->logInfo($aData['id'] . "\t" .
|
||||
$aData['username'] . "\t" .
|
||||
$aData['valid'] . "\t" .
|
||||
$aData['invalid'] . "\t" .
|
||||
number_format($aData['percentage'], 8) . "\t" .
|
||||
number_format($aData['payout'], 8) . "\t" .
|
||||
number_format($aData['donation'], 8) . "\t" .
|
||||
number_format($aData['fee'], 8));
|
||||
$log->logInfo(
|
||||
sprintf($strLogMask, $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'],
|
||||
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8))
|
||||
);
|
||||
|
||||
// Update user share statistics
|
||||
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
|
||||
|
||||
@ -25,27 +25,28 @@ chdir(dirname(__FILE__));
|
||||
// Include all settings and classes
|
||||
require_once('shared.inc.php');
|
||||
|
||||
// Header
|
||||
$log->logInfo('Running statistical queries, errors may just mean no shares were available');
|
||||
$strLogMask = "| %-26.26s | %8.8s | %-6.6s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'Method', 'Runtime', 'Status'));
|
||||
|
||||
// Per user share statistics based on all shares submitted
|
||||
$start = microtime(true);
|
||||
if ( ! $statistics->getAllUserShares() )
|
||||
$log->logError('getAllUserShares update failed');
|
||||
$log->logInfo("getAllUserShares " . number_format(microtime(true) - $start, 2) . " seconds");
|
||||
$statistics->getAllUserShares() ? $status = 'OK' : $status = 'ERROR';
|
||||
$log->logInfo(sprintf($strLogMask, 'getAllUserShares', number_format(microtime(true) - $start, 3), $status));
|
||||
|
||||
// Get all user hashrate statistics for caching
|
||||
$start = microtime(true);
|
||||
if ( ! $statistics->getAllUserMiningStats() )
|
||||
$log->logError('getAllUserMiningStats update failed');
|
||||
$log->logInfo("getAllUserMiningStats " . number_format(microtime(true) - $start, 2) . " seconds");
|
||||
$statistics->getAllUserMiningStats() ? $status = 'OK' : $status = 'ERROR';
|
||||
$log->logInfo(sprintf($strLogMask, 'getAllUserMiningStats', number_format(microtime(true) - $start, 3), $status));
|
||||
|
||||
$start = microtime(true);
|
||||
if (!$statistics->getTopContributors('hashes'))
|
||||
$log->logError("getTopContributors hashes update failed");
|
||||
$log->logInfo("getTopContributors hashes " . number_format(microtime(true) - $start, 2) . " seconds");
|
||||
$statistics->getTopContributors('hashes') ? $status = 'OK' : $status = 'ERROR';
|
||||
$log->logInfo(sprintf($strLogMask, 'getTopContributors(hashes)', number_format(microtime(true) - $start, 3), $status));
|
||||
|
||||
$start = microtime(true);
|
||||
if (!$statistics->getCurrentHashrate())
|
||||
$log->logError("getCurrentHashrate update failed");
|
||||
$log->logInfo("getCurrentHashrate " . number_format(microtime(true) - $start, 2) . " seconds");
|
||||
$statistics->getCurrentHashrate() ? $status = 'OK' : $status = 'ERROR';
|
||||
$log->logInfo(sprintf($strLogMask, 'getTopContributors(shares)', number_format(microtime(true) - $start, 3), $status));
|
||||
|
||||
require_once('cron_end.inc.php');
|
||||
?>
|
||||
|
||||
@ -28,27 +28,44 @@ require_once('shared.inc.php');
|
||||
// Include additional file not set in autoloader
|
||||
require_once(CLASS_DIR . '/tools.class.php');
|
||||
|
||||
// Header and info
|
||||
$log->logInfo('Running periodic tasks to update database values for GUI access');
|
||||
$strLogMask = "| %-25.25s | %15.15s | %8.8s | %-6.6s | %-80.80s |";
|
||||
$log->logInfo(sprintf($strLogMask, 'Method', 'Value', 'Runtime', 'Status', 'Message'));
|
||||
|
||||
// Fetch latest coin price via API call
|
||||
$start = microtime(true);
|
||||
$message = 'Updated latest ' . $config['currency'] . ' price from ' . $config['price']['url'] . ' API';
|
||||
$status = 'OK';
|
||||
if ($price = $tools->getPrice()) {
|
||||
$log->logDebug("Price update: found $price as price");
|
||||
if (!$setting->setValue('price', $price))
|
||||
$log->logError("unable to update value in settings table");
|
||||
if (!$setting->setValue('price', $price)) {
|
||||
$message = 'Unable to store new price value: ' . $setting->getCronError();
|
||||
$status = 'ERROR';
|
||||
}
|
||||
} else {
|
||||
$log->logError("failed to fetch API data: " . $tools->getCronError());
|
||||
$message = 'Failed to fetch price from API: ' . $price->getCronError();
|
||||
$status = 'ERROR';
|
||||
}
|
||||
$log->logInfo(sprintf($strLogMask, 'Price Update', $price, number_format(microtime(true) - $start, 3), $status, $message));
|
||||
|
||||
|
||||
// Update Uptime Robot status in Settings table via API call
|
||||
$start = microtime(true);
|
||||
$message = 'Updated Uptime Robot status from API';
|
||||
$status = 'OK';
|
||||
if ($api_keys = $setting->getValue('monitoring_uptimerobot_api_keys')) {
|
||||
if (!strstr($api_keys, 'MONITOR_API_KEY|MONITOR_NAME')) {
|
||||
$monitoring->setTools($tools);
|
||||
if (!$monitoring->storeUptimeRobotStatus()) {
|
||||
$log->logError($monitoring->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0017', 1, false, false);
|
||||
$message = $monitoring->getCronError();
|
||||
$status = 'ERROR';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$log->logDebug('Skipped Uptime Robot API update, missing api keys');
|
||||
$status = 'SKIPED';
|
||||
$message = 'Missing API keys and monitor names';
|
||||
}
|
||||
$log->logInfo(sprintf($strLogMask, 'Uptime Robot', 'n/a', number_format(microtime(true) - $start, 3), $status, $message));
|
||||
|
||||
require_once('cron_end.inc.php');
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user