blocks: avoid delayed coin save + screenlog func

in some cases, there was issues to save correctly with the coin form.
This commit is contained in:
Tanguy Pruvot 2018-07-11 00:44:31 +02:00
parent 243c7eaf39
commit 0f129bdd65
4 changed files with 29 additions and 22 deletions

View file

@ -1,5 +1,6 @@
<?php
require_once('functions.php');
require_once('blocks.php');
require_once('coins.php');
require_once('rawcoins.php');

View file

@ -281,6 +281,7 @@ function BackendBlocksUpdate($coinid = NULL)
// auto update mature_blocks
if ($block->confirmations > 0 && $block->confirmations < $coin->mature_blocks || empty($coin->mature_blocks)) {
$coin = getdbo('db_coins', $block->coin_id); // refresh coin data
debuglog("{$coin->symbol} mature_blocks updated to {$block->confirmations}");
$coin->mature_blocks = $block->confirmations;
$coin->save();
@ -295,7 +296,7 @@ function BackendBlocksUpdate($coinid = NULL)
}
////////////////////////////////////////////////////////////////////////////////////////////
// Search new block transactions
// Search new block transactions (main thread)
function BackendBlockFind2($coinid = NULL)
{
@ -319,13 +320,6 @@ function BackendBlockFind2($coinid = NULL)
{
if(!isset($transaction['blockhash'])) continue;
if($transaction['time'] > time() - 5*60) continue;
if($transaction['time'] > $mostrecent)
{
$coin->lastblock = $transaction['blockhash'];
$mostrecent = $transaction['time'];
}
if($transaction['time'] < time() - 60*60) continue;
if($transaction['category'] != 'generate' && $transaction['category'] != 'immature') continue;
@ -340,6 +334,13 @@ function BackendBlockFind2($coinid = NULL)
if ($coin->rpcencoding == 'DCR')
debuglog("{$coin->name} generated block {$blockext['height']} detected!");
if($transaction['time'] > $mostrecent) {
$coin = getdbo('db_coins', $coin->id); // refresh coin data
$coin->lastblock = $transaction['blockhash'];
$coin->save();
$mostrecent = $transaction['time'];
}
$db_block = new db_blocks;
$db_block->blockhash = $transaction['blockhash'];
$db_block->coin_id = $coin->id;
@ -367,6 +368,7 @@ function BackendBlockFind2($coinid = NULL)
}
if (!$coin->hasmasternodes) {
$coin = getdbo('db_coins', $coin->id); // refresh coin data
$coin->hasmasternodes = true;
$coin->save();
}
@ -380,14 +382,13 @@ function BackendBlockFind2($coinid = NULL)
debuglog(__FUNCTION__.": unable to insert block!");
BackendBlockNew($coin, $db_block);
}
$coin->save();
} // tx
}
$d1 = microtime(true) - $t1;
controller()->memcache->add_monitoring_function(__FUNCTION__, $d1);
//debuglog(__FUNCTION__." took ".round($d1,3)." sec");
screenlog(__FUNCTION__.": took ".round($d1,3)." sec");
}
////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,12 @@
<?php
/**
* Directly output Logs in screen (main/blocks/loop2)
*/
function screenlog($line)
{
$app = Yii::app();
if ($app instanceof CYiimpConsoleApp) {
$date = date('y-m-d h:i:s');
echo("$date $line\n");
}
}

View file

@ -3,12 +3,6 @@
require_once('serverconfig.php');
require_once('yaamp/defaultconfig.php');
function ld($string)
{
$d = date('h:i:s');
echo("$d - $string\n");
}
class CronjobController extends CommonController
{
private function monitorApache()
@ -47,7 +41,7 @@ class CronjobController extends CommonController
public function actionRunBlocks()
{
// debuglog(__METHOD__);
// screenlog(__FUNCTION__);
set_time_limit(0);
$this->monitorApache();
@ -55,7 +49,6 @@ class CronjobController extends CommonController
$last_complete = memcache_get($this->memcache->memcache, "cronjob_block_time_start");
if($last_complete+(5*60) < time())
dborun("update jobs set active=false");
BackendBlockFind1();
if(!memcache_get($this->memcache->memcache, 'balances_locked')) {
BackendClearEarnings();
@ -65,12 +58,12 @@ class CronjobController extends CommonController
BackendBlocksUpdate();
memcache_set($this->memcache->memcache, "cronjob_block_time_start", time());
// debuglog(__METHOD__);
// screenlog(__FUNCTION__.' done');
}
public function actionRunLoop2()
{
// debuglog(__METHOD__);
// screenlog(__FUNCTION__);
set_time_limit(0);
$this->monitorApache();
@ -99,7 +92,7 @@ class CronjobController extends CommonController
}
memcache_set($this->memcache->memcache, "cronjob_loop2_time_start", time());
// debuglog(__METHOD__);
// screenlog(__FUNCTION__.' done');
}
public function actionRun()