fixing PPLNS payouts one last time

This commit is contained in:
Sebastian Grewe 2013-08-22 16:16:04 +02:00
parent db754c146e
commit 6eec747be6
2 changed files with 7 additions and 6 deletions

View File

@ -48,9 +48,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$pplns_target = $config['pplns']['shares']['default'];
}
// We use baseline shares, so we have to calculate back to diff shares
$pplns_target = $pplns_target * pow(2, ($config['difficulty'] - 16));
if (!$aBlock['accounted']) {
$iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0;
$iCurrentUpstreamId = $aBlock['share_id'];
@ -69,7 +66,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if ($iRoundShares >= $pplns_target) {
$log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares");
$iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']);
$aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $aBlock['share_id']);
// We need to go one ID lower due to `id >` or we won't match if minimum share ID == $aBlock['share_id']
$aAccountShares = $share->getSharesForAccounts($iMinimumShareId - 1, $aBlock['share_id']);
if (empty($aAccountShares)) {
$log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height']);
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
@ -80,7 +78,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
foreach($aAccountShares as $key => $aData) {
$iNewRoundShares += $aData['valid'];
}
$log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target);
$log->logInfo('Adjusting round target to PPLNS target ' . $iNewRoundShares);
$iRoundShares = $iNewRoundShares;
} else {
$log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares");
@ -160,6 +158,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$statistics->updateShareStatistics($aRoundData, $aBlock['id']))
$log->logError('Failed to update share statistics for ' . $aData['username']);
}
// Add new credit transaction
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
$log->logFatal('Failed to insert new Credit transaction to database for ' . $aData['username']);

View File

@ -311,6 +311,8 @@ class Share {
* Fetch the lowest needed share ID from shares
**/
function getMinimumShareId($iCount, $current_upstream) {
// We don't use baseline here to be more accurate
$iCount = $iCount * pow(2, ($this->config['difficulty'] - 16));
$stmt = $this->mysqli->prepare("
SELECT MIN(b.id) AS id FROM
(
@ -334,7 +336,7 @@ class Share {
$stmt = $this->mysqli->prepare("
SELECT MIN(b.share_id) AS share_id FROM
(
SELECT share_id, @total := @total + IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total
SELECT share_id, @total := @total + (IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) / POW(2, (" . $this->config['difficulty'] . " - 16))) AS total
FROM $this->tableArchive, (SELECT @total := 0) AS a
WHERE our_result = 'Y'
AND @total < ?