From 0f129bdd659c51c854a18631fd0039e553e6c92a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 11 Jul 2018 00:44:31 +0200 Subject: [PATCH] blocks: avoid delayed coin save + screenlog func in some cases, there was issues to save correctly with the coin form. --- web/yaamp/core/backend/backend.php | 1 + web/yaamp/core/backend/blocks.php | 23 ++++++++++--------- web/yaamp/core/backend/functions.php | 12 ++++++++++ .../modules/thread/CronjobController.php | 15 ++++-------- 4 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 web/yaamp/core/backend/functions.php diff --git a/web/yaamp/core/backend/backend.php b/web/yaamp/core/backend/backend.php index 4f0c177..b2940d3 100644 --- a/web/yaamp/core/backend/backend.php +++ b/web/yaamp/core/backend/backend.php @@ -1,5 +1,6 @@ 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"); } //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/web/yaamp/core/backend/functions.php b/web/yaamp/core/backend/functions.php new file mode 100644 index 0000000..96c8357 --- /dev/null +++ b/web/yaamp/core/backend/functions.php @@ -0,0 +1,12 @@ +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()