From 3deaf82f1e931793b5770b431a22b00370135995 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Feb 2014 11:38:57 +0100 Subject: [PATCH 1/3] [ADDED] Use block averages for payout estimates Fixes #1514 once merged. --- public/include/classes/block.class.php | 15 +++++++++++++++ public/include/classes/statistics.class.php | 3 ++- public/include/config/global.inc.dist.php | 4 ++-- public/include/pages/statistics/pool.inc.php | 5 ++++- public/include/smarty_globals.inc.php | 2 +- public/templates/mpos/statistics/pool/default.tpl | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 52cbfebf..ef0cdf7f 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -239,6 +239,21 @@ class Block extends Base { $field = array( 'name' => 'accounted', 'value' => 1, 'type' => 'i'); return $this->updateSingle($block_id, $field); } + + /** + * Fetch the average amount of the past N blocks + * @param limit int Block limit + * @param return mixed Block array or false + **/ + public function getAverageAmount($limit=10) { + $stmt = $this->mysqli->prepare("SELECT AVG(amount) as avg_amount FROM ( SELECT amount FROM $this->table ORDER BY id DESC LIMIT ?) AS t1"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result()) { + return $result->fetch_object()->avg_amount; + } else { + $this->setErrorMessage('Failed to get average award from blocks'); + return $this->sqlError(); + } + } } // Automatically load our class for furhter usage diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 5f746e8f..18b62041 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -808,7 +808,8 @@ class Statistics extends Base { $this->debug->append("STA " . __METHOD__, 4); if ($this->config['payout_system'] != 'pps') { if (@$value1['valid'] > 0 && @$value2['valid'] > 0) { - $aEstimates['block'] = round(( (int)$value2['valid'] / (int)$value1['valid'] ) * (float)$this->config['reward'], 8); + $this->config['reward_type'] == 'fixed' ? $reward = $this->config['reward'] : $reward = $this->block->getAverageAmount(); + $aEstimates['block'] = round(( (int)$value2['valid'] / (int)$value1['valid'] ) * (float)$reward, 8); $bNoFees == 0 ? $aEstimates['fee'] = round(((float)$this->config['fees'] / 100) * (float)$aEstimates['block'], 8) : $aEstimates['fee'] = 0; $aEstimates['donation'] = round((( (float)$dDonate / 100) * ((float)$aEstimates['block'] - (float)$aEstimates['fee'])), 8); $aEstimates['payout'] = round((float)$aEstimates['block'] - (float)$aEstimates['donation'] - (float)$aEstimates['fee'], 8); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 9a7c45eb..a4e1c8cf 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -192,7 +192,7 @@ $config['difficulty'] = 20; * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-reward-settings **/ $config['reward_type'] = 'block'; -$config['reward'] = 50; +$config['reward'] = 20; /** * Confirmations @@ -249,4 +249,4 @@ $config['smarty']['cache_lifetime'] = 30; **/ $config['system']['load']['max'] = 10.0; -?> \ No newline at end of file +?> diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 84fb3546..37ede713 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -42,6 +42,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $dTimeSinceLast = 0; } + // Block average reward or fixed + $reward = $config['reward_type'] == 'fixed' ? $config['reward'] : $block->getAverageAmount(); + // Round progress $iEstShares = $statistics->getEstimatedShares($dDifficulty); $aRoundShares = $statistics->getRoundShares(); @@ -73,7 +76,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $smarty->assign("LASTBLOCK", 0); } $smarty->assign("DIFFICULTY", $dDifficulty); - $smarty->assign("REWARD", $config['reward']); + $smarty->assign("REWARD", $reward); } else { $debug->append('Using cached page', 3); } diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 98b44bd1..060d6c96 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -60,7 +60,7 @@ $aGlobal = array( 'roundshares' => $aRoundShares, 'fees' => $config['fees'], 'confirmations' => $config['confirmations'], - 'reward' => $config['reward'], + 'reward' => $config['reward_type'] == 'fixed' ? $config['reward'] : $block->getAverageAmount(), 'price' => $setting->getValue('price'), 'twofactor' => $config['twofactor'], 'csrf' => $config['csrf'], diff --git a/public/templates/mpos/statistics/pool/default.tpl b/public/templates/mpos/statistics/pool/default.tpl index bd5a14d5..e1e0619b 100644 --- a/public/templates/mpos/statistics/pool/default.tpl +++ b/public/templates/mpos/statistics/pool/default.tpl @@ -1,4 +1,5 @@ +{$REWARD}
{include file="statistics/pool/contributors_shares.tpl"} {include file="statistics/pool/contributors_hashrate.tpl"} From 458a43d469c727a806a1737978b04b9779319d61 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Feb 2014 11:49:30 +0100 Subject: [PATCH 2/3] [FIX] Debug var removed --- public/templates/mpos/statistics/pool/default.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/public/templates/mpos/statistics/pool/default.tpl b/public/templates/mpos/statistics/pool/default.tpl index e1e0619b..bd5a14d5 100644 --- a/public/templates/mpos/statistics/pool/default.tpl +++ b/public/templates/mpos/statistics/pool/default.tpl @@ -1,5 +1,4 @@ -{$REWARD}
{include file="statistics/pool/contributors_shares.tpl"} {include file="statistics/pool/contributors_hashrate.tpl"} From 6130db50a59e101616c98df621d5688253df5599 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Feb 2014 12:19:16 +0100 Subject: [PATCH 3/3] [FIX] Default reward to 50 again --- public/include/config/global.inc.dist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index a4e1c8cf..49d7d259 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -192,7 +192,7 @@ $config['difficulty'] = 20; * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-reward-settings **/ $config['reward_type'] = 'block'; -$config['reward'] = 20; +$config['reward'] = 50; /** * Confirmations