Skip to content

Commit 0af2b90

Browse files
committed
Merge pull request #680 from obigal/pplns-payout-blockavg-fix
pplns_payout block average fix when multiple blocks found during a payou...
2 parents 57e9aff + 66296a8 commit 0af2b90

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

cronjobs/pplns_payout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// We support some dynamic share targets but fall back to our fixed value
4747
// Re-calculate after each run due to re-targets in this loop
4848
if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) {
49-
$pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount']));
49+
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']));
5050
} else {
5151
$pplns_target = $config['pplns']['shares']['default'];
5252
}

public/include/classes/block.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public function getBlockCount() {
109109
* @param limit int Maximum blocks to check
110110
* @return data float Float value of average shares
111111
**/
112-
public function getAvgBlockShares($limit=1) {
113-
$stmt = $this->mysqli->prepare("SELECT AVG(x.shares) AS average FROM (SELECT shares FROM $this->table ORDER BY height DESC LIMIT ?) AS x");
114-
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result())
112+
public function getAvgBlockShares($height, $limit=1) {
113+
$stmt = $this->mysqli->prepare("SELECT AVG(x.shares) AS average FROM (SELECT shares FROM $this->table WHERE height <= ? ORDER BY height DESC LIMIT ?) AS x");
114+
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $height, $limit) && $stmt->execute() && $result = $stmt->get_result())
115115
return (float)$result->fetch_object()->average;
116116
return false;
117117
}

public/include/smarty_globals.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
$aGlobal['userdata']['est_payout'] = 0;
137137
}
138138
case 'pplns':
139-
if ($iAvgBlockShares = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount']))) {
139+
if ($aLastBlock = $block->getLast() && $iAvgBlockShares = round($block->getAvgBlockShares($aLastBlock['height'], $config['pplns']['blockavg']['blockcount']))) {
140140
$aGlobal['pplns']['target'] = $iAvgBlockShares;
141141
} else {
142142
$aGlobal['pplns']['target'] = $config['pplns']['shares']['default'];

0 commit comments

Comments
 (0)