From d294e266a41bccb2a9617a87bc313e36bd5a4370 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 15 May 2014 10:40:28 +0200 Subject: [PATCH] [CHANGE] Estimated time per block calculations --- include/classes/statistics.class.php | 13 +++++++++---- include/pages/api/getdashboarddata.inc.php | 4 +++- include/pages/dashboard.inc.php | 2 +- include/pages/statistics/pool.inc.php | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/classes/statistics.class.php b/include/classes/statistics.class.php index 22f45c23..60de0c09 100644 --- a/include/classes/statistics.class.php +++ b/include/classes/statistics.class.php @@ -815,21 +815,26 @@ class Statistics extends Base { * Get the Expected Time per Block in the whole Network in seconde * @return seconds double Seconds per Block */ - public function getNetworkExpectedTimePerBlock(){ + public function getExpectedTimePerBlock($type='network',$hashrate = 0){ if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($this->bitcoin->can_connect() === true) { - $dNetworkHashrate = $this->bitcoin->getnetworkhashps(); + if ($type == 'network') { + $hashrate = $this->bitcoin->getnetworkhashps(); + } else { + // We need hashes/second and expect khash as input + $hashrate = $hashrate * 1000; + } $dDifficulty = $this->bitcoin->getdifficulty(); } else { $dNetworkHashrate = 1; $dDifficulty = 1; } - if($dNetworkHashrate <= 0){ + if($hashrate <= 0){ return $this->memcache->setCache(__FUNCTION__, $this->config['cointarget']); } - return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate)); + return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $hashrate)); } /** diff --git a/include/pages/api/getdashboarddata.inc.php b/include/pages/api/getdashboarddata.inc.php index b351ec64..ccd8a645 100644 --- a/include/pages/api/getdashboarddata.inc.php +++ b/include/pages/api/getdashboarddata.inc.php @@ -78,7 +78,8 @@ $iEstShares = $statistics->getEstimatedShares($dDifficulty); $iEstShares > 0 && $aRoundShares['valid'] > 0 ? $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2) : $dEstPercent = 0; // Some estimates -$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock(); +$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock(); +$dPoolExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $dPoolHashrate); $dEstNextDifficulty = $statistics->getExpectedNextDifficulty(); $iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange(); @@ -105,6 +106,7 @@ $data = array( 'name' => $setting->getValue('website_name'), 'currency' => $config['currency'] ), + 'esttimeperblock' => round($dPoolExpectedTimePerBlock, 2), 'blocks' => $aLastBlocks, 'workers' => $worker->getCountAllActiveWorkers(), 'hashrate' => $dPoolHashrateAdjusted, 'shares' => array( 'valid' => $aRoundShares['valid'], 'invalid' => $aRoundShares['invalid'], 'invalid_percent' => $dPoolInvalidPercent, 'estimated' => $iEstShares, 'progress' => $dEstPercent ), diff --git a/include/pages/dashboard.inc.php b/include/pages/dashboard.inc.php index c0ac2403..e813c834 100644 --- a/include/pages/dashboard.inc.php +++ b/include/pages/dashboard.inc.php @@ -33,7 +33,7 @@ if ($user->isAuthenticated()) { // Avoid confusion, ensure our nethash isn't higher than poolhash if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; - $dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock(); + $dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate); $dEstNextDifficulty = $statistics->getExpectedNextDifficulty(); $iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange(); diff --git a/include/pages/statistics/pool.inc.php b/include/pages/statistics/pool.inc.php index 47ba55c4..cc27b12f 100644 --- a/include/pages/statistics/pool.inc.php +++ b/include/pages/statistics/pool.inc.php @@ -32,7 +32,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); // Time in seconds, not hours, using modifier in smarty to translate - $iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0; + $iCurrentPoolHashrate > 0 ? $iEstTime = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate) : $iEstTime = 0; // Time since last block if (!empty($aBlockData)) { @@ -54,7 +54,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $dEstPercent = 0; } - $dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock(); + $dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock(); $dEstNextDifficulty = $statistics->getExpectedNextDifficulty(); $iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();