sql dump bootstrapping

This commit is contained in:
admin@arionum.com
2019-09-16 06:16:35 +03:00
parent 55816af407
commit 4697718bdc

View File

@@ -95,61 +95,23 @@ $current = $block->current();
// bootstrapping the initial sync // bootstrapping the initial sync
if ($current['height']==1) { if ($current['height']==1) {
echo "Bootstrapping!\n"; echo "Bootstrapping!\n";
$last=file_get_contents("http://dumps.arionum.com/last"); $db_name=substr($_config['db_connect'], strrpos($_config['db_connect'], "dbname=")+7);
$last=intval($last); echo "DB name: $db_name\n";
$failed_sync=false; echo "Downloading the blockchain dump from arionum.info\n";
for ($i=1000;$i<=$last;$i=$i+1000) { $arofile=__DIR__ . '/tmp/aro.sql';
echo "Download file $i\n"; if (file_exists("/usr/bin/curl")) {
$res=trim(file_get_contents("http://dumps.arionum.com/aro.db.$i")); system("/usr/bin/curl -o $arofile 'https://arionum.info/dump/aro.sql'", $ret);
if ($res===false) { } elseif (file_exists("/usr/bin/wget")) {
echo "Could not download the bootstrap file $i. Syncing the old fashioned way.\n"; system("/usr/bin/wget -O $arofile 'https://arionum.info/dump/aro.sql'", $ret);
break; } else {
} die("/usr/bin/curl and /usr/bin/wget not installed or inaccessible. Please install either of them.");
$data=json_decode($res, true);
if ($data===false||is_null($data)) {
echo "Could not parse the bootstrap file $i. Syncing the old fashioned way.\n";
echo json_last_error_msg();
break;
}
foreach ($data as $x) {
if (count($x['data'])>0) {
$transactions=[];
foreach ($x['data'] as $d) {
$trans = [
"id" => $d[0],
"dst" => $d[1],
"val" => $d[2],
"fee" => $d[3],
"signature" => $d[4],
"message" => $d[5],
"version" => $d[6],
"date" => $d[7],
"public_key" => $d[8],
];
ksort($trans);
$transactions[$d[0]] = $trans;
}
ksort($transactions);
$x['data']=$transactions;
} }
echo "-> Adding block $x[height]\n"; echo "Importing the blockchain dump\n";
system("mysql -u ".escapeshellarg($_config['db_user'])." -p".escapeshellarg($_config['db_pass'])." ".escapeshellarg($db_name). " < ".$arofile);
$res=$block->add($x['height'], $x['public_key'], $x['nonce'], $x['data'], $x['date'], $x['signature'], $x['difficulty'], $x['reward_signature'], $x['argon'], true); echo "Bootstrapping completed. Sleeping for 3 min. \n";
if (!$res) { sleep(180);
echo "Error: Adding the block failed. Syncing the old way.\n";
$failed_sync=true;
break;
}
}
if ($failed_sync) {
break;
}
}
$current = $block->current(); $current = $block->current();
} }
// the microsanity process is an anti-fork measure that will determine the best blockchain to choose for the last block // the microsanity process is an anti-fork measure that will determine the best blockchain to choose for the last block
@@ -683,7 +645,6 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
// $db->run("DELETE FROM masternode WHERE height>:h", [":h"=>$current['height']]); // $db->run("DELETE FROM masternode WHERE height>:h", [":h"=>$current['height']]);
// $db->exec("UNLOCK TABLES"); // $db->exec("UNLOCK TABLES");
// } // }
} }
} }
@@ -893,12 +854,8 @@ echo "Masternode votes\n";
$hash=escapeshellarg(san($hash)); $hash=escapeshellarg(san($hash));
system("php propagate.php transaction $hash > /dev/null 2>&1 &"); system("php propagate.php transaction $hash > /dev/null 2>&1 &");
echo "Blacklist Hash: $hash\n"; echo "Blacklist Hash: $hash\n";
} }
} }
} }