From 45851ea6544f3c2f7b917808f186ffe1af878d98 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 13 Mar 2014 07:43:45 +0100 Subject: [PATCH 1/3] [FEATURE] Added Pool Bonus for Prop and PPLNS --- cronjobs/pplns_payout.php | 16 +++++++++++++--- cronjobs/proportional_payout.php | 17 ++++++++++++++--- public/include/config/global.inc.dist.php | 7 ++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 08656ed7e..68b3ef2d9 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -181,8 +181,8 @@ } // Table header for account shares - $strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |"; - $log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee')); + $strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |"; + $log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus')); // Loop through all accounts that have found shares for this round foreach ($aTotalAccountShares as $key => $aData) { @@ -202,15 +202,21 @@ $aData['fee' ] = 0; $aData['donation'] = 0; + // Calculate pool fees if ($config['fees'] > 0 && $aData['no_fees'] == 0) $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); + + // Calculate pool bonus if it applies, will be paid from liquid assets! + if ($config['pool_bonus'] > 0) + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + // Calculate donation amount, fees not included $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); // Verbose output of this users calculations $log->logInfo( sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'], - number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8) + number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8) ) ); @@ -225,6 +231,10 @@ if ($aData['donation'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) $log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError() . 'on block ' . $aBlock['id']); + // Add new bonus credit + if ($aData['pool_bonus'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id'])) + $log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError()); } // Add full round share statistics diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index a91ba7a4d..7f5b163fb 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -40,8 +40,8 @@ $count = 0; // Table header for account shares -$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |"; -$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee')); +$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s |"; +$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus')); foreach ($aAllBlocks as $iIndex => $aBlock) { // If we have unaccounted blocks without share_ids, they might not have been inserted yet if (!$aBlock['share_id']) { @@ -86,18 +86,25 @@ // Defaults $aData['fee' ] = 0; $aData['donation'] = 0; + $aData['pool_bonus'] = 0; $aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8); $aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8); + // Calculate pool fees if they apply if ($config['fees'] > 0 && $aData['no_fees'] == 0) $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); + + // Calculate pool bonus if it applies, will be paid from liquid assets! + if ($config['pool_bonus'] > 0) + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + // Calculate donation amount, fees not included $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); // Verbose output of this users calculations $log->logInfo( sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'], - number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)) + number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8)) ); // Update user share statistics @@ -114,6 +121,10 @@ if ($aData['donation'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) $log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError()); + // Add new bonus credit + if ($aData['pool_bonus'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id'])) + $log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError()); } // Add block as accounted for into settings table diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 2da7464ec..3df03f703 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -128,12 +128,13 @@ $config['txfee_manual'] = 0.1; /** - * Block Bonus - * Bonus in coins of block bonus + * Block & Pool Bonus + * Bonus coins for blockfinder or a pool bonus for everyone * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-block-bonus + * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-pool-bonus */ $config['block_bonus'] = 0; - +$config['pool_bonus'] = 0; /** * Payout System From d468c826940567d4b061c072051945c0735852dd Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 13 Mar 2014 14:25:52 +0100 Subject: [PATCH 2/3] [ADDED] Block or Payout based bonus percentage --- cronjobs/pplns_payout.php | 10 ++++++++-- cronjobs/proportional_payout.php | 9 +++++++-- public/include/config/global.inc.dist.php | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 68b3ef2d9..c256b2792 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -201,14 +201,20 @@ // Defaults $aData['fee' ] = 0; $aData['donation'] = 0; + $aData['pool_bonus'] = 0; // Calculate pool fees if ($config['fees'] > 0 && $aData['no_fees'] == 0) $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); // Calculate pool bonus if it applies, will be paid from liquid assets! - if ($config['pool_bonus'] > 0) - $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + if ($config['pool_bonus'] > 0) { + if ($config['pool_bonus_type'] == 'block') { + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + } else { + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8); + } + } // Calculate donation amount, fees not included $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 7f5b163fb..80b74231d 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -95,8 +95,13 @@ $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); // Calculate pool bonus if it applies, will be paid from liquid assets! - if ($config['pool_bonus'] > 0) - $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + if ($config['pool_bonus'] > 0) { + if ($config['pool_bonus_type'] == 'block') { + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8); + } else { + $aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8); + } + } // Calculate donation amount, fees not included $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 3df03f703..b1a2d7a7e 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -135,6 +135,7 @@ */ $config['block_bonus'] = 0; $config['pool_bonus'] = 0; +$config['pool_bonus_type'] = 'payout'; /** * Payout System From d205e53649a7e18e579428acb1a3fe80cca3597f Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 14 Mar 2014 11:49:57 +0100 Subject: [PATCH 3/3] [CLEANUP] Percentage column shorter --- cronjobs/proportional_payout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 80b74231d..58f47ee9b 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -40,7 +40,7 @@ $count = 0; // Table header for account shares -$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s |"; +$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |"; $log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus')); foreach ($aAllBlocks as $iIndex => $aBlock) { // If we have unaccounted blocks without share_ids, they might not have been inserted yet