From 09d3dd51badbf35089a69f6b8ce338bf22327415 Mon Sep 17 00:00:00 2001 From: "admin@arionum.com" Date: Fri, 18 Oct 2019 07:38:52 +0300 Subject: [PATCH] auto resync --- include/config-sample.inc.php | 4 +++ include/init.inc.php | 2 +- sanity.php | 54 +++++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/include/config-sample.inc.php b/include/config-sample.inc.php index 37fd1c0..5d0d397 100755 --- a/include/config-sample.inc.php +++ b/include/config-sample.inc.php @@ -128,6 +128,10 @@ $_config['sanity_rebroadcast_locals'] = true; // Get more peers? $_config['get_more_peers'] = true; +// Allow automated resyncs if the node is stuck. Enabled by default + +$_config['auto_resync'] = true; + /* |-------------------------------------------------------------------------- | Logging Configuration diff --git a/include/init.inc.php b/include/init.inc.php index 62a7916..67a9d54 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -1,6 +1,6 @@ ($_config['sanity_interval'] ?? 900 * 10)) { + if (time() - $pid_time > ($_config['sanity_interval'] * 20 ?? 900 * 20)) { @unlink(SANITY_LOCK_PATH); } @@ -620,14 +620,21 @@ if ($current['height'] < $largest_height && $largest_height > 1) { if ($block_parse_failed==true||$argv[1]=="resync") { $last_resync=$db->single("SELECT val FROM config WHERE cfg='last_resync'"); if ($last_resync0) { - $to_remove=intval($argv[2]); + if ((($current['date']run("SET foreign_key_checks=0;"); + $tables = ["accounts", "transactions", "mempool", "masternode","blocks"]; + foreach ($tables as $table) { + $db->run("TRUNCATE TABLE {$table}"); } - _log("Removing $to_remove blocks, the blockchain is stale."); - $block->pop($to_remove); + $db->run("SET foreign_key_checks=1;"); + $resyncing=true; + $db->run("UPDATE config SET val=0 WHERE cfg='sanity_sync'", [":time" => $t]); + + _log("Exiting sanity, next sanity will resync from scratch."); + + @unlink(SANITY_LOCK_PATH); + exit; } elseif ($current['date']pop(200); @@ -746,19 +753,6 @@ foreach ($r as $x) { } } -//clean tmp files -_log("Cleaning tmp files"); -$f = scandir("tmp/"); -$time = time(); -foreach ($f as $x) { - if (strlen($x) < 5 && substr($x, 0, 1) == ".") { - continue; - } - $pid_time = filemtime("tmp/$x"); - if ($time - $pid_time > 7200) { - @unlink("tmp/$x"); - } -} //recheck the last blocks @@ -831,7 +825,7 @@ if ($_config['masternode']==true&&!empty($_config['masternode_public_key'])&&!em if ($f) { $res=json_decode($f, true); $res=$res['data']; - if ($res['height']<$current['height']-360) { + if ($res['height']<$current['height']-10080) { $blacklist=1; } echo "Masternode Height: ".$res['height']."\n"; @@ -885,6 +879,22 @@ if ($_config['masternode']==true&&!empty($_config['masternode_public_key'])&&!em +//clean tmp files +_log("Cleaning tmp files"); +$f = scandir("tmp/"); +$time = time(); +foreach ($f as $x) { + if (strlen($x) < 5 && substr($x, 0, 1) == ".") { + continue; + } + $pid_time = filemtime("tmp/$x"); + if ($time - $pid_time > 7200) { + @unlink("tmp/$x"); + } +} + + + _log("Finishing sanity"); -@unlink(SANITY_LOCK_PATH); \ No newline at end of file +@unlink(SANITY_LOCK_PATH);