diff --git a/cronjobs/payouts.php b/cronjobs/payouts.php index 4b778c99..88018fdf 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -29,142 +29,137 @@ if ($setting->getValue('disable_payouts') == 1) { $log->logInfo(" payouts disabled via admin panel"); $monitoring->endCronjob($cron_name, 'E0009', 0, true, false); } - +$log->logInfo("Starting Payout..."); if ($bitcoin->can_connect() !== true) { $log->logFatal(" unable to connect to RPC server, exiting"); $monitoring->endCronjob($cron_name, 'E0006', 1, true); } - if ($setting->getValue('disable_manual_payouts') != 1) { - // Fetch outstanding payout requests - $aPayouts = $oPayout->getUnprocessedPayouts(); - if (count($aPayouts > 0)) $log->logDebug(" found " . count($aPayouts) . " queued manual payout requests"); - - if (count($aPayouts) > 0) { - $log->logInfo("\tAccount ID\tUsername\tBalance\t\tCoin Address"); - foreach ($aPayouts as $aData) { - $aBalance = $transaction->getBalance($aData['account_id']); - $dBalance = $aBalance['confirmed']; - $aData['coin_address'] = $user->getCoinAddress($aData['account_id']); - $aData['username'] = $user->getUserName($aData['account_id']); - if ($dBalance > $config['txfee_manual']) { - // To ensure we don't run this transaction again, lets mark it completed - if (!$oPayout->setProcessed($aData['id'])) { - $log->logFatal('unable to mark transactions ' . $aData['id'] . ' as processed.'); - $monitoring->endCronjob($cron_name, 'E0010', 1, true); - } - - $log->logInfo("\t" . $aData['account_id'] . "\t\t" . $aData['username'] . "\t" . $dBalance . "\t\t" . $aData['coin_address']); - try { - $aStatus = $bitcoin->validateaddress($aData['coin_address']); - if (!$aStatus['isvalid']) { - $log->logError('Failed to verify this users coin address, skipping payout'); - continue; - } - } catch (Exception $e) { - $log->logError('Failed to verify this users coin address, skipping payout'); - continue; - } - try { - $txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']); - } catch (Exception $e) { - $log->logFatal('Failed sending coins to user, aborting due to a coind exception in RPC call. Please check your RPC transactions.'); - $monitoring->endCronjob($cron_name, 'E0078', 1, true); - } - - if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee_manual'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee_manual'], 'TXFee', NULL, $aData['coin_address'])) { - // Mark all older transactions as archived - if (!$transaction->setArchived($aData['account_id'], $transaction->insert_id)) - $log->logError('Failed to mark transactions for #' . $aData['account_id'] . ' prior to #' . $transaction->insert_id . ' as archived'); - // Notify user via mail - $aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id'])); - $aMailData['subject'] = 'Manual Payout Completed'; - $aMailData['amount'] = $dBalance - $config['txfee_manual']; - $aMailData['payout_id'] = $aData['id']; - if (!$notification->sendNotification($aData['account_id'], 'manual_payout', $aMailData)) - $log->logError('Failed to send notification email to users address ' . $aMailData['email'] . ' : ' . $notification->getCronError); - // Recheck the users balance to make sure it is now 0 - $aBalance = $transaction->getBalance($aData['account_id']); - if ($aBalance['confirmed'] > 0) { - $log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!'); - $monitoring->endCronjob($cron_name, 'E0065', 1, true); - } - } else { - $log->logFatal('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id'])); - $monitoring->endCronjob($cron_name, 'E0064', 1, true); - } - } + // Fetch outstanding payout requests + if ($aPayouts = $oPayout->getUnprocessedPayouts()) { + if (count($aPayouts) > 0) { + $log->logInfo("\tStarting Manual Payments..."); + $log->logInfo("\tAccount ID\tUsername\tBalance\t\tCoin Address"); + foreach ($aPayouts as $aData) { + $aBalance = $transaction->getBalance($aData['account_id']); + $dBalance = $aBalance['confirmed']; + $aData['coin_address'] = $user->getCoinAddress($aData['account_id']); + $aData['username'] = $user->getUserName($aData['account_id']); + if ($dBalance > $config['txfee_manual']) { + // To ensure we don't run this transaction again, lets mark it completed + if (!$oPayout->setProcessed($aData['id'])) { + $log->logFatal('unable to mark transactions ' . $aData['id'] . ' as processed. ERROR: ' . $oPayout->getCronError()); + $monitoring->endCronjob($cron_name, 'E0010', 1, true); + } + $log->logInfo("\t" . $aData['account_id'] . "\t\t" . $aData['username'] . "\t" . $dBalance . "\t\t" . $aData['coin_address']); + try { + $txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']); + } catch (Exception $e) { + $log->logError('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage()); + continue; + } + if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee_manual'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee_manual'], 'TXFee', NULL, $aData['coin_address'])) { + // Mark all older transactions as archived + if (!$transaction->setArchived($aData['account_id'], $transaction->insert_id)) + $log->logError('Failed to mark transactions for #' . $aData['account_id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError()); + // Notify user via mail + $aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id'])); + $aMailData['subject'] = 'Manual Payout Completed'; + $aMailData['amount'] = $dBalance - $config['txfee_manual']; + $aMailData['payout_id'] = $aData['id']; + if (!$notification->sendNotification($aData['account_id'], 'manual_payout', $aMailData)) + $log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . 'ERROR: ' . $notification->getCronError()); + // Recheck the users balance to make sure it is now 0 + if (!$aBalance = $transaction->getBalance($aData['account_id'])) { + $log->logFatal('Failed to fetch balance for account ' . $aData['account_id'] . '. ERROR: ' . $transaction->getCronError()); + $monitoring->endCronjob($cron_name, 'E0065', 1, true); + } + if ($aBalance['confirmed'] > 0) { + $log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!'); + $monitoring->endCronjob($cron_name, 'E0065', 1, true); + } + } + else { + $log->logFatal('Failed to add new Debit_MP transaction in database for user ' . $user->getUserName($aData['account_id']) . ' ERROR: ' . $transaction->getCronError()); + $monitoring->endCronjob($cron_name, 'E0064', 1, true); + } + } + } + } } - } -} else { - $log->logDebug("Manual payouts are disabled via admin panel"); + else if (empty($aPayouts)) { + $log->logInfo("\tStopping Payments. No Payout Requests Found."); + } +else { + $log->logFatal("\tFailed Processing Manual Payment Queue...Aborting..."); + $monitoring->endCronjob($cron_name, 'E0050', 1, true); +} +if (count($aPayouts > 0)) $log->logDebug(" found " . count($aPayouts) . " queued manual payout requests"); +} +else { + $log->logDebug("Manual payouts are disabled via admin panel"); } - if ($setting->getValue('disable_auto_payouts') != 1) { - // Fetch all users balances - $users = $transaction->getAPQueue(); - if (count($users) > 0) $log->logDebug(" found " . count($users) . " queued payout(s)"); - - // Go through users and run transactions - if (! empty($users)) { - $log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress"); - - foreach ($users as $aUserData) { - $dBalance = $aUserData['confirmed']; - $log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']); - - // Only run if balance meets threshold and can pay the potential transaction fee - if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee_auto']) { - // Validate address against RPC - try { - $aStatus = $bitcoin->validateaddress($aUserData['coin_address']); - if (!$aStatus['isvalid']) { - $log->logError('Failed to verify this users coin address, skipping payout'); - continue; - } - } catch (Exception $e) { - $log->logError('Failed to verify this users coin address, skipping payout'); - continue; - } - - // Send balance, fees are reduced later by RPC Server - try { - $txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']); - } catch (Exception $e) { - $log->logFatal('Failed sending coins to user, aborting due to a coind exception in RPC call. Please check your RPC transactions.'); - $monitoring->endCronjob($cron_name, 'E0078', 1, true); - } - - // Create transaction record - if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee_auto'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee_auto'], 'TXFee', NULL, $aUserData['coin_address'])) { - // Mark all older transactions as archived - if (!$transaction->setArchived($aUserData['id'], $transaction->insert_id)) - $log->logError('Failed to mark transactions for user #' . $aUserData['id'] . ' prior to #' . $transaction->insert_id . ' as archived'); - // Notify user via mail - $aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id'])); - $aMailData['subject'] = 'Auto Payout Completed'; - $aMailData['amount'] = $dBalance - $config['txfee_auto']; - if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData)) - $log->logError('Failed to send notification email to users address: ' . $aMailData['email']); - // Recheck the users balance to make sure it is now 0 - $aBalance = $transaction->getBalance($aUserData['id']); - if ($aBalance['confirmed'] > 0) { - $log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!'); - $monitoring->endCronjob($cron_name, 'E0065', 1, true); - } - } else { - $log->logFatal('Failed to add new Debit_AP transaction in database for user ' . $user->getUserName($aUserData['id'])); - $monitoring->endCronjob($cron_name, 'E0064', 1, true); - } - } + // Fetch all users balances + if ($users = $transaction->getAPQueue()) { + if (!empty($users)) { + if (count($users) > 0) $log->logDebug(" found " . count($users) . " queued payout(s)"); + // Go through users and run transactions + $log->logInfo("Starting Payments..."); + $log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress"); + foreach ($users as $aUserData) { + $dBalance = $aUserData['confirmed']; + $log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']); + // Only run if balance meets threshold and can pay the potential transaction fee + if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee_auto']) { + // Send balance, fees are reduced later by RPC Server + try { + $txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']); + } + catch (Exception $e) { + $log->logError('Skipping payment. Failed to send balance to coin address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage()); + continue; + } + // Create transaction record + if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee_auto'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee_auto'], 'TXFee', NULL, $aUserData['coin_address'])) { + // Mark all older transactions as archived + if (!$transaction->setArchived($aUserData['id'], $transaction->insert_id)) + $log->logError('Failed to mark transactions for user #' . $aUserData['id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError()); + // Notify user via mail + $aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id'])); + $aMailData['subject'] = 'Auto Payout Completed'; + $aMailData['amount'] = $dBalance - $config['txfee_auto']; + if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData)) + $log->logError('Failed to send notification email to users address: ' . $aMailData['email'] . ' ERROR: ' . $notification->getCronError()); + // Recheck the users balance to make sure it is now 0 + $aBalance = $transaction->getBalance($aUserData['id']); + if ($aBalance['confirmed'] > 0) { + $log->logFatal('User has a remaining balance of ' . $aBalance['confirmed'] . ' after a successful payout!'); + $monitoring->endCronjob($cron_name, 'E0065', 1, true); + } + } + else { + $log->logFatal('Failed to add new Debit_AP transaction in database for user ' . $user->getUserName($aUserData['id']) . ' ERROR: ' . $transaction->getCronError()); + $monitoring->endCronjob($cron_name, 'E0064', 1, true); + } + } + } + } + } + else if(empty($users)) { + $log->logInfo("\tSkipping payments. No Auto Payments Eligible."); + $log->logDebug("Users have not configured their AP > 0"); + } + else{ + $log->logFatal("\tFailed Processing Auto Payment Payment Queue. ERROR: " . $transaction->getCronError()); + $monitoring->endCronjob($cron_name, 'E0050', 1, true); } - } else { - $log->logDebug(" no user has configured their AP > 0"); - } -} else { - $log->logDebug("Auto payouts disabled via admin panel"); } +else { + $log->logDebug("Auto payouts disabled via admin panel"); +} +$log->logInfo("Completed Payouts"); // Cron cleanup and monitoring require_once('cron_end.inc.php'); ?> diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 0368e8a7..286e747f 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -106,7 +106,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { // Grab only the most recent shares from Archive that fill the missing shares $log->logInfo('Fetching ' . ($pplns_target - $iRoundShares) . ' additional shares from archive'); if (!$aArchiveShares = $share->getArchiveShares($pplns_target - $iRoundShares)) { - $log->logError('Failed to fetch shares from archive, setting target to round total'); + $log->logError('Failed to fetch shares from archive, setting target to round total. Error: ' . $share->getCronError()); $pplns_target = $iRoundShares; } else { // Add archived shares to users current shares, if we have any in archive @@ -236,10 +236,10 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { // Move counted shares to archive before this blockhash upstream share if (!$share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId)) - $log->logError('Failed to copy shares to archive table for block ' . $aBlock['id'] . ': ' . $share->getCronError() . ': ' . $share->getCronError()); + $log->logError('Failed to copy shares to archive table: ' . $iPreviousShareId . ' to ' . $iCurrentUpstreamId . ' aborting! Error: ' . $share->getCronError()); // Delete all accounted shares if (!$share->deleteAccountedShares($iCurrentUpstreamId, $iPreviousShareId)) { - $log->logFatal("Failed to delete accounted shares from $iPreviousShareId to $iCurrentUpstreamId for block " . $aBlock['id'] . ", aborting! Error: " . $share->getCronError()); + $log->logFatal("Failed to delete accounted shares from " . $iPreviousShareId . " to " . $iCurrentUpstreamId . " aborting! Error: " . $share->getCronError()); $monitoring->endCronjob($cron_name, 'E0016', 1, true); } // Mark this block as accounted for diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 1c79e411..96f84c01 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -28,9 +28,10 @@ require_once('shared.inc.php'); // Check if we are set as the payout system if ($config['payout_system'] != 'pps') { - $log->logInfo("Please activate this cron in configuration via payout_system = pps\n"); + $log->logInfo("\tPlease activate this cron in configuration via payout_system = pps\n"); exit(0); } +$log->logInfo("Starting PPS Payout..."); // Fetch all transactions since our last block if ( $bitcoin->can_connect() === true ){ @@ -50,33 +51,50 @@ if ( $bitcoin->can_connect() === true ){ // We don't use the classes implementation just in case people start mucking around with it if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > 0) { $pps_reward = round($block->getAvgBlockReward($config['pps']['blockavg']['blockcount'])); - $log->logInfo("PPS reward using block average, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); + $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); } } 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 -$iPreviousShareId = $setting->getValue('pps_last_share_id'); -$iLastShareId = $share->getLastInsertedShareId(); + +if (!$iPreviousShareId = $setting->getValue('pps_last_share_id')) { + $log->logError("Failed to fetch Previous Share ID. ERROR: " . $setting->getCronError()); +} +$log->logInfo("\tPPS Last Share ID: " . $iPreviousShareId); + +if (!$iLastShareId = $share->getLastInsertedShareId()) { + $log->logError("Failed to fetch Last Inserted PPS Share ID. ERROR: " . $share->getCronError()); +} +$log->logInfo("\tPPS Last Processed Share ID: " . $iLastShareId); // Check for all new shares, we start one higher as our last accounted share to avoid duplicates -$aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId); +$log->logInfo("\tQuery getSharesForAccounts... starting..."); +if (!$aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId)) { + $log->logError("Failed to fetch Account Shares. ERROR: " . $share->getCronError()); +} +$log->logInfo("\tQuery Completed..."); if (!empty($aAccountShares)) { // Info for this payout - $log->logInfo("PPS reward type: " . $config['pps']['reward']['type'] . ", amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty . "\tPPS value: " . $pps_value); - $log->logInfo("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee"); + $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"); } foreach ($aAccountShares as $aData) { @@ -123,48 +141,69 @@ foreach ($aAccountShares as $aData) { } // Store our last inserted ID for the next run -$setting->setValue('pps_last_share_id', $iLastShareId); +$log->logInfo("\tFetching Last Share ID..."); +if (!$setting->setValue('pps_last_share_id', $iLastShareId)) { + $log->logError("Failed to fetch Last Share ID. ERROR: " . $setting->getCronError()); +} // Fetch all unaccounted blocks -$aAllBlocks = $block->getAllUnaccounted('ASC'); -if (empty($aAllBlocks)) { - $log->logDebug("No new unaccounted blocks found"); - // No monitoring event here, not fatal for PPS +$log->logInfo("\tFetching unaccounted blocks."); +if ($aAllBlocks = $block->getAllUnaccounted('ASC')) { + // Go through blocks and archive/delete shares that have been accounted for + foreach ($aAllBlocks as $iIndex => $aBlock) { + // If we are running through more than one block, check for previous share ID + $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); + } + // Per account statistics + $log->logInfo("\tRefresh user statistics..."); + if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) { + $log->logError("Failed to Account Shares. ERROR: " . $share->getCronError()); + } + foreach ($aAccountShares as $key => $aData) { + if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) + $log->logError("Failed to update statistics for Block " . $aBlock['id'] . "for" . $aData['username'] . ' ERROR: ' . $statistics->getCronError()); + } + $log->logInfo("\tUser Statistics updated."); + + // Move shares to archive + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Move shares to archive..."); + if ($aBlock['share_id'] < $iLastShareId) { + if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare)) + $log->logError("Failed to copy shares to from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ' Error: ' . $share->getCronError()); + } + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Shares moved to archive..."); + + // Delete shares + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Deleting accounted shares..."); + if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) { + $log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError()); + $monitoring->endCronjob($cron_name, 'E0016', 1, true); + } + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Deleted accounted shares."); + + // Mark this block as accounted for + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Marking Block as accounted..."); + if (!$block->setAccounted($aBlock['id'])) { + $log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError()); + $monitoring->endCronjob($cron_name, 'E0014', 1, true); + } + $log->logInfo("\tBlock: " . $aBlock['id'] . "\t Block paid and accounted for."); + } } - -// Go through blocks and archive/delete shares that have been accounted for -foreach ($aAllBlocks as $iIndex => $aBlock) { - // If we are running through more than one block, check 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); - } - // Per account statistics - $aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id']); - foreach ($aAccountShares as $key => $aData) { - if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) - $log->logError("Failed to update stats for this block on : " . $aData['username'] . ': ' . $statistics->getCronError()); - } - // Move shares to archive - if ($aBlock['share_id'] < $iLastShareId) { - if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare)) - $log->logError("Failed to copy shares to archive: " . $share->getCronError() . ': ' . $share->getCronError()); - } - // Delete shares - if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) { - $log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError()); - $monitoring->endCronjob($cron_name, 'E0016', 1, true); - } - // Mark this block as accounted for - if (!$block->setAccounted($aBlock['id'])) { - $log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError()); - $monitoring->endCronjob($cron_name, 'E0014', 1, true); - } +else if (empty($aAllBlocks)) { + $log->logInfo("\tNo new blocks."); + // No monitoring event here, not fatal for PPS +} else { + $log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError()); } +$log->logInfo("Completed PPS Payout"); require_once('cron_end.inc.php'); ?>