diff --git a/include/class/Block.php b/include/class/Block.php index 5239fe76..1ad8f511 100755 --- a/include/class/Block.php +++ b/include/class/Block.php @@ -191,7 +191,7 @@ public function add(&$error = null, $syncing=false) Cache::set("current", $this->toArray()); Cache::set("height", $this->height); Cache::set("current_export", Block::export($hash)); - Cache::set("mineInfo", Blockchain::getMineInfo()); + Cache::set("mineInfo", Blockchain::calculateMineInfo()); Masternode::resetVerified(); @@ -708,6 +708,7 @@ public static function delete($height) Cache::remove("mineInfo"); Cache::remove("height"); Cache::remove("current_export"); + Cache::remove("mineInfo"); } catch (Exception $e) { _log("Error locking delete blocks ".$e->getMessage()); diff --git a/include/class/Blockchain.php b/include/class/Blockchain.php index aca98560..2f04a39b 100644 --- a/include/class/Blockchain.php +++ b/include/class/Blockchain.php @@ -30,7 +30,7 @@ static function getAvgBlockTime($blocks) { return $elapsed / $blocks; } - static function getMineInfo() { + static function calculateMineInfo() { global $_config; $diff = Block::difficulty(); $current = Block::current(); @@ -55,6 +55,15 @@ static function getMineInfo() { return $res; } + static function getMineInfo() { + $info = Cache::get("mineInfo"); + if(empty($info)) { + $info = Blockchain::calculateMineInfo(); + Cache::set("mineInfo", $info); + } + return $info; + } + static function addBlock(Block $block) { } diff --git a/include/class/Cache.php b/include/class/Cache.php index 2f09fcc8..d3b53e26 100644 --- a/include/class/Cache.php +++ b/include/class/Cache.php @@ -29,7 +29,7 @@ static function get($key, $default = null) { if(file_exists($cache_file)) { $content = file_get_contents($cache_file); $res = json_decode($content, true); - if($res) { + if (json_last_error() === JSON_ERROR_NONE) { return $res; } } diff --git a/include/class/NodeMiner.php b/include/class/NodeMiner.php index be38ff5d..2072cd96 100644 --- a/include/class/NodeMiner.php +++ b/include/class/NodeMiner.php @@ -149,18 +149,12 @@ function start($mine_blocks = null, $sleep = 3) { _log("Mining attempt={$this->attempt} height=$height difficulty=$difficulty elapsed=$elapsed hit=$hit target=$target speed={$this->speed} blockFound=$blockFound", 3); $this->miningStat['hashes']++; - $mod = 10+$this->cpu; - if($this->attempt % $mod == 0) { - $info = $this->getMiningInfo(); - if($info!==false) { - _log("Checking new block from server ".$info['block']. " with our block $prev_block_id", 4); - if($info['block']!= $prev_block_id) { - _log("New block received", 3); - $this->miningStat['dropped']++; - break; - } - } - } + $info = $this->getMiningInfo(); + if ($info['block'] != $prev_block_id) { + _log("New block received", 3); + $this->miningStat['dropped']++; + break; + } $send_interval = 60; $t=time();