diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index f5d6f24c..d95af481 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -51,7 +51,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $pplns_target = $config['pplns']['shares']['default']; } - if (!$aBlock['accounted']) { + if (!$aBlock['accounted'] && $aBlock['height'] > $setting->getValue('last_accounted_block_height')) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; if (!is_numeric($iCurrentUpstreamId)) { @@ -183,6 +183,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $log->logFatal("Failed to delete accounted shares from $iPreviousShareId to $iCurrentUpstreamId, aborting!"); exit(1); } + // Store this blocks height as last accounted for + $setting->setValue('last_accounted_block_height', $aBlock['height']); // Mark this block as accounted for if (!$block->setAccounted($aBlock['id'])) { $log->logFatal("Failed to mark block as accounted! Aborting!"); @@ -191,6 +193,22 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + } else { + $aMailData = array( + 'email' => $setting->getValue('website_email'), + 'subject' => 'Payout processing aborted', + 'Error' => 'Potential double payout detected. All payouts halted until fixed!', + 'BlockID' => $aBlock['id'], + 'Block Height' => $aBlock['height'], + 'Block Share ID' => $aBlock['share_id'] + ); + if (!$mail->sendMail('notifications/error', $aMailData)) + $log->logError(" Failed sending notifications: " . $notification->getError() . "\n"); + $log->logFatal('Potential double payout detected. Aborted.'); + $monitoring->setStatus($cron_name . "_active", "yesno", 0); + $monitoring->setStatus($cron_name . "_message", "message", "Block height for block too low! Potential double payout detected."); + $monitoring->setStatus($cron_name . "_status", "okerror", 1); + exit(1); } } diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index e6e76113..31a24beb 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -45,7 +45,7 @@ $count = 0; // Table header for account shares $log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee"); foreach ($aAllBlocks as $iIndex => $aBlock) { - if (!$aBlock['accounted']) { + if (!$aBlock['accounted'] && $aBlock['height'] > $setting->getValue('last_accounted_block_height')) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; $aAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']); @@ -82,7 +82,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { number_format($aData['percentage'], 8) . "\t" . number_format($aData['payout'], 8) . "\t" . number_format($aData['donation'], 8) . "\t" . - number_format($aData['fee']), 8); + number_format($aData['fee'], 8)); // Update user share statistics if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) @@ -111,6 +111,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + // Add block as accounted for into settings table + $setting->setValue('last_accounted_block_height', $aBlock['height']); // Mark this block as accounted for if (!$block->setAccounted($aBlock['id'])) { $log->logFatal('Failed to mark block as accounted! Aborted.'); @@ -119,7 +121,24 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + } else { + $log->logFatal('Possible double payout detected. Aborted.'); + $aMailData = array( + 'email' => $setting->getValue('website_email'), + 'subject' => 'Payout Failure: Double Payout', + 'Error' => 'Possible double payout detected', + 'BlockID' => $aBlock['id'], + 'Block Height' => $aBlock['height'], + 'Block Share ID' => $aBlock['share_id'] + ); + if (!$mail->sendMail('notifications/error', $aMailData)) + $log->logError(" Failed sending notifications: " . $notification->getError() . "\n"); + $monitoring->setStatus($cron_name . "_active", "yesno", 0); + $monitoring->setStatus($cron_name . "_message", "message", 'Possible double payout detected. Aborted.'); + $monitoring->setStatus($cron_name . "_status", "okerror", 1); + exit(1); } + exit; } require_once('cron_end.inc.php'); diff --git a/public/templates/mail/notifications/error.tpl b/public/templates/mail/notifications/error.tpl new file mode 100644 index 00000000..9aab79bf --- /dev/null +++ b/public/templates/mail/notifications/error.tpl @@ -0,0 +1,10 @@ + +
+This should never happen. Please review the error output below.
+ +{foreach from=$DATA key=text item=message} + {if $text != 'email' && $text != 'subject'} +{$text}: {$message}
+ {/if} +{/foreach}