From 418728071ba74c5f28e6e92a2b3899913adbf06d Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 6 Jan 2014 12:21:32 +0100 Subject: [PATCH] [UPDATE] Allow deletion of accounts Updated backend and theme to be able to deal with deleted accounts * Backends will skip any users that have no account_id associated with their shares * Updated round stats theme to show users as unknown if none can be found This will not fully address the issue of account deletion but at least wont break the system anymore. --- cronjobs/findblock.php | 4 ++-- cronjobs/pplns_payout.php | 6 ++++++ cronjobs/pps_payout.php | 6 ++++++ cronjobs/proportional_payout.php | 11 ++++++++--- .../templates/mpos/statistics/round/block_stats.tpl | 2 +- .../mpos/statistics/round/pplns_block_stats.tpl | 2 +- .../mpos/statistics/round/pplns_block_stats_small.tpl | 2 +- .../mpos/statistics/round/pplns_round_shares.tpl | 2 +- .../mpos/statistics/round/pplns_transactions.tpl | 2 +- .../statistics/round/pplns_transactions_small.tpl | 2 +- .../templates/mpos/statistics/round/round_shares.tpl | 2 +- .../mpos/statistics/round/round_transactions.tpl | 2 +- 12 files changed, 30 insertions(+), 13 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index daa91030..aaeeaf69 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -137,13 +137,13 @@ if (empty($aAllBlocks)) { // Store new information if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId)) $log->logError('Failed to update share ID in database for block ' . $aBlock['height'] . ': ' . $block->getCronError()); - if (!$block->setFinder($aBlock['id'], $iAccountId)) + if (!empty($iAccountId) && !$block->setFinder($aBlock['id'], $iAccountId)) $log->logError('Failed to update finder account ID in database for block ' . $aBlock['height'] . ': ' . $block->getCronError()); if (!$block->setFindingWorker($aBlock['id'], $iWorker)) $log->logError('Failed to update worker ID in database for block ' . $aBlock['height'] . ': ' . $block->getCronError()); if (!$block->setShares($aBlock['id'], $iRoundShares)) $log->logError('Failed to update share count in database for block ' . $aBlock['height'] . ': ' . $block->getCronError()); - if ($config['block_bonus'] > 0 && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) { + if ($config['block_bonus'] > 0 && !empty($iAccountId) && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) { $log->logError('Failed to create Bonus transaction in database for user ' . $user->getUserName($iAccountId) . ' for block ' . $aBlock['height'] . ': ' . $transaction->getCronError()); } diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 8d60ae2e..87a02ac5 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -158,6 +158,12 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { // Loop through all accounts that have found shares for this round foreach ($aAccountShares as $key => $aData) { + // Skip entries that have no account ID, user deleted? + if (empty($aData['id'])) { + $log->logInfo('User ' . $aData['username'] . ' does not have an associated account, skipping'); + continue; + } + // Payout based on PPLNS target shares, proportional payout for all users $aData['percentage'] = round(( 100 / $iRoundShares) * $aData['valid'], 8); $aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8); diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 434d3074..1c79e411 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -80,6 +80,12 @@ if (!empty($aAccountShares)) { } foreach ($aAccountShares as $aData) { + // Skip entries that have no account ID, user deleted? + if (empty($aData['id'])) { + $log->logInfo('User ' . $aData['username'] . ' does not have an associated account, skipping'); + continue; + } + // MPOS uses a base difficulty setting to avoid showing weightened shares // Since we need weightened shares here, we go back to the proper value for payouts $aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 8); diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 59819b29..0fbc80cd 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -72,12 +72,17 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { // Loop through all accounts that have found shares for this round foreach ($aAccountShares as $key => $aData) { - // Payout based on shares, PPS system - $aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8); - $aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8); + // Skip entries that have no account ID, user deleted? + if (empty($aData['id'])) { + $log->logInfo('User ' . $aData['username'] . ' does not have an associated account, skipping'); + continue; + } + // Defaults $aData['fee' ] = 0; $aData['donation'] = 0; + $aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8); + $aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8); if ($config['fees'] > 0 && $aData['no_fees'] == 0) $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); diff --git a/public/templates/mpos/statistics/round/block_stats.tpl b/public/templates/mpos/statistics/round/block_stats.tpl index aafcb856..b0f84475 100644 --- a/public/templates/mpos/statistics/round/block_stats.tpl +++ b/public/templates/mpos/statistics/round/block_stats.tpl @@ -37,7 +37,7 @@ Shares {$BLOCKDETAILS.shares|number_format:"0"|default:"0"} Finder - {$BLOCKDETAILS.finder|default:"0"} + {$BLOCKDETAILS.finder|default:"unknown"} diff --git a/public/templates/mpos/statistics/round/pplns_block_stats.tpl b/public/templates/mpos/statistics/round/pplns_block_stats.tpl index 5e99fcc1..af7577bb 100644 --- a/public/templates/mpos/statistics/round/pplns_block_stats.tpl +++ b/public/templates/mpos/statistics/round/pplns_block_stats.tpl @@ -76,7 +76,7 @@ Finder - {$BLOCKDETAILS.finder|default:"0"} + {$BLOCKDETAILS.finder|default:"unknown"} Round Variance {if $PPLNSSHARES > 0}{math assign="percentage1" equation=(($BLOCKDETAILS.shares / $PPLNSSHARES) * 100)}{/if}{$percentage1|number_format:"2"} % diff --git a/public/templates/mpos/statistics/round/pplns_block_stats_small.tpl b/public/templates/mpos/statistics/round/pplns_block_stats_small.tpl index 06a70bba..f7049e31 100644 --- a/public/templates/mpos/statistics/round/pplns_block_stats_small.tpl +++ b/public/templates/mpos/statistics/round/pplns_block_stats_small.tpl @@ -63,7 +63,7 @@ Shares {$BLOCKDETAILS.shares|number_format:"0"|default:"0"} Finder - {$BLOCKDETAILS.finder|default:"0"} + {$BLOCKDETAILS.finder|default:"unknown"} Seconds This Round {$BLOCKDETAILS.round_time|number_format:"0"|default:"0"} Round Variance diff --git a/public/templates/mpos/statistics/round/pplns_round_shares.tpl b/public/templates/mpos/statistics/round/pplns_round_shares.tpl index 68436b42..9272a07a 100644 --- a/public/templates/mpos/statistics/round/pplns_round_shares.tpl +++ b/public/templates/mpos/statistics/round/pplns_round_shares.tpl @@ -15,7 +15,7 @@ {section contrib $PPLNSROUNDSHARES} {$rank++} - {if $PPLNSROUNDSHARES[contrib].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$PPLNSROUNDSHARES[contrib].username|escape}{/if} + {if $PPLNSROUNDSHARES[contrib].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$PPLNSROUNDSHARES[contrib].username|default:"unknown"|escape}{/if} {$PPLNSROUNDSHARES[contrib].pplns_valid|number_format} {$PPLNSROUNDSHARES[contrib].pplns_invalid|number_format} {if $PPLNSROUNDSHARES[contrib].pplns_invalid > 0 && $PPLNSROUNDSHARES[contrib].pplns_valid > 0}{($PPLNSROUNDSHARES[contrib].pplns_invalid / $PPLNSROUNDSHARES[contrib].pplns_valid * 100)|number_format:"2"|default:"0"}{else}0.00{/if} diff --git a/public/templates/mpos/statistics/round/pplns_transactions.tpl b/public/templates/mpos/statistics/round/pplns_transactions.tpl index 3487bc15..ef4628fa 100644 --- a/public/templates/mpos/statistics/round/pplns_transactions.tpl +++ b/public/templates/mpos/statistics/round/pplns_transactions.tpl @@ -16,7 +16,7 @@ {assign var=percentage1 value=0} {section txs $ROUNDTRANSACTIONS} - {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|escape}{/if} + {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|default:"unknown"|escape}{/if} {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format} {if $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid > 0 }{(( 100 / $BLOCKDETAILS.shares) * $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid)|number_format:"2"}{else}0.00{/if} {$PPLNSROUNDSHARES[txs].pplns_valid|number_format|default:"0"} diff --git a/public/templates/mpos/statistics/round/pplns_transactions_small.tpl b/public/templates/mpos/statistics/round/pplns_transactions_small.tpl index b50c416d..74e45bf5 100644 --- a/public/templates/mpos/statistics/round/pplns_transactions_small.tpl +++ b/public/templates/mpos/statistics/round/pplns_transactions_small.tpl @@ -19,7 +19,7 @@ {section txs $ROUNDTRANSACTIONS} - {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|escape}{/if} + {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|default:"unknown"|escape}{/if} {$SHARESDATA[$ROUNDTRANSACTIONS[txs].username].valid|number_format} {$SHARESDATA[$ROUNDTRANSACTIONS[txs].username].invalid|number_format} {if $SHARESDATA[$ROUNDTRANSACTIONS[txs].username].invalid > 0 }{($SHARESDATA[$ROUNDTRANSACTIONS[txs].username].invalid / $SHARESDATA[$ROUNDTRANSACTIONS[txs].username].valid * 100)|number_format:"2"|default:"0"}{else}0.00{/if} diff --git a/public/templates/mpos/statistics/round/round_shares.tpl b/public/templates/mpos/statistics/round/round_shares.tpl index 3a58e846..a941f917 100644 --- a/public/templates/mpos/statistics/round/round_shares.tpl +++ b/public/templates/mpos/statistics/round/round_shares.tpl @@ -16,7 +16,7 @@ {foreach key=id item=data from=$ROUNDSHARES} {$rank++} - {if $data.is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$data.username|escape}{/if} + {if $data.is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$data.username|default:"unknown"|escape}{/if} {$data.valid|number_format} {$data.invalid|number_format} {if $data.invalid > 0 }{($data.invalid / $data.valid * 100)|number_format:"2"|default:"0"}{else}0.00{/if} diff --git a/public/templates/mpos/statistics/round/round_transactions.tpl b/public/templates/mpos/statistics/round/round_transactions.tpl index 1ab76f97..ddca39c8 100644 --- a/public/templates/mpos/statistics/round/round_transactions.tpl +++ b/public/templates/mpos/statistics/round/round_transactions.tpl @@ -13,7 +13,7 @@ {section txs $ROUNDTRANSACTIONS} - {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|escape}{/if} + {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|default:"unknown"|escape}{/if} {$ROUNDTRANSACTIONS[txs].type|default:""} {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format} {(( 100 / $BLOCKDETAILS.shares) * $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid)|default:"0"|number_format:"2"}