adjusting pplns target to baseline shares
This commit is contained in:
parent
75d0dfe5f7
commit
c9a8f8dc65
@ -45,9 +45,12 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) {
|
||||
$pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount']));
|
||||
} else {
|
||||
$pplns_target = $config['pplns']['shares']['default'] ;
|
||||
$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'];
|
||||
@ -65,7 +68,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
|
||||
if ($iRoundShares >= $pplns_target) {
|
||||
$log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares");
|
||||
$aAccountShares = $share->getSharesForAccounts($aBlock['share_id'] - $pplns_target, $aBlock['share_id']);
|
||||
$iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']);
|
||||
$aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $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);
|
||||
@ -73,8 +77,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
}
|
||||
foreach($aAccountShares as $key => $aData) {
|
||||
$iNewRoundShares += $aData['valid'];
|
||||
}
|
||||
$log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target);
|
||||
$iRoundShares = $pplns_target;
|
||||
$iRoundShares = $iNewRoundShares;
|
||||
} else {
|
||||
$log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares");
|
||||
// We need to fill up with archived shares
|
||||
|
||||
@ -130,7 +130,7 @@ class Share {
|
||||
* return array data Returns an array with usernames as keys for easy access
|
||||
**/
|
||||
function getArchiveShares($iCount) {
|
||||
$iMinId = $this->getMaxArchiveShareId() - $iCount;
|
||||
$iMinId = $this->getMinArchiveShareId($iCount);
|
||||
$iMaxId = $this->getMaxArchiveShareId();
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
@ -307,6 +307,46 @@ class Share {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the lowest needed share ID from shares
|
||||
**/
|
||||
function getMinimumShareId($iCount, $current_upstream) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT MIN(b.id) AS id FROM
|
||||
(
|
||||
SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total
|
||||
FROM $this->table, (SELECT @total := 0) AS a
|
||||
WHERE our_result = 'Y'
|
||||
AND id <= ? AND @total < ?
|
||||
ORDER BY id DESC
|
||||
) AS b
|
||||
WHERE total <= ?
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the lowest needed share ID from archive
|
||||
**/
|
||||
function getMinArchiveShareId($iCount) {
|
||||
$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
|
||||
FROM $this->tableArchive, (SELECT @total := 0) AS a
|
||||
WHERE our_result = 'Y'
|
||||
AND @total < ?
|
||||
ORDER BY share_id DESC
|
||||
) AS b
|
||||
WHERE total <= ?
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->share_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
**/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user