[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.
This commit is contained in:
Sebastian Grewe 2013-10-26 02:38:24 +02:00
parent ee46e65fca
commit 0838bc7783
4 changed files with 31 additions and 18 deletions

View File

@ -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" .

View File

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

View File

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

View File

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