[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!
This commit is contained in:
Sebastian Grewe 2013-11-05 16:37:53 +01:00
parent dd1ef86b81
commit a8b99484cc
2 changed files with 18 additions and 12 deletions

View File

@ -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))

View File

@ -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');