[IMPROVED] PPLNS payout log format

This commit is contained in:
Sebastian Grewe 2014-02-15 17:10:58 +01:00
parent 950e607230
commit ee805b65ce

View File

@ -38,6 +38,7 @@ if (empty($aAllBlocks)) {
$monitoring->endCronjob($cron_name, 'E0011', 0, true, false); $monitoring->endCronjob($cron_name, 'E0011', 0, true, false);
} }
$log->logDebug('Starting PPLNS payout process');
$count = 0; $count = 0;
foreach ($aAllBlocks as $iIndex => $aBlock) { foreach ($aAllBlocks as $iIndex => $aBlock) {
// If we have unaccounted blocks without share_ids, they might not have been inserted yet // If we have unaccounted blocks without share_ids, they might not have been inserted yet
@ -77,29 +78,31 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$config['reward_type'] == 'block' ? $dReward = $aBlock['amount'] : $dReward = $config['reward']; $config['reward_type'] == 'block' ? $dReward = $aBlock['amount'] : $dReward = $config['reward'];
$aRoundAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']); $aRoundAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']);
$log->logInfo('Target: ' . $pplns_target . '; Shares: ' . $iRoundShares . '; Height: ' . $aBlock['height'] . '; Amount: ' . $aBlock['amount'] . '; Found by ID: ' . $aBlock['account_id']); $strLogMask = "| %20.20s | %20.20s | %8.8s | %10.10s | %15.15s |";
$log->logInfo(sprintf($strLogMask, 'PPLNS Target', 'Actual Shares', 'Height', 'Amount', 'Finder'));
$log->logInfo(sprintf($strLogMask, $pplns_target, $iRoundShares, $aBlock['height'], $aBlock['amount'], $user->getUsername($aBlock['account_id'])));
if ($iRoundShares >= $pplns_target) { if ($iRoundShares >= $pplns_target) {
$log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares"); $log->logDebug(" Matching or exceeding PPLNS target of $pplns_target with $iRoundShares");
$iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']); $iMinimumShareId = $share->getMinimumShareId($pplns_target, $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'] // 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']); $aAccountShares = $share->getSharesForAccounts($iMinimumShareId - 1, $aBlock['share_id']);
if (empty($aAccountShares)) { if (empty($aAccountShares)) {
$log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height'] . ', Block ID: ' . $aBlock['id']); $log->logFatal(" No shares found for this block, aborted! Block Height : " . $aBlock['height'] . ', Block ID: ' . $aBlock['id']);
$monitoring->endCronjob($cron_name, 'E0013', 1, true); $monitoring->endCronjob($cron_name, 'E0013', 1, true);
} }
foreach($aAccountShares as $key => $aData) { foreach($aAccountShares as $key => $aData) {
$iNewRoundShares += $aData['valid']; $iNewRoundShares += $aData['valid'];
} }
$log->logInfo('Adjusting round to PPLNS target of ' . $pplns_target . ' shares used ' . $iNewRoundShares); $log->logInfo(' Adjusting round to PPLNS target of ' . $pplns_target . ' shares used ' . $iNewRoundShares);
$iRoundShares = $iNewRoundShares; $iRoundShares = $iNewRoundShares;
} else { } else {
$log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares"); $log->logDebug(" Not able to match PPLNS target of $pplns_target with $iRoundShares");
// We need to fill up with archived shares // We need to fill up with archived shares
// Grab the full current round shares since we didn't match target // Grab the full current round shares since we didn't match target
$aAccountShares = $aRoundAccountShares; $aAccountShares = $aRoundAccountShares;
if (empty($aAccountShares)) { if (empty($aAccountShares)) {
$log->logFatal("No shares found for this block, aborted! Block height: " . $aBlock['height'] . ', Block ID:' . $aBlock['id']); $log->logFatal(" No shares found for this block, aborted! Block height: " . $aBlock['height'] . ', Block ID:' . $aBlock['id']);
$monitoring->endCronjob($cron_name, 'E0013', 1, true); $monitoring->endCronjob($cron_name, 'E0013', 1, true);
} }
@ -112,27 +115,31 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
// Add archived shares to users current shares, if we have any in archive // Add archived shares to users current shares, if we have any in archive
if (is_array($aArchiveShares)) { if (is_array($aArchiveShares)) {
$log->logDebug('Found shares in archive to match PPLNS target, calculating per-user shares'); $log->logDebug('Found shares in archive to match PPLNS target, calculating per-user shares');
$strLogMask = "| %-20.20s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s | %15.15s |";
$log->logDebug(sprintf($strLogMask, 'Username', 'Round Valid', 'Archive Valid', 'Total Valid', 'Round Invalid', 'Archive Invalid', 'Total Invalid'));
foreach($aAccountShares as $key => $aData) { foreach($aAccountShares as $key => $aData) {
if (array_key_exists($aData['username'], $aArchiveShares)) { if (array_key_exists($aData['username'], $aArchiveShares)) {
$log->logDebug('Found user ' . $aData['username'] . ' in archived shares'); $log->logDebug(sprintf($strLogMask, $aData['username'],
$log->logDebug(' valid : ' . $aAccountShares[$key]['valid'] . ' + ' . $aArchiveShares[$aData['username']]['valid'] . ' = ' . ($aAccountShares[$key]['valid'] + $aArchiveShares[$aData['username']]['valid']) ); $aAccountShares[$key]['valid'], $aArchiveShares[$aData['username']]['valid'], ($aAccountShares[$key]['valid'] + $aArchiveShares[$aData['username']]['valid']),
$log->logDebug(' invalid : ' . $aAccountShares[$key]['invalid'] . ' + ' . $aArchiveShares[$aData['username']]['invalid'] . ' = ' . ($aAccountShares[$key]['invalid'] + $aArchiveShares[$aData['username']]['invalid']) ); $aAccountShares[$key]['invalid'], $aArchiveShares[$aData['username']]['invalid'], ($aAccountShares[$key]['invalid'] + $aArchiveShares[$aData['username']]['invalid']))
);
$aAccountShares[$key]['valid'] += $aArchiveShares[$aData['username']]['valid']; $aAccountShares[$key]['valid'] += $aArchiveShares[$aData['username']]['valid'];
$aAccountShares[$key]['invalid'] += $aArchiveShares[$aData['username']]['invalid']; $aAccountShares[$key]['invalid'] += $aArchiveShares[$aData['username']]['invalid'];
} }
} }
// reverse payout // reverse payout
if ($config['pplns']['reverse_payout']) { if ($config['pplns']['reverse_payout']) {
$log->logDebug('Reverse payout enabled, adding shelved shares for all users');
$aSharesData = NULL; $aSharesData = NULL;
foreach($aAccountShares as $key => $aData) { foreach($aAccountShares as $key => $aData) {
$aSharesData[$aData['username']] = $aData; $aSharesData[$aData['username']] = $aData;
} }
// Add users from archive not in current round // Add users from archive not in current round
$strLogMask = "| %-20.20s | %15.15s | %15.15s |";
$log->logDebug(sprintf($strLogMask, 'Username', 'Shelved Valid', 'Shelved Invalid'));
foreach($aArchiveShares as $key => $aArchData) { foreach($aArchiveShares as $key => $aArchData) {
if (!array_key_exists($aArchData['account'], $aSharesData)) { if (!array_key_exists($aArchData['account'], $aSharesData)) {
$log->logDebug('Adding user ' . $aArchData['account'] . ' to round shares'); $log->logDebug(sprintf($strLogMask, $aArchData['account'], $aArchData['valid'], $aArchData['invalid']));
$log->logDebug(' valid : ' . $aArchData['valid']);
$log->logDebug(' invalid : ' . $aArchData['invalid']);
$aArchData['username'] = $aArchData['account']; $aArchData['username'] = $aArchData['account'];
$aSharesData[$aArchData['account']] = $aArchData; $aSharesData[$aArchData['account']] = $aArchData;
} }
@ -174,7 +181,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
} }
// Table header for account shares // Table header for account shares
$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee"); $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'));
// Loop through all accounts that have found shares for this round // Loop through all accounts that have found shares for this round
foreach ($aTotalAccountShares as $key => $aData) { foreach ($aTotalAccountShares as $key => $aData) {
@ -200,14 +208,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
// Verbose output of this users calculations // Verbose output of this users calculations
$log->logInfo($aData['id'] . "\t" . $log->logInfo(
$aData['username'] . "\t" . sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'],
$aData['pplns_valid'] . "\t" . number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)
$aData['pplns_invalid'] . "\t" . )
number_format($aData['percentage'], 8) . "\t" . );
number_format($aData['payout'], 8) . "\t" .
number_format($aData['donation'], 8) . "\t" .
number_format($aData['fee'], 8));
// Add new credit transaction // Add new credit transaction
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))