diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 9794546d..73ce4a17 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -50,13 +50,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)) { @@ -205,7 +207,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 b2b85efa..49ab7a94 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -42,13 +42,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']); @@ -101,7 +104,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))