Skip to content

Commit 5724068

Browse files
committed
Merge pull request #2191 from MPOS/estblock-changes
[CHANGE] Est time per block changes
2 parents fef95b9 + 4cb0e1c commit 5724068

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

include/classes/statistics.class.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -815,21 +815,23 @@ public function getEstimatedShares($dDiff) {
815815
* Get the Expected Time per Block in the whole Network in seconde
816816
* @return seconds double Seconds per Block
817817
*/
818-
public function getNetworkExpectedTimePerBlock(){
818+
public function getExpectedTimePerBlock($type='network',$hashrate = 0){
819819
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
820820

821821
if ($this->bitcoin->can_connect() === true) {
822-
$dNetworkHashrate = $this->bitcoin->getnetworkhashps();
822+
if ($type == 'network') {
823+
$hashrate = $this->bitcoin->getnetworkhashps();
824+
} else {
825+
// We need hashes/second and expect khash as input
826+
$hashrate = $hashrate * 1000;
827+
}
823828
$dDifficulty = $this->bitcoin->getdifficulty();
824829
} else {
825-
$dNetworkHashrate = 1;
830+
$hashrate = 1;
826831
$dDifficulty = 1;
827832
}
828-
if($dNetworkHashrate <= 0){
829-
return $this->memcache->setCache(__FUNCTION__, $this->config['cointarget']);
830-
}
831-
832-
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate));
833+
if ($hashrate <= 0) $hashrate = 1;
834+
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $hashrate));
833835
}
834836

835837
/**

include/pages/api/getdashboarddata.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
$iEstShares > 0 && $aRoundShares['valid'] > 0 ? $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2) : $dEstPercent = 0;
7979

8080
// Some estimates
81-
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
81+
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock();
82+
$dPoolExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $dPoolHashrate);
8283
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
8384
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
8485

@@ -105,6 +106,7 @@
105106
'name' => $setting->getValue('website_name'),
106107
'currency' => $config['currency']
107108
),
109+
'esttimeperblock' => round($dPoolExpectedTimePerBlock, 2),
108110
'blocks' => $aLastBlocks,
109111
'workers' => $worker->getCountAllActiveWorkers(), 'hashrate' => $dPoolHashrateAdjusted,
110112
'shares' => array( 'valid' => $aRoundShares['valid'], 'invalid' => $aRoundShares['invalid'], 'invalid_percent' => $dPoolInvalidPercent, 'estimated' => $iEstShares, 'progress' => $dEstPercent ),

include/pages/dashboard.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// Avoid confusion, ensure our nethash isn't higher than poolhash
3434
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
3535

36-
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
36+
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate);
3737
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
3838
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
3939

include/pages/statistics/pool.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$iCurrentPoolHashrate = $statistics->getCurrentHashrate();
3333

3434
// Time in seconds, not hours, using modifier in smarty to translate
35-
$iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0;
35+
$iCurrentPoolHashrate > 0 ? $iEstTime = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate) : $iEstTime = 0;
3636

3737
// Time since last block
3838
if (!empty($aBlockData)) {
@@ -54,7 +54,7 @@
5454
$dEstPercent = 0;
5555
}
5656

57-
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
57+
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock();
5858
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
5959
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
6060

templates/bootstrap/dashboard/js/api.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ $(document).ready(function(){
117117
$('#b-nextdiff').html('n/a');
118118
$('#b-nextdiffc').html(' No Estimates');
119119
}
120-
var minutes = Math.floor(data.getdashboarddata.data.network.esttimeperblock / 60);
121-
var seconds = Math.floor(data.getdashboarddata.data.network.esttimeperblock - minutes * 60);
120+
var minutes = Math.floor(data.getdashboarddata.data.pool.esttimeperblock / 60);
121+
var seconds = Math.floor(data.getdashboarddata.data.pool.esttimeperblock - minutes * 60);
122122
$('#b-esttimeperblock').html(minutes + " minutes " + seconds + " seconds"); // <- this needs some nicer format
123123
$('#b-nblock').html(data.getdashboarddata.data.network.block);
124124
$('#b-roundprogress').html(number_format(parseFloat(data.getdashboarddata.data.pool.shares.progress).toFixed(2), 2) + "%");

0 commit comments

Comments
 (0)