From 93b7fb6de296dffafb2871abbaa589d2d01560f3 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 15:43:13 +0100 Subject: [PATCH 1/8] [IMPROVED] Findblocks log formatting --- cronjobs/findblock.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 1ac69535..0c8dfeca 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -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)) From aab216e1171c6e0087115ed34686558e15e49af2 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 15:57:53 +0100 Subject: [PATCH 2/8] [IMPROVED] Blockupdate log format --- cronjobs/blockupdate.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cronjobs/blockupdate.php b/cronjobs/blockupdate.php index bc5d4913..5fbd42de 100755 --- a/cronjobs/blockupdate.php +++ b/cronjobs/blockupdate.php @@ -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')); + $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')); + $header = true; + } + $log->logInfo(sprintf($strLogMask, $aBlock['id'], $aBlock['height'], $aBlock['blockhash'], $aBlock['confirmations'], $aBlockInfo['confirmations'], $status)); } } From 950e607230d69cbd124fbc955cd9b086795b3de6 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 17:10:45 +0100 Subject: [PATCH 3/8] [IMPROVED] Proportional payout log format --- cronjobs/proportional_payout.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 15ea13dc..4fa4bc5d 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -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'])) From ee805b65cee30b34c9016efbc49de8b374a1072c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 17:10:58 +0100 Subject: [PATCH 4/8] [IMPROVED] PPLNS payout log format --- cronjobs/pplns_payout.php | 47 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 7ff88379..08656ed7 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -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'])) From 1d5acb48b2a5ad41673f4d17eb53e787d2fd139b Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 18:16:57 +0100 Subject: [PATCH 5/8] [FIX] Wrong argument count --- cronjobs/blockupdate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cronjobs/blockupdate.php b/cronjobs/blockupdate.php index 5fbd42de..f7938dee 100755 --- a/cronjobs/blockupdate.php +++ b/cronjobs/blockupdate.php @@ -48,7 +48,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $log->logError(" Block became orphaned but unable to update database entries"); } if (!$header) { - $log->logInfo(sprintf($strLogMask, 'ID', 'Height', 'Blockhash', 'Old', 'New')); + $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)); @@ -64,7 +64,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $status = 'UPDATED'; } if (!$header) { - $log->logInfo(sprintf($strLogMask, 'ID', 'Height', 'Blockhash', 'Old', 'New')); + $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)); From e46036325c86ba817b7a0d7a5ab3714f8aa9fe9e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 18:17:12 +0100 Subject: [PATCH 6/8] [IMPROVED] PPS payout log format --- cronjobs/pps_payout.php | 57 +++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 987b5f17..4b5a0e9e 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -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..."); From 35910ef0972f80f1203e98839aa841d81e4d203e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 18:32:39 +0100 Subject: [PATCH 7/8] [IMPROVED] Statistics log format --- cronjobs/statistics.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cronjobs/statistics.php b/cronjobs/statistics.php index 0149afc0..6530fab7 100755 --- a/cronjobs/statistics.php +++ b/cronjobs/statistics.php @@ -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'); ?> From e36060cd2e2bec79669d280fa4f8b53edd443d1d Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 18:44:00 +0100 Subject: [PATCH 8/8] [IMPROVED] Tickerupdate log format --- cronjobs/tickerupdate.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/cronjobs/tickerupdate.php b/cronjobs/tickerupdate.php index 59916d63..e1198889 100755 --- a/cronjobs/tickerupdate.php +++ b/cronjobs/tickerupdate.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'); ?>