Merge pull request #718 from TheSerapher/issue-715
[IMPROVED] Detect potential dual payout situations
This commit is contained in:
commit
c5b7de5055
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
10
public/templates/mail/notifications/error.tpl
Normal file
10
public/templates/mail/notifications/error.tpl
Normal file
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>An error occured!</h1>
|
||||
<p>This should never happen. Please review the error output below.</p>
|
||||
|
||||
{foreach from=$DATA key=text item=message}
|
||||
{if $text != 'email' && $text != 'subject'}
|
||||
<p>{$text}: {$message}</p>
|
||||
{/if}
|
||||
{/foreach}
|
||||
Loading…
Reference in New Issue
Block a user