Merge pull request #8 from arionum/master

alpha 5
This commit is contained in:
Ario Sius
2020-02-02 13:12:06 +01:00
committed by GitHub
4 changed files with 73 additions and 65 deletions

View File

@@ -1431,12 +1431,13 @@ class Block
public function pop($no = 1)
{
$current = $this->current();
$this->delete($current['height'] - $no + 1);
return $this->delete($current['height'] - $no + 1);
}
// delete all blocks >= height
public function delete($height)
{
global $_config;
if ($height < 2) {
$height = 2;
}
@@ -1446,7 +1447,7 @@ class Block
$r = $db->run("SELECT * FROM blocks WHERE height>=:height ORDER by height DESC", [":height" => $height]);
if (count($r) == 0) {
return;
return true;
}
$db->beginTransaction();
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE, masternode WRITE, peers write, config WRITE, assets WRITE, assets_balance WRITE, assets_market WRITE, votes WRITE,logs WRITE");
@@ -1456,6 +1457,25 @@ class Block
if ($res === false) {
_log("A transaction could not be reversed. Delete block failed.");
$db->rollback();
// the blockchain has some flaw, we should resync from scratch
$current = $this->current();
if (($current['date']<time()-(3600*48)) && $_config['auto_resync']!==false) {
_log("Blockchain corrupted. Resyncing from scratch.");
$db->run("SET foreign_key_checks=0;");
$tables = ["accounts", "transactions", "mempool", "masternode","blocks"];
foreach ($tables as $table) {
$db->run("TRUNCATE TABLE {$table}");
}
$db->run("SET foreign_key_checks=1;");
$db->exec("UNLOCK TABLES");
$db->run("UPDATE config SET val=0 WHERE cfg='sanity_sync'");
@unlink(SANITY_LOCK_PATH);
system("php sanity.php > /dev/null 2>&1 &");
exit;
}
$db->exec("UNLOCK TABLES");
return false;
}

View File

@@ -1,6 +1,6 @@
<?php
// ARO version
define("VERSION", "1.0.0-alpha.4");
define("VERSION", "1.0.0-alpha.5");
// UTC timezone by default
date_default_timezone_set("UTC");