Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/class/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());
Expand Down
11 changes: 10 additions & 1 deletion include/class/Blockchain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {

}
Expand Down
2 changes: 1 addition & 1 deletion include/class/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
18 changes: 6 additions & 12 deletions include/class/NodeMiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down