From 0838bc77830941e25394da6ac71e7abd058060cf Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 26 Oct 2013 02:38:24 +0200 Subject: [PATCH] [FIX] Fixing PPS calculations * [FIX] PPS estimations * [FIX] PPS Value, PPS Payouts being off (too low) Tested on testnet, estimates worked perfectly and payouts worked well. --- cronjobs/pps_payout.php | 20 ++++++++++++-------- public/include/classes/statistics.class.php | 10 ++++------ public/include/config/global.inc.dist.php | 17 ++++++++++++++--- public/include/smarty_globals.inc.php | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 7c3515fb..58a72485 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -54,19 +54,18 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > if ($config['pps']['reward']['type'] == 'block') { if ($aLastBlock = $block->getLast()) { $pps_reward = $aLastBlock['amount']; - $log->logInfo("PPS reward using last block, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); } else { $pps_reward = $config['pps']['reward']['default']; - $log->logInfo("PPS reward using default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); } } else { $pps_reward = $config['pps']['reward']['default']; - $log->logInfo("PPS reward fixed default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); } } // Per-share value to be paid out to users -$pps_value = round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12); +$pps_value = round($pps_reward / (pow(2, $config['pps_target']) * $dDifficulty), 12); +echo (pow(2, $config['pps_target']) * $dDifficulty); + // Find our last share accounted and last inserted share for PPS calculations $iPreviousShareId = $setting->getValue('pps_last_share_id'); @@ -75,11 +74,16 @@ $iLastShareId = $share->getLastInsertedShareId(); // Check for all new shares, we start one higher as our last accounted share to avoid duplicates $aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId); -$log->logInfo("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee"); +if (!empty($aAccountShares)) { + // Info for this payout + $log->logInfo("PPS reward type: " . $config['pps']['reward']['type'] . ", amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty . "\tPPS value: " . $pps_value); + $log->logInfo("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee"); +} foreach ($aAccountShares as $aData) { - // Take our valid shares and multiply by per share value - $aData['payout'] = round($aData['valid'] * $pps_value, 8); + // 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); // Defaults $aData['fee' ] = 0; @@ -94,7 +98,7 @@ foreach ($aAccountShares as $aData) { $log->logInfo($aData['id'] . "\t" . $aData['username'] . "\t" . $aData['invalid'] . "\t" . - $aData['valid'] . "\t*\t" . + $aData['valid'] * pow(2, ($config['difficulty'] - 16)) . "\t*\t" . number_format($pps_value, 12) . "\t=\t" . number_format($aData['payout'], 8) . "\t" . number_format($aData['donation'], 8) . "\t" . diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 38f5360a..00e16066 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -645,14 +645,12 @@ class Statistics { } } else { // Hack so we can use this method for PPS estimates too + // value1 = shares/s + // value2 = avg share difficulty if (@$value1 > 0 && @$value2 > 0) { - // Default: No fees applied so multiply by 1 - $fee = 1; - if ($this->config['fees'] > 0) - $bNoFees == 0 ? $fee = round(((float)$this->config['fees'] / 100), 8) : $fee = 1; + $hour = 60 * 60; $pps = $value1 * $value2 * $ppsvalue; - $hour = 3600; - $aEstimates['hours1'] = $pps * $hour * $fee; + $aEstimates['hours1'] = $pps * $hour; $aEstimates['hours24'] = $pps * 24 * $hour; $aEstimates['days7'] = $pps * 24 * 7 * $hour; $aEstimates['days14'] = $pps * 14 * 24 * 7 * $hour; diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index b9cfda0d..734791fb 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -308,9 +308,20 @@ $config['pps']['reward']['default'] = 50; $config['pps']['reward']['type'] = 'blockavg'; $config['pps']['blockavg']['blockcount'] = 10; -// pps base payout target, default 16 = difficulty 1 shares for vardiff -// (1/(65536 * difficulty) * reward) = (reward / (pow(2,32) * difficulty) * pow(2, 16)) -$config['pps_target'] = 16; // do not change unless you know what it does +/** + * Please note: Do NOT touch this if you are running MPOS in scrypt coins! + * The VARDIFF / Stratum Settings / Target Bits system can be VERY confusing + * so unless you have spend over 2 hours talking with pooler, do not edit this. + * + * I have added this here to allow SHA256 coins in the future. For now, leave it + * at 16! + * + * Default: + * 16 = Scrypt + * Options: + * 32 = SHA256 + **/ +$config['pps_target'] = 16; /** * Memcache configuration diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 9bb4ac60..da5916ec 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -140,7 +140,7 @@ if (@$_SESSION['USERDATA']['id']) { } } - $aGlobal['ppsvalue'] = number_format(round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); + $aGlobal['ppsvalue'] = number_format(round($pps_reward / (pow(2, $config['pps_target']) * $dDifficulty), 12) ,12); $aGlobal['userdata']['sharedifficulty'] = $statistics->getUserShareDifficulty($_SESSION['USERDATA']['id']); $aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']); break;