sync fix
This commit is contained in:
97
util.php
97
util.php
@@ -43,6 +43,8 @@ $cmd = trim($argv[1]);
|
||||
*/
|
||||
|
||||
if ($cmd == 'clean') {
|
||||
if(file_exists("tmp/sanity-lock")) die("Sanity running. Wait for it to finish");
|
||||
touch("tmp/sanity-lock");
|
||||
$db->run("SET foreign_key_checks=0;");
|
||||
$tables = ["accounts", "transactions", "mempool", "masternode","blocks"];
|
||||
foreach ($tables as $table) {
|
||||
@@ -51,6 +53,7 @@ if ($cmd == 'clean') {
|
||||
$db->run("SET foreign_key_checks=1;");
|
||||
|
||||
echo "\n The database has been cleared\n";
|
||||
unlink("tmp/sanity-lock");
|
||||
} /**
|
||||
* @api {php util.php} pop Pop
|
||||
* @apiName pop
|
||||
@@ -64,9 +67,12 @@ if ($cmd == 'clean') {
|
||||
*/
|
||||
|
||||
elseif ($cmd == 'pop') {
|
||||
if(file_exists("tmp/sanity-lock")) die("Sanity running. Wait for it to finish");
|
||||
touch("tmp/sanity-lock");
|
||||
$no = intval($argv[2]);
|
||||
$block = new Block();
|
||||
$block->pop($no);
|
||||
unlink("tmp/sanity-lock");
|
||||
} /**
|
||||
* @api {php util.php} block-time Block-time
|
||||
* @apiName block-time
|
||||
@@ -411,7 +417,7 @@ elseif ($cmd == "check-address") {
|
||||
}
|
||||
|
||||
echo "The address is valid\n";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api {php util.php} get-address Get-Address
|
||||
* @apiName get-address
|
||||
@@ -443,35 +449,78 @@ elseif ($cmd == 'get-address') {
|
||||
* php util.php clean-blacklist
|
||||
*
|
||||
*/
|
||||
|
||||
} elseif ($cmd == 'clean-blacklist') {
|
||||
$db->run("UPDATE peers SET blacklisted=0, fails=0, stuckfail=0");
|
||||
echo "All the peers have been removed from the blacklist\n";
|
||||
}elseif($cmd == 'resync-accounts'){
|
||||
// resyncs the balance on all accounts
|
||||
$db->run("UPDATE peers SET blacklisted=0, fails=0, stuckfail=0");
|
||||
echo "All the peers have been removed from the blacklist\n";
|
||||
} elseif ($cmd == 'resync-accounts') {
|
||||
// resyncs the balance on all accounts
|
||||
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
|
||||
$r=$db->run("SELECT * FROM accounts");
|
||||
foreach($r as $x){
|
||||
$r=$db->run("SELECT * FROM accounts");
|
||||
foreach ($r as $x) {
|
||||
$alias=$x['alias'];
|
||||
if(empty($alias)) $alias="A";
|
||||
$rec=$db->single("SELECT SUM(val) FROM transactions WHERE (dst=:id or dst=:alias) AND (height<80000 OR (version!=100 AND version!=103)) and version<111",[":id"=>$x['id'], ":alias"=>$alias]);
|
||||
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0",[":pub"=>$x['public_key']]);
|
||||
if($spent==false) $spent=0;
|
||||
$balance=round(($rec-$spent),8);
|
||||
if($x['balance']!=$balance){
|
||||
echo "rec: $rec, spent: $spent, bal: $x[balance], should be: $balance - $x[id] $x[public_key]\n";
|
||||
if(trim($argv[2])!="check") {
|
||||
$db->run("UPDATE accounts SET balance=:bal WHERE id=:id",[":id"=>$x['id'], ":bal"=>$balance]);
|
||||
}
|
||||
if (empty($alias)) {
|
||||
$alias="A";
|
||||
}
|
||||
}
|
||||
$db->exec("UNLOCK TABLES");
|
||||
echo "All done";
|
||||
|
||||
$rec=$db->single("SELECT SUM(val) FROM transactions WHERE (dst=:id or dst=:alias) AND (height<80000 OR (version!=100 AND version!=103)) and version<111", [":id"=>$x['id'], ":alias"=>$alias]);
|
||||
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0", [":pub"=>$x['public_key']]);
|
||||
if ($spent==false) {
|
||||
$spent=0;
|
||||
}
|
||||
$balance=round(($rec-$spent), 8);
|
||||
if ($x['balance']!=$balance) {
|
||||
echo "rec: $rec, spent: $spent, bal: $x[balance], should be: $balance - $x[id] $x[public_key]\n";
|
||||
if (trim($argv[2])!="check") {
|
||||
$db->run("UPDATE accounts SET balance=:bal WHERE id=:id", [":id"=>$x['id'], ":bal"=>$balance]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->exec("UNLOCK TABLES");
|
||||
echo "All done";
|
||||
} elseif ($cmd=="compare-blocks") {
|
||||
$block=new Block();
|
||||
|
||||
$current=$block->current();
|
||||
$peer=trim($argv[2]);
|
||||
$limit=intval($argv[3]);
|
||||
if($limit==0) $limit=5000;
|
||||
for($i=$current['height']-$limit;$i<=$current['height'];$i++){
|
||||
$data=peer_post($peer."/peer.php?q=getBlock",["height" => $i]);
|
||||
if($data==false) {
|
||||
continue;
|
||||
}
|
||||
$our=$block->export(false,$i);
|
||||
if($data!=$our) {
|
||||
echo "Failed block -> $i\n";
|
||||
if($argv[4]=="dump"){
|
||||
echo "\n\n ---- Internal ----\n\n";
|
||||
var_dump($our);
|
||||
echo "\n\n ---- External ----\n\n";
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($cmd=='compare-accounts'){
|
||||
$peer=trim($argv[2]);
|
||||
$r=$db->run("SELECT id,balance FROM accounts");
|
||||
foreach($r as $x){
|
||||
$data=peer_post($peer."/api.php?q=getBalance",["account" => $x['id']]);
|
||||
if($data==false) {
|
||||
continue;
|
||||
}
|
||||
if($data!=$x['balance']) {
|
||||
echo "$x[id]\t\t$x[balance]\t$data\n";
|
||||
}
|
||||
}
|
||||
} elseif ($cmd=='masternode-hash'){
|
||||
$res=$db->run("SELECT * FROM masternode ORDER by public_key ASC");
|
||||
$block=new Block();
|
||||
$current=$block->current();
|
||||
echo "Height:\t\t$current[height]\n";
|
||||
echo "Hash:\t\t".md5(json_encode($res))."\n\n";
|
||||
|
||||
} else {
|
||||
echo "Invalid command\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user