Update files to use class constructor parentheses
This commit is contained in:
8
api.php
8
api.php
@@ -276,7 +276,7 @@ if ($q == "getAddress") {
|
|||||||
* @apiSuccess {string} private_key Private key
|
* @apiSuccess {string} private_key Private key
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$res = $acc->generate_account();
|
$res = $acc->generate_account();
|
||||||
api_echo($res);
|
api_echo($res);
|
||||||
} elseif ($q == "currentBlock") {
|
} elseif ($q == "currentBlock") {
|
||||||
@@ -391,10 +391,10 @@ if ($q == "getAddress") {
|
|||||||
api_err("Hard fork in progress. Please retry the transaction later!"); //10800
|
api_err("Hard fork in progress. Please retry the transaction later!"); //10800
|
||||||
}
|
}
|
||||||
|
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
|
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
|
|
||||||
$dst = san($data['dst']);
|
$dst = san($data['dst']);
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ class Account
|
|||||||
public function get_transactions($id, $limit = 100)
|
public function get_transactions($id, $limit = 100)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$public_key = $this->public_key($id);
|
$public_key = $this->public_key($id);
|
||||||
$limit = intval($limit);
|
$limit = intval($limit);
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class Block
|
|||||||
public function add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon)
|
public function add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
|
|
||||||
$generator = $acc->get_address($public_key);
|
$generator = $acc->get_address($public_key);
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ class Block
|
|||||||
_log("Invalid block argon - $data[argon]");
|
_log("Invalid block argon - $data[argon]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
// generator's public key must be valid
|
// generator's public key must be valid
|
||||||
|
|
||||||
if (!$acc->valid_key($data['public_key'])) {
|
if (!$acc->valid_key($data['public_key'])) {
|
||||||
@@ -274,12 +274,12 @@ class Block
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the mempool transactions
|
// get the mempool transactions
|
||||||
$txn = new Transaction;
|
$txn = new Transaction();
|
||||||
$data = $txn->mempool($this->max_transactions());
|
$data = $txn->mempool($this->max_transactions());
|
||||||
|
|
||||||
|
|
||||||
$difficulty = $this->difficulty();
|
$difficulty = $this->difficulty();
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$generator = $acc->get_address($public_key);
|
$generator = $acc->get_address($public_key);
|
||||||
|
|
||||||
// always sort the transactions in the same way
|
// always sort the transactions in the same way
|
||||||
@@ -397,8 +397,8 @@ class Block
|
|||||||
if ($data === false) {
|
if ($data === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
// no transactions means all are valid
|
// no transactions means all are valid
|
||||||
if (count($data) == 0) {
|
if (count($data) == 0) {
|
||||||
return true;
|
return true;
|
||||||
@@ -503,7 +503,7 @@ class Block
|
|||||||
$height = 2;
|
$height = 2;
|
||||||
}
|
}
|
||||||
global $db;
|
global $db;
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
|
|
||||||
$r = $db->run("SELECT * FROM blocks WHERE height>=:height ORDER by height DESC", [":height" => $height]);
|
$r = $db->run("SELECT * FROM blocks WHERE height>=:height ORDER by height DESC", [":height" => $height]);
|
||||||
|
|
||||||
@@ -538,7 +538,7 @@ class Block
|
|||||||
{
|
{
|
||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
|
|
||||||
$x = $db->row("SELECT * FROM blocks WHERE id=:id", [":id" => $id]);
|
$x = $db->row("SELECT * FROM blocks WHERE id=:id", [":id" => $id]);
|
||||||
|
|
||||||
@@ -599,7 +599,7 @@ class Block
|
|||||||
}
|
}
|
||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
if (!empty($height)) {
|
if (!empty($height)) {
|
||||||
$block = $db->row("SELECT * FROM blocks WHERE height=:height", [":height" => $height]);
|
$block = $db->row("SELECT * FROM blocks WHERE height=:height", [":height" => $height]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ $_config['db_connect']="mysql:host=localhost;dbname=ENTER-DB-NAME";
|
|||||||
$_config['db_user']="ENTER-DB-USER";
|
$_config['db_user']="ENTER-DB-USER";
|
||||||
$_config['db_pass']="ENTER-DB-PASS";
|
$_config['db_pass']="ENTER-DB-PASS";
|
||||||
|
|
||||||
// Maximum number of connected peers
|
// Maximum number of connected peers
|
||||||
$_config['max_peers']=30;
|
$_config['max_peers']=30;
|
||||||
// Testnet, used for development
|
// Testnet, used for development
|
||||||
$_config['testnet']=false;
|
$_config['testnet']=false;
|
||||||
@@ -36,5 +36,3 @@ $_config['sanity_rebroadcast_locals']=true;
|
|||||||
$_config['enable_logging']=false;
|
$_config['enable_logging']=false;
|
||||||
// log file, should not be publicly viewable
|
// log file, should not be publicly viewable
|
||||||
$_config['log_file']="/var/log/aro.log";
|
$_config['log_file']="/var/log/aro.log";
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Transaction
|
|||||||
public function reverse($block)
|
public function reverse($block)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$r = $db->run("SELECT * FROM transactions WHERE block=:block", [":block" => $block]);
|
$r = $db->run("SELECT * FROM transactions WHERE block=:block", [":block" => $block]);
|
||||||
foreach ($r as $x) {
|
foreach ($r as $x) {
|
||||||
if (empty($x['src'])) {
|
if (empty($x['src'])) {
|
||||||
@@ -40,7 +40,7 @@ class Transaction
|
|||||||
public function clean_mempool()
|
public function clean_mempool()
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$height = $current['height'];
|
$height = $current['height'];
|
||||||
$limit = $height - 1000;
|
$limit = $height - 1000;
|
||||||
@@ -51,7 +51,7 @@ class Transaction
|
|||||||
public function mempool($max)
|
public function mempool($max)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$height = $current['height'] + 1;
|
$height = $current['height'] + 1;
|
||||||
// only get the transactions that are not locked with a future height
|
// only get the transactions that are not locked with a future height
|
||||||
@@ -64,15 +64,16 @@ class Transaction
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
$balance = [];
|
$balance = [];
|
||||||
foreach ($r as $x) {
|
foreach ($r as $x) {
|
||||||
$trans = ["id" => $x['id'],
|
$trans = [
|
||||||
"dst" => $x['dst'],
|
"id" => $x['id'],
|
||||||
"val" => $x['val'],
|
"dst" => $x['dst'],
|
||||||
"fee" => $x['fee'],
|
"val" => $x['val'],
|
||||||
"signature" => $x['signature'],
|
"fee" => $x['fee'],
|
||||||
"message" => $x['message'],
|
"signature" => $x['signature'],
|
||||||
"version" => $x['version'],
|
"message" => $x['message'],
|
||||||
"date" => $x['date'],
|
"version" => $x['version'],
|
||||||
"public_key" => $x['public_key'],
|
"date" => $x['date'],
|
||||||
|
"public_key" => $x['public_key'],
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($i >= $max) {
|
if ($i >= $max) {
|
||||||
@@ -122,22 +123,23 @@ class Transaction
|
|||||||
public function add_mempool($x, $peer = "")
|
public function add_mempool($x, $peer = "")
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$height = $current['height'];
|
$height = $current['height'];
|
||||||
$x['id'] = san($x['id']);
|
$x['id'] = san($x['id']);
|
||||||
$bind = [":peer" => $peer,
|
$bind = [
|
||||||
":id" => $x['id'],
|
":peer" => $peer,
|
||||||
"public_key" => $x['public_key'],
|
":id" => $x['id'],
|
||||||
":height" => $height,
|
"public_key" => $x['public_key'],
|
||||||
":src" => $x['src'],
|
":height" => $height,
|
||||||
":dst" => $x['dst'],
|
":src" => $x['src'],
|
||||||
":val" => $x['val'],
|
":dst" => $x['dst'],
|
||||||
":fee" => $x['fee'],
|
":val" => $x['val'],
|
||||||
":signature" => $x['signature'],
|
":fee" => $x['fee'],
|
||||||
":version" => $x['version'],
|
":signature" => $x['signature'],
|
||||||
":date" => $x['date'],
|
":version" => $x['version'],
|
||||||
":message" => $x['message'],
|
":date" => $x['date'],
|
||||||
|
":message" => $x['message'],
|
||||||
];
|
];
|
||||||
$db->run(
|
$db->run(
|
||||||
"INSERT into mempool SET peer=:peer, id=:id, public_key=:public_key, height=:height, src=:src, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
"INSERT into mempool SET peer=:peer, id=:id, public_key=:public_key, height=:height, src=:src, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
||||||
@@ -150,21 +152,22 @@ class Transaction
|
|||||||
public function add($block, $height, $x)
|
public function add($block, $height, $x)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$acc->add($x['public_key'], $block);
|
$acc->add($x['public_key'], $block);
|
||||||
$acc->add_id($x['dst'], $block);
|
$acc->add_id($x['dst'], $block);
|
||||||
$x['id'] = san($x['id']);
|
$x['id'] = san($x['id']);
|
||||||
$bind = [":id" => $x['id'],
|
$bind = [
|
||||||
":public_key" => $x['public_key'],
|
":id" => $x['id'],
|
||||||
":height" => $height,
|
":public_key" => $x['public_key'],
|
||||||
":block" => $block,
|
":height" => $height,
|
||||||
":dst" => $x['dst'],
|
":block" => $block,
|
||||||
":val" => $x['val'],
|
":dst" => $x['dst'],
|
||||||
":fee" => $x['fee'],
|
":val" => $x['val'],
|
||||||
":signature" => $x['signature'],
|
":fee" => $x['fee'],
|
||||||
":version" => $x['version'],
|
":signature" => $x['signature'],
|
||||||
":date" => $x['date'],
|
":version" => $x['version'],
|
||||||
":message" => $x['message'],
|
":date" => $x['date'],
|
||||||
|
":message" => $x['message'],
|
||||||
];
|
];
|
||||||
$res = $db->run(
|
$res = $db->run(
|
||||||
"INSERT into transactions SET id=:id, public_key=:public_key, block=:block, height=:height, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
"INSERT into transactions SET id=:id, public_key=:public_key, block=:block, height=:height, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
||||||
@@ -198,11 +201,11 @@ class Transaction
|
|||||||
{
|
{
|
||||||
// if no specific block, use current
|
// if no specific block, use current
|
||||||
if ($height === 0) {
|
if ($height === 0) {
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$height = $current['height'];
|
$height = $current['height'];
|
||||||
}
|
}
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
||||||
|
|
||||||
// the value must be >=0
|
// the value must be >=0
|
||||||
@@ -309,8 +312,8 @@ class Transaction
|
|||||||
public function get_transaction($id)
|
public function get_transaction($id)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
|
|
||||||
$x = $db->row("SELECT * FROM transactions WHERE id=:id", [":id" => $id]);
|
$x = $db->row("SELECT * FROM transactions WHERE id=:id", [":id" => $id]);
|
||||||
@@ -318,17 +321,18 @@ class Transaction
|
|||||||
if (!$x) {
|
if (!$x) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$trans = ["block" => $x['block'],
|
$trans = [
|
||||||
"height" => $x['height'],
|
"block" => $x['block'],
|
||||||
"id" => $x['id'],
|
"height" => $x['height'],
|
||||||
"dst" => $x['dst'],
|
"id" => $x['id'],
|
||||||
"val" => $x['val'],
|
"dst" => $x['dst'],
|
||||||
"fee" => $x['fee'],
|
"val" => $x['val'],
|
||||||
"signature" => $x['signature'],
|
"fee" => $x['fee'],
|
||||||
"message" => $x['message'],
|
"signature" => $x['signature'],
|
||||||
"version" => $x['version'],
|
"message" => $x['message'],
|
||||||
"date" => $x['date'],
|
"version" => $x['version'],
|
||||||
"public_key" => $x['public_key'],
|
"date" => $x['date'],
|
||||||
|
"public_key" => $x['public_key'],
|
||||||
];
|
];
|
||||||
$trans['src'] = $acc->get_address($x['public_key']);
|
$trans['src'] = $acc->get_address($x['public_key']);
|
||||||
$trans['confirmations'] = $current['height'] - $x['height'];
|
$trans['confirmations'] = $current['height'] - $x['height'];
|
||||||
@@ -352,9 +356,9 @@ class Transaction
|
|||||||
public function get_transactions($height = "", $id = "")
|
public function get_transactions($height = "", $id = "")
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$block = new Block;
|
$block = new Block();
|
||||||
$current = $block->current();
|
$current = $block->current();
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$height = san($height);
|
$height = san($height);
|
||||||
$id = san($id);
|
$id = san($id);
|
||||||
if (empty($id) && empty($height)) {
|
if (empty($id) && empty($height)) {
|
||||||
@@ -367,17 +371,18 @@ class Transaction
|
|||||||
}
|
}
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach ($r as $x) {
|
foreach ($r as $x) {
|
||||||
$trans = ["block" => $x['block'],
|
$trans = [
|
||||||
"height" => $x['height'],
|
"block" => $x['block'],
|
||||||
"id" => $x['id'],
|
"height" => $x['height'],
|
||||||
"dst" => $x['dst'],
|
"id" => $x['id'],
|
||||||
"val" => $x['val'],
|
"dst" => $x['dst'],
|
||||||
"fee" => $x['fee'],
|
"val" => $x['val'],
|
||||||
"signature" => $x['signature'],
|
"fee" => $x['fee'],
|
||||||
"message" => $x['message'],
|
"signature" => $x['signature'],
|
||||||
"version" => $x['version'],
|
"message" => $x['message'],
|
||||||
"date" => $x['date'],
|
"version" => $x['version'],
|
||||||
"public_key" => $x['public_key'],
|
"date" => $x['date'],
|
||||||
|
"public_key" => $x['public_key'],
|
||||||
];
|
];
|
||||||
$trans['src'] = $acc->get_address($x['public_key']);
|
$trans['src'] = $acc->get_address($x['public_key']);
|
||||||
$trans['confirmations'] = $current['height'] - $x['height'];
|
$trans['confirmations'] = $current['height'] - $x['height'];
|
||||||
@@ -407,17 +412,18 @@ class Transaction
|
|||||||
if (!$x) {
|
if (!$x) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$trans = ["block" => $x['block'],
|
$trans = [
|
||||||
"height" => $x['height'],
|
"block" => $x['block'],
|
||||||
"id" => $x['id'],
|
"height" => $x['height'],
|
||||||
"dst" => $x['dst'],
|
"id" => $x['id'],
|
||||||
"val" => $x['val'],
|
"dst" => $x['dst'],
|
||||||
"fee" => $x['fee'],
|
"val" => $x['val'],
|
||||||
"signature" => $x['signature'],
|
"fee" => $x['fee'],
|
||||||
"message" => $x['message'],
|
"signature" => $x['signature'],
|
||||||
"version" => $x['version'],
|
"message" => $x['message'],
|
||||||
"date" => $x['date'],
|
"version" => $x['version'],
|
||||||
"public_key" => $x['public_key'],
|
"date" => $x['date'],
|
||||||
|
"public_key" => $x['public_key'],
|
||||||
];
|
];
|
||||||
$trans['src'] = $x['src'];
|
$trans['src'] = $x['src'];
|
||||||
|
|
||||||
|
|||||||
33
peer.php
33
peer.php
@@ -49,8 +49,10 @@ if ($q == "peer") {
|
|||||||
}
|
}
|
||||||
$hostname = san_host($hostname);
|
$hostname = san_host($hostname);
|
||||||
// if it's already peered, only repeer on request
|
// if it's already peered, only repeer on request
|
||||||
$res = $db->single("SELECT COUNT(1) FROM peers WHERE hostname=:hostname AND ip=:ip",
|
$res = $db->single(
|
||||||
[":hostname" => $hostname, ":ip" => $ip]);
|
"SELECT COUNT(1) FROM peers WHERE hostname=:hostname AND ip=:ip",
|
||||||
|
[":hostname" => $hostname, ":ip" => $ip]
|
||||||
|
);
|
||||||
if ($res == 1) {
|
if ($res == 1) {
|
||||||
if ($data['repeer'] == 1) {
|
if ($data['repeer'] == 1) {
|
||||||
$res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]);
|
$res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]);
|
||||||
@@ -68,8 +70,10 @@ if ($q == "peer") {
|
|||||||
if ($res < $_config['max_peers']) {
|
if ($res < $_config['max_peers']) {
|
||||||
$reserve = 0;
|
$reserve = 0;
|
||||||
}
|
}
|
||||||
$db->run("INSERT ignore INTO peers SET hostname=:hostname, reserve=:reserve, ping=UNIX_TIMESTAMP(), ip=:ip ON DUPLICATE KEY UPDATE hostname=:hostname2",
|
$db->run(
|
||||||
[":ip" => $ip, ":hostname2" => $hostname, ":hostname" => $hostname, ":reserve" => $reserve]);
|
"INSERT ignore INTO peers SET hostname=:hostname, reserve=:reserve, ping=UNIX_TIMESTAMP(), ip=:ip ON DUPLICATE KEY UPDATE hostname=:hostname2",
|
||||||
|
[":ip" => $ip, ":hostname2" => $hostname, ":hostname" => $hostname, ":reserve" => $reserve]
|
||||||
|
);
|
||||||
// re-peer to make sure the peer is valid
|
// re-peer to make sure the peer is valid
|
||||||
$res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]);
|
$res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]);
|
||||||
if ($res !== false) {
|
if ($res !== false) {
|
||||||
@@ -118,7 +122,7 @@ if ($q == "peer") {
|
|||||||
if ($res != 0) {
|
if ($res != 0) {
|
||||||
api_err("The transaction is already in a block");
|
api_err("The transaction is already in a block");
|
||||||
}
|
}
|
||||||
$acc = new Account;
|
$acc = new Account();
|
||||||
$src = $acc->get_address($data['public_key']);
|
$src = $acc->get_address($data['public_key']);
|
||||||
// make sure the sender has enough balance
|
// make sure the sender has enough balance
|
||||||
$balance = $db->single("SELECT balance FROM accounts WHERE id=:id", [":id" => $src]);
|
$balance = $db->single("SELECT balance FROM accounts WHERE id=:id", [":id" => $src]);
|
||||||
@@ -214,8 +218,17 @@ if ($q == "peer") {
|
|||||||
}
|
}
|
||||||
$b = $data;
|
$b = $data;
|
||||||
// add the block to the blockchain
|
// add the block to the blockchain
|
||||||
$res = $block->add($b['height'], $b['public_key'], $b['nonce'], $b['data'], $b['date'], $b['signature'],
|
$res = $block->add(
|
||||||
$b['difficulty'], $b['reward_signature'], $b['argon']);
|
$b['height'],
|
||||||
|
$b['public_key'],
|
||||||
|
$b['nonce'],
|
||||||
|
$b['data'],
|
||||||
|
$b['date'],
|
||||||
|
$b['signature'],
|
||||||
|
$b['difficulty'],
|
||||||
|
$b['reward_signature'],
|
||||||
|
$b['argon']
|
||||||
|
);
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
_log('['.$ip."] invalid block data - $data[height]");
|
_log('['.$ip."] invalid block data - $data[height]");
|
||||||
@@ -245,8 +258,10 @@ elseif ($q == "getBlock") {
|
|||||||
|
|
||||||
$height = intval($data['height']);
|
$height = intval($data['height']);
|
||||||
|
|
||||||
$r = $db->run("SELECT id,height FROM blocks WHERE height>=:height ORDER by height ASC LIMIT 100",
|
$r = $db->run(
|
||||||
[":height" => $height]);
|
"SELECT id,height FROM blocks WHERE height>=:height ORDER by height ASC LIMIT 100",
|
||||||
|
[":height" => $height]
|
||||||
|
);
|
||||||
foreach ($r as $x) {
|
foreach ($r as $x) {
|
||||||
$blocks[$x['height']] = $block->export($x['id']);
|
$blocks[$x['height']] = $block->export($x['id']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ if ($type == "block") {
|
|||||||
}
|
}
|
||||||
// broadcast a transaction to some peers
|
// broadcast a transaction to some peers
|
||||||
if ($type == "transaction") {
|
if ($type == "transaction") {
|
||||||
$trx = new Transaction;
|
$trx = new Transaction();
|
||||||
// get the transaction data
|
// get the transaction data
|
||||||
$data = $trx->export($id);
|
$data = $trx->export($id);
|
||||||
|
|
||||||
|
|||||||
104
sanity.php
104
sanity.php
@@ -79,8 +79,10 @@ $microsanity = false;
|
|||||||
if ($arg == "microsanity" && !empty($arg2)) {
|
if ($arg == "microsanity" && !empty($arg2)) {
|
||||||
do {
|
do {
|
||||||
// the microsanity runs only against 1 specific peer
|
// the microsanity runs only against 1 specific peer
|
||||||
$x = $db->row("SELECT id,hostname FROM peers WHERE reserve=0 AND blacklisted<UNIX_TIMESTAMP() AND ip=:ip",
|
$x = $db->row(
|
||||||
[":ip" => $arg2]);
|
"SELECT id,hostname FROM peers WHERE reserve=0 AND blacklisted<UNIX_TIMESTAMP() AND ip=:ip",
|
||||||
|
[":ip" => $arg2]
|
||||||
|
);
|
||||||
|
|
||||||
if (!$x) {
|
if (!$x) {
|
||||||
echo "Invalid node - $arg2\n";
|
echo "Invalid node - $arg2\n";
|
||||||
@@ -118,8 +120,14 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
|||||||
// make sure the block is valid
|
// make sure the block is valid
|
||||||
$prev = $block->get($current['height'] - 1);
|
$prev = $block->get($current['height'] - 1);
|
||||||
$public = $acc->public_key($data['generator']);
|
$public = $acc->public_key($data['generator']);
|
||||||
if (!$block->mine($public, $data['nonce'], $data['argon'], $block->difficulty($current['height'] - 1),
|
if (!$block->mine(
|
||||||
$prev['id'], $prev['height'])) {
|
$public,
|
||||||
|
$data['nonce'],
|
||||||
|
$data['argon'],
|
||||||
|
$block->difficulty($current['height'] - 1),
|
||||||
|
$prev['id'],
|
||||||
|
$prev['height']
|
||||||
|
)) {
|
||||||
echo "Invalid prev-block\n";
|
echo "Invalid prev-block\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -134,8 +142,17 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
|||||||
// add the new block
|
// add the new block
|
||||||
echo "Starting to sync last block from $x[hostname]\n";
|
echo "Starting to sync last block from $x[hostname]\n";
|
||||||
$b = $data;
|
$b = $data;
|
||||||
$res = $block->add($b['height'], $b['public_key'], $b['nonce'], $b['data'], $b['date'], $b['signature'],
|
$res = $block->add(
|
||||||
$b['difficulty'], $b['reward_signature'], $b['argon']);
|
$b['height'],
|
||||||
|
$b['public_key'],
|
||||||
|
$b['nonce'],
|
||||||
|
$b['data'],
|
||||||
|
$b['date'],
|
||||||
|
$b['signature'],
|
||||||
|
$b['difficulty'],
|
||||||
|
$b['reward_signature'],
|
||||||
|
$b['argon']
|
||||||
|
);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
_log("Block add: could not add block - $b[id] - $b[height]");
|
_log("Block add: could not add block - $b[id] - $b[height]");
|
||||||
|
|
||||||
@@ -234,8 +251,10 @@ foreach ($r as $x) {
|
|||||||
if ($data === false) {
|
if ($data === false) {
|
||||||
_log("Peer $x[hostname] unresponsive");
|
_log("Peer $x[hostname] unresponsive");
|
||||||
// if the peer is unresponsive, mark it as failed and blacklist it for a while
|
// if the peer is unresponsive, mark it as failed and blacklist it for a while
|
||||||
$db->run("UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*3600) WHERE id=:id",
|
$db->run(
|
||||||
[":id" => $x['id']]);
|
"UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*3600) WHERE id=:id",
|
||||||
|
[":id" => $x['id']]
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,8 +282,10 @@ foreach ($r as $x) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// make sure there's no peer in db with this ip or hostname
|
// make sure there's no peer in db with this ip or hostname
|
||||||
if (!$db->single("SELECT COUNT(1) FROM peers WHERE ip=:ip or hostname=:hostname",
|
if (!$db->single(
|
||||||
[":ip" => $peer['ip'], ":hostname" => $peer['hostname']])) {
|
"SELECT COUNT(1) FROM peers WHERE ip=:ip or hostname=:hostname",
|
||||||
|
[":ip" => $peer['ip'], ":hostname" => $peer['hostname']]
|
||||||
|
)) {
|
||||||
$i++;
|
$i++;
|
||||||
// check a max_test_peers number of peers from each peer
|
// check a max_test_peers number of peers from each peer
|
||||||
if ($i > $_config['max_test_peers']) {
|
if ($i > $_config['max_test_peers']) {
|
||||||
@@ -295,8 +316,10 @@ foreach ($r as $x) {
|
|||||||
$data['height'] = san($data['height']);
|
$data['height'] = san($data['height']);
|
||||||
|
|
||||||
if ($data['height'] < $current['height'] - 500) {
|
if ($data['height'] < $current['height'] - 500) {
|
||||||
$db->run("UPDATE peers SET stuckfail=stuckfail+1, blacklisted=UNIX_TIMESTAMP()+7200 WHERE id=:id",
|
$db->run(
|
||||||
[":id" => $x['id']]);
|
"UPDATE peers SET stuckfail=stuckfail+1, blacklisted=UNIX_TIMESTAMP()+7200 WHERE id=:id",
|
||||||
|
[":id" => $x['id']]
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if ($x['stuckfail'] > 0) {
|
if ($x['stuckfail'] > 0) {
|
||||||
@@ -418,8 +441,14 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
|||||||
}
|
}
|
||||||
// check if the block mining data is correct
|
// check if the block mining data is correct
|
||||||
for ($i = $last_good + 1; $i <= $largest_height; $i++) {
|
for ($i = $last_good + 1; $i <= $largest_height; $i++) {
|
||||||
if (!$block->mine($cblock[$i]['public_key'], $cblock[$i]['nonce'], $cblock[$i]['argon'],
|
if (!$block->mine(
|
||||||
$cblock[$i]['difficulty'], $cblock[$i - 1]['id'], $cblock[$i - 1]['height'])) {
|
$cblock[$i]['public_key'],
|
||||||
|
$cblock[$i]['nonce'],
|
||||||
|
$cblock[$i]['argon'],
|
||||||
|
$cblock[$i]['difficulty'],
|
||||||
|
$cblock[$i - 1]['id'],
|
||||||
|
$cblock[$i - 1]['height']
|
||||||
|
)) {
|
||||||
$invalid = true;
|
$invalid = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -454,8 +483,17 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
|||||||
$good_peer = false;
|
$good_peer = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$res = $block->add($b['height'], $b['public_key'], $b['nonce'], $b['data'], $b['date'], $b['signature'],
|
$res = $block->add(
|
||||||
$b['difficulty'], $b['reward_signature'], $b['argon']);
|
$b['height'],
|
||||||
|
$b['public_key'],
|
||||||
|
$b['nonce'],
|
||||||
|
$b['data'],
|
||||||
|
$b['date'],
|
||||||
|
$b['signature'],
|
||||||
|
$b['difficulty'],
|
||||||
|
$b['reward_signature'],
|
||||||
|
$b['argon']
|
||||||
|
);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
_log("Block add: could not add block - $b[id] - $b[height]");
|
_log("Block add: could not add block - $b[id] - $b[height]");
|
||||||
$good_peer = false;
|
$good_peer = false;
|
||||||
@@ -483,21 +521,27 @@ $db->run("DELETE FROM `mempool` WHERE `date` < UNIX_TIMESTAMP()-(3600*24*14)");
|
|||||||
|
|
||||||
//rebroadcasting local transactions
|
//rebroadcasting local transactions
|
||||||
if ($_config['sanity_rebroadcast_locals'] == true) {
|
if ($_config['sanity_rebroadcast_locals'] == true) {
|
||||||
$r = $db->run("SELECT id FROM mempool WHERE height>=:current and peer='local' order by `height` asc LIMIT 20",
|
$r = $db->run(
|
||||||
[":current" => $current['height']]);
|
"SELECT id FROM mempool WHERE height>=:current and peer='local' order by `height` asc LIMIT 20",
|
||||||
|
[":current" => $current['height']]
|
||||||
|
);
|
||||||
_log("Rebroadcasting local transactions - ".count($r));
|
_log("Rebroadcasting local transactions - ".count($r));
|
||||||
foreach ($r as $x) {
|
foreach ($r as $x) {
|
||||||
$x['id'] = san($x['id']);
|
$x['id'] = san($x['id']);
|
||||||
system("php propagate.php transaction $x[id] > /dev/null 2>&1 &");
|
system("php propagate.php transaction $x[id] > /dev/null 2>&1 &");
|
||||||
$db->run("UPDATE mempool SET height=:current WHERE id=:id",
|
$db->run(
|
||||||
[":id" => $x['id'], ":current" => $current['height']]);
|
"UPDATE mempool SET height=:current WHERE id=:id",
|
||||||
|
[":id" => $x['id'], ":current" => $current['height']]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//rebroadcasting transactions
|
//rebroadcasting transactions
|
||||||
$forgotten = $current['height'] - $_config['sanity_rebroadcast_height'];
|
$forgotten = $current['height'] - $_config['sanity_rebroadcast_height'];
|
||||||
$r = $db->run("SELECT id FROM mempool WHERE height<:forgotten ORDER by val DESC LIMIT 10",
|
$r = $db->run(
|
||||||
[":forgotten" => $forgotten]);
|
"SELECT id FROM mempool WHERE height<:forgotten ORDER by val DESC LIMIT 10",
|
||||||
|
[":forgotten" => $forgotten]
|
||||||
|
);
|
||||||
|
|
||||||
_log("Rebroadcasting external transactions - ".count($r));
|
_log("Rebroadcasting external transactions - ".count($r));
|
||||||
|
|
||||||
@@ -520,8 +564,10 @@ foreach ($r as $x) {
|
|||||||
$url = $x['hostname']."/peer.php?q=";
|
$url = $x['hostname']."/peer.php?q=";
|
||||||
$data = peer_post($url."ping", [], 5);
|
$data = peer_post($url."ping", [], 5);
|
||||||
if ($data === false) {
|
if ($data === false) {
|
||||||
$db->run("UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*60) WHERE id=:id",
|
$db->run(
|
||||||
[":id" => $x['id']]);
|
"UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*60) WHERE id=:id",
|
||||||
|
[":id" => $x['id']]
|
||||||
|
);
|
||||||
_log("Random reserve peer test $x[hostname] -> FAILED");
|
_log("Random reserve peer test $x[hostname] -> FAILED");
|
||||||
} else {
|
} else {
|
||||||
_log("Random reserve peer test $x[hostname] -> OK");
|
_log("Random reserve peer test $x[hostname] -> OK");
|
||||||
@@ -564,8 +610,14 @@ if ($_config['sanity_recheck_blocks'] > 0) {
|
|||||||
|
|
||||||
$key = $db->single("SELECT public_key FROM accounts WHERE id=:id", [":id" => $data['generator']]);
|
$key = $db->single("SELECT public_key FROM accounts WHERE id=:id", [":id" => $data['generator']]);
|
||||||
|
|
||||||
if (!$block->mine($key, $data['nonce'], $data['argon'], $data['difficulty'], $blocks[$i - 1]['id'],
|
if (!$block->mine(
|
||||||
$blocks[$i - 1]['height'])) {
|
$key,
|
||||||
|
$data['nonce'],
|
||||||
|
$data['argon'],
|
||||||
|
$data['difficulty'],
|
||||||
|
$blocks[$i - 1]['id'],
|
||||||
|
$blocks[$i - 1]['height']
|
||||||
|
)) {
|
||||||
$db->run("UPDATE config SET val=1 WHERE cfg='sanity_sync'");
|
$db->run("UPDATE config SET val=1 WHERE cfg='sanity_sync'");
|
||||||
_log("Invalid block detected. Deleting everything after $data[height] - $data[id]");
|
_log("Invalid block detected. Deleting everything after $data[height] - $data[id]");
|
||||||
sleep(10);
|
sleep(10);
|
||||||
|
|||||||
Reference in New Issue
Block a user