From a8b99484cc871fd49f174df7318768ab2a169188 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 5 Nov 2013 16:37:53 +0100 Subject: [PATCH 1/2] [FIX] Do not use Block Height to fetch prev block This should fix issues with orhpan blocks followed by real ones with the same height. Fixes #715, attempt four! --- cronjobs/pplns_payout.php | 14 ++++++++------ cronjobs/proportional_payout.php | 16 ++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 18b2d89a..a1d77d5e 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -53,13 +53,15 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $pplns_target = $config['pplns']['shares']['default']; } - if ($iLastBlockHeight = $setting->getValue('last_accounted_block_height')) { - $aLastAccountedBlock = $block->getBlock($iLastBlockHeight); + if ($iLastBlockId = $setting->getValue('last_accounted_block_id')) { + $aLastAccountedBlock = $block->getBlockById($iLastBlockId); } else { - $iLastBlockHeight = 0; + // A fake block to ensure payouts get started on first round + $iLastBlockId = 0; + $aLastAccountedBlock = array('height' => 0, 'confirmations' => 1); } - // Double payout detection - if ( @$aLastAccountedBlock['confirmations'] != -1 || ( !$aBlock['accounted'] && $aBlock['height'] > $iLastBlockHeight )) { + // Ensure we are not paying out twice, ignore if the previous paid block is orphaned (-1 confirmations) and payout anyway + if ((!$aBlock['accounted'] && $aBlock['height'] > $aLastAccountedBlock['height']) || (@$aLastAccountedBlock['confirmations'] == -1)) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; if (!is_numeric($iCurrentUpstreamId)) { @@ -217,7 +219,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { } // Store this blocks height as last accounted for - $setting->setValue('last_accounted_block_height', $aBlock['height']); + $setting->setValue('last_accounted_block_id', $aBlock['id']); // Move counted shares to archive before this blockhash upstream share if (!$share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId)) diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 807fe073..c9acb32a 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -45,13 +45,16 @@ $count = 0; // Table header for account shares $log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee"); foreach ($aAllBlocks as $iIndex => $aBlock) { - if ($iLastBlockHeight = $setting->getValue('last_accounted_block_height')) { - $aLastAccountedBlock = $block->getBlock($iLastBlockHeight); + if ($iLastBlockId = $setting->getValue('last_accounted_block_id')) { + $aLastAccountedBlock = $block->getBlockById($iLastBlockId); } else { - $iLastBlockHeight = 0; + // A fake block to ensure payouts get started on first round + $iLastBlockId = 0; + $aLastAccountedBlock = array('height' => 0, 'confirmations' => 1); } - // Double payout detection - if ( ( !$aBlock['accounted'] && $aBlock['height'] > $iLastBlockHeight ) || @$aLastAccountedBlock['confirmations'] == -1) { + + // Ensure we are not paying out twice, ignore if the previous paid block is orphaned (-1 confirmations) and payout anyway + if ((!$aBlock['accounted'] && $aBlock['height'] > $aLastAccountedBlock['height']) || (@$aLastAccountedBlock['confirmations'] == -1)) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; $aAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']); @@ -107,7 +110,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { } // Add block as accounted for into settings table - $setting->setValue('last_accounted_block_height', $aBlock['height']); + $setting->setValue('last_accounted_block_id', $aBlock['id']); // Move counted shares to archive before this blockhash upstream share if (!$share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId)) @@ -145,6 +148,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + exit; } require_once('cron_end.inc.php'); From 3edd7671a45f666882a9aab543c73bd61a4aa69c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 10 Nov 2013 17:15:03 +0100 Subject: [PATCH 2/2] [FIX] Removed debug exit --- cronjobs/proportional_payout.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index c9acb32a..65f8dd98 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -148,7 +148,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } - exit; } require_once('cron_end.inc.php');