From c4b6cce000520961489e24aa8968e310a7299e7a Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:17:02 +0300 Subject: [PATCH 01/19] cleanup of php notices --- sanity.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sanity.php b/sanity.php index 4d63012..c269c95 100755 --- a/sanity.php +++ b/sanity.php @@ -44,15 +44,15 @@ // set the new sanity lock flock($sanity_lock, LOCK_EX); -$arg = trim($argv[1]); -$arg2 = trim($argv[2]); +$arg = trim($argv[1] ?? ""); +$arg2 = trim($argv[2] ?? ""); echo "Sleeping for 3 seconds\n"; // sleep for 3 seconds to make sure there's a delay between starting the sanity and other processes if ($arg != "microsanity") { sleep(3); } -if ($argv[1]=="dev") { +if ($arg=="dev") { error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); ini_set("display_errors", "on"); } @@ -305,7 +305,8 @@ } // contact all the active peers - $i = 0; +$i = 0; +$largest_height=0; foreach ($r as $x) { _log("Contacting peer $x[hostname]"); $url = $x['hostname']."/peer.php?q="; @@ -327,7 +328,7 @@ $peer['ip'] = san_ip($peer['ip']); $pid = md5($peer['hostname']); // do not peer if we are already peered - if ($peered[$pid] == 1) { + if (isset($peered[$pid]) && $peered[$pid] == 1) { continue; } $peered[$pid] = 1; @@ -404,6 +405,7 @@ // add the hostname and block relationship to an array $block_peers[$data['id']][] = $x['hostname']; // count the number of peers with this block id + if(!isset($blocks_count[$data['id']])) { $blocks_count[$data['id']]=0; } $blocks_count[$data['id']]++; // keep block data for this block id $blocks[$data['id']] = $data; From acef2b87696e67bea773e491c564d67f4326948b Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:33:23 +0300 Subject: [PATCH 02/19] php notices cleaup --- include/init.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/init.inc.php b/include/init.inc.php index 6c89e73..aad331c 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -60,7 +60,7 @@ } // nothing is allowed while in maintenance -if ($_config['maintenance'] == 1) { +if (isset($_config['maintenance']) && $_config['maintenance'] == 1) { api_err("under-maintenance"); } @@ -94,9 +94,10 @@ } // current hostname -$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".san_host($_SERVER['HTTP_HOST']); +$http_host=san_host($_SERVER['HTTP_HOST'] ?? ""); +$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".$http_host; // set the hostname to the current one -if ($hostname != $_config['hostname'] && $_SERVER['HTTP_HOST'] != "localhost" && $_SERVER['HTTP_HOST'] != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { +if ($hostname != $_config['hostname'] && $http_host != "localhost" && $http_host != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { $db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]); $_config['hostname'] = $hostname; } From 8c5b08967799b775e937f9009fc0f784d7bf87f5 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:45:16 +0300 Subject: [PATCH 03/19] php notices cleanup --- propagate.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/propagate.php b/propagate.php index b8f0138..0f77457 100755 --- a/propagate.php +++ b/propagate.php @@ -27,18 +27,18 @@ require_once __DIR__.'/include/init.inc.php'; $block = new Block(); -$type = san($argv[1]); -$id = san($argv[2]); +$type = san($argv[1] ?? ""); +$id = san($argv[2] ?? ""); $debug = false; $linear = false; // if debug mode, all data is printed to console, no background processes -if (trim($argv[5]) == 'debug') { +if (trim($argv[5] ?? "") == 'debug') { $debug = true; } -if (trim($argv[5]) == 'linear') { +if (trim($argv[5] ?? "") == 'linear') { $linear = true; } -$peer = san(trim($argv[3])); +$peer = san(trim($argv[3] ?? "")); // broadcasting a block to all peers @@ -111,10 +111,10 @@ echo "Block sent to $hostname:\n"; $response = peer_post($hostname."/peer.php?q=submitBlock", $data, 60, $debug); _log("Propagating block to $hostname - [result: $response] $data[height] - $data[id]",2); - if ($response == "block-ok") { - echo "Block $i accepted. Exiting.\n"; + if (is_string($response) && $response == "block-ok") { + echo "Block $data[height] accepted. Exiting.\n"; exit; - } elseif ($response['request'] == "microsync") { + } elseif (isset($response['request']) && $response['request'] == "microsync") { // the peer requested us to send more blocks, as it's behind echo "Microsync request\n"; $height = intval($response['height']); @@ -142,7 +142,7 @@ } echo "Block\t$i\t accepted\n"; } - } elseif ($response == "reverse-microsanity") { + } elseif (is_string($response) && $response == "reverse-microsanity") { // the peer informe us that we should run a microsanity echo "Running microsanity\n"; $ip = trim($argv[4]); From 61ba0909dc8716ea4f8245162e198f8cad1263ae Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:49:26 +0300 Subject: [PATCH 04/19] php notices cleanup --- include/functions.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index a87f807..191c57a 100755 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -3,6 +3,7 @@ // simple santization function to accept only alphanumeric characters function san($a, $b = "") { + if(empty($a)) return ""; $a = preg_replace("/[^a-zA-Z0-9".$b."]/", "", $a); return $a; @@ -10,12 +11,14 @@ function san($a, $b = "") function san_ip($a) { + if(empty($a)) return ""; $a = preg_replace("/[^a-fA-F0-9\[\]\.\:]/", "", $a); return $a; } function san_host($a) { + if(empty($a)) return ""; $a = preg_replace("/[^a-zA-Z0-9\.\-\:\/]/", "", $a); return $a; } @@ -285,14 +288,14 @@ function peer_post($url, $data = [], $timeout = 60, $debug = false) $context = stream_context_create($opts); - $result = file_get_contents($url, false, $context); + $result = @file_get_contents($url, false, $context); if ($debug) { echo "\nPeer response: $result\n"; } $res = json_decode($result, true); // the function will return false if something goes wrong - if ($res['status'] != "ok" || $res['coin'] != $_config['coin']) { + if ($res==false || is_null($res) || $res['status'] != "ok" || $res['coin'] != $_config['coin']) { return false; } return $res['data']; From 3ff05e2399198289433a1bde46e7f5c67b23879e Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:55:50 +0300 Subject: [PATCH 05/19] Update peer.php --- peer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peer.php b/peer.php index 818528b..7880cb4 100755 --- a/peer.php +++ b/peer.php @@ -71,7 +71,7 @@ [":hostname" => $hostname, ":ip" => $ip] ); if ($res == 1) { - if ($data['repeer'] == 1) { + if (isset(data['repeer']) && $data['repeer'] == 1) { $res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]); if ($res !== false) { api_echo("re-peer-ok"); From adfebbce611a58c0f31ab77a640b74c0bac37459 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:59:13 +0300 Subject: [PATCH 06/19] Update api.php --- api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.php b/api.php index 7ac69bf..a2ea17b 100755 --- a/api.php +++ b/api.php @@ -452,15 +452,15 @@ - $private_key = san($data['private_key']); + $private_key = san($data['private_key'] ?? ""); if (!$acc->valid_key($private_key)) { api_err("Invalid private key"); } - $signature = san($data['signature']); + $signature = san($data['signature'] ?? ""); if (!$acc->valid_key($signature)) { api_err("Invalid signature"); } - $date = $data['date'] + 0; + $date = ($data['date'] ?? 0) + 0; if ($date == 0) { $date = time(); From b2125770b32dd8637fd01a17c20f09bc0d42860c Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:02:42 +0300 Subject: [PATCH 07/19] Update transaction.inc.php --- include/transaction.inc.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/transaction.inc.php b/include/transaction.inc.php index ebd60df..bbc26fa 100755 --- a/include/transaction.inc.php +++ b/include/transaction.inc.php @@ -307,7 +307,9 @@ public function mempool($max) _log("$x[id] - Transaction Check Failed"); continue; } - + if(!isset($balance[$x['src']])){ + $balance[$x['src']]=0; + } $balance[$x['src']] += $x['val'] + $x['fee']; if ($db->single("SELECT COUNT(1) FROM transactions WHERE id=:id", [":id" => $x['id']]) > 0) { _log("$x[id] - Duplicate transaction"); From 77af1a22acd9d1c3b1d56f52bd545c4cd86165f6 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:04:45 +0300 Subject: [PATCH 08/19] php notices cleanup --- include/block.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/block.inc.php b/include/block.inc.php index 779c960..d1a207e 100755 --- a/include/block.inc.php +++ b/include/block.inc.php @@ -1242,6 +1242,9 @@ public function parse_block($block, $height, $data, $test = true, $bootstrapping } // prepare total balance + if(!isset($balance[$x['src']])){ + $balance[$x['src']]=0; + } $balance[$x['src']] += $x['val'] + $x['fee']; // check if the transaction is already on the blockchain From 55831545fb12e17656a6c4e19c3929f94a88ba70 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:45:18 +0300 Subject: [PATCH 09/19] typo --- peer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peer.php b/peer.php index 7880cb4..88ab855 100755 --- a/peer.php +++ b/peer.php @@ -71,7 +71,7 @@ [":hostname" => $hostname, ":ip" => $ip] ); if ($res == 1) { - if (isset(data['repeer']) && $data['repeer'] == 1) { + if (isset($data['repeer']) && $data['repeer'] == 1) { $res = peer_post($hostname."/peer.php?q=peer", ["hostname" => $_config['hostname']]); if ($res !== false) { api_echo("re-peer-ok"); From 65f109d31e0758ecce887fc54636c05e32887d80 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:00:52 +0300 Subject: [PATCH 10/19] Update propagate.php --- propagate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/propagate.php b/propagate.php index 0f77457..8f1014a 100755 --- a/propagate.php +++ b/propagate.php @@ -110,7 +110,7 @@ // send the block as POST to the peer echo "Block sent to $hostname:\n"; $response = peer_post($hostname."/peer.php?q=submitBlock", $data, 60, $debug); - _log("Propagating block to $hostname - [result: $response] $data[height] - $data[id]",2); + _log("Propagating block to $hostname - $data[height] - $data[id]",2); if (is_string($response) && $response == "block-ok") { echo "Block $data[height] accepted. Exiting.\n"; exit; From e6afa848ffed5387889c8011890774f428a61b5a Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:05:51 +0300 Subject: [PATCH 11/19] cleaning php notices --- util.php | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/util.php b/util.php index 76e1a96..94862fc 100755 --- a/util.php +++ b/util.php @@ -30,7 +30,7 @@ } require_once __DIR__.'/include/init.inc.php'; -$cmd = trim($argv[1]); +$cmd = trim($argv[1] ?? ""); /** * @api {php util.php} clean Clean @@ -73,7 +73,7 @@ die("Sanity running. Wait for it to finish"); } touch("tmp/sanity-lock"); - $no = intval($argv[2]); + $no = intval($argv[2] ?? 0); $block = new Block(); $block->pop($no); unlink("tmp/sanity-lock"); @@ -124,7 +124,8 @@ elseif ($cmd == "peer") { - $res = peer_post($argv[2]."/peer.php?q=peer", ["hostname" => $_config['hostname']]); + $peer=trim($argv[2] ?? ""); + $res = peer_post($peer."/peer.php?q=peer", ["hostname" => $_config['hostname']]); if ($res !== false) { echo "Peering OK\n"; } else { @@ -188,8 +189,8 @@ * */ elseif ($cmd == "blocks") { - $height = intval($argv[2]); - $limit = intval($argv[3]); + $height = intval($argv[2] ?? 0); + $limit = intval($argv[3] ?? 100); if ($limit < 1) { $limit = 100; } @@ -286,7 +287,7 @@ * Peer removed */ elseif ($cmd == "delete-peer") { - $peer = trim($argv[2]); + $peer = trim($argv[2] ?? 0); if (empty($peer)) { die("Invalid peer"); } @@ -319,7 +320,7 @@ */ elseif ($cmd == "peers-block") { $only_diff = false; - if ($argv[2] == "diff") { + if (isset($argv[2]) && $argv[2] == "diff") { $current = $db->single("SELECT height FROM blocks ORDER by height DESC LIMIT 1"); $only_diff = true; } @@ -327,7 +328,7 @@ foreach ($r as $x) { $a = peer_post($x['hostname']."/peer.php?q=currentBlock", [], 5); $enc = base58_encode($x['hostname']); - if ($argv[2] == "debug") { + if (isset($argv[2]) && $argv[2] == "debug") { echo "$enc\t"; } if ($only_diff == false || $current != $a['height']) { @@ -350,7 +351,7 @@ */ elseif ($cmd == "balance") { - $id = san($argv[2]); + $id = san($argv[2] ?? ""); $res = $db->single( "SELECT balance FROM accounts WHERE id=:id OR public_key=:id2 LIMIT 1", [":id" => $id, ":id2" => $id] @@ -391,7 +392,7 @@ * } */ elseif ($cmd == "block") { - $id = san($argv[2]); + $id = san($argv[2] ?? ""); $res = $db->row("SELECT * FROM blocks WHERE id=:id OR height=:id2 LIMIT 1", [":id" => $id, ":id2" => $id]); var_dump($res); @@ -410,7 +411,7 @@ * The address is valid */ elseif ($cmd == "check-address") { - $dst = trim($argv[2]); + $dst = trim($argv[2] ?? ""); $acc = new Account(); if (!$acc->valid($dst)) { die("Invalid address"); @@ -438,7 +439,7 @@ */ elseif ($cmd == 'get-address') { - $public_key = trim($argv2); + $public_key = trim($argv[2] ?? ""); if (strlen($public_key) < 32) { die("Invalid public key"); } @@ -487,7 +488,7 @@ $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") { + if (trim($argv[2] ?? "")!="check") { $db->run("UPDATE accounts SET balance=:bal WHERE id=:id", [":id"=>$x['id'], ":bal"=>$balance]); } } @@ -499,8 +500,8 @@ $block=new Block(); $current=$block->current(); - $peer=trim($argv[2]); - $limit=intval($argv[3]); + $peer=trim($argv[2] ?? ""); + $limit=intval($argv[3] ?? 0); if ($limit==0) { $limit=5000; } @@ -512,7 +513,7 @@ $our=$block->export(false, $i); if ($data!=$our) { echo "Failed block -> $i\n"; - if ($argv[4]=="dump") { + if (isset($argv[4]) && $argv[4]=="dump") { echo "\n\n ---- Internal ----\n\n"; var_dump($our); echo "\n\n ---- External ----\n\n"; @@ -521,7 +522,7 @@ } } } elseif ($cmd=='compare-accounts') { - $peer=trim($argv[2]); + $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']]); @@ -547,12 +548,12 @@ } elseif ($cmd == "version") { echo "\n\n".VERSION."\n\n"; } elseif ($cmd == "sendblock") { - $peer=trim($argv[3]); + $peer=trim($argv[3] ?? ""); if (!filter_var($peer, FILTER_VALIDATE_URL)) { die("Invalid peer hostname"); } $peer = filter_var($peer, FILTER_SANITIZE_URL); - $height=intval($argv[2]); + $height=intval($argv[2] ?? ""); $block=new Block(); $data = $block->export("", $height); @@ -563,7 +564,7 @@ $response = peer_post($peer."/peer.php?q=submitBlock", $data, 60, true); var_dump($response); } elseif ($cmd == "recheck-external-blocks") { - $peer=trim($argv[2]); + $peer=trim($argv[2] ?? ""); if (!filter_var($peer, FILTER_VALIDATE_URL)) { die("Invalid peer hostname"); } @@ -572,7 +573,7 @@ $blocks = []; $block = new Block(); - $height=intval($argv[3]); + $height=intval($argv[3] ?? 0); $last=peer_post($peer."/peer.php?q=currentBlock"); From adc3fb48c4432668e769b871f2228515007bbd83 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:28:58 +0300 Subject: [PATCH 12/19] Update config-sample.inc.php --- include/config-sample.inc.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/config-sample.inc.php b/include/config-sample.inc.php index 5d0d397..ecc4f53 100755 --- a/include/config-sample.inc.php +++ b/include/config-sample.inc.php @@ -147,6 +147,9 @@ // Log verbosity (default 0, maximum 3) $_config['log_verbosity'] = 0; +// Log E_ALL php errors +$_config['log_php_errors'] = false; + /* |-------------------------------------------------------------------------- | Masternode Configuration @@ -159,4 +162,4 @@ // The public key for the masternode $_config['masternode_public_key'] = ''; $_config['masternode_voting_public_key'] = ''; -$_config['masternode_voting_private_key'] = ''; \ No newline at end of file +$_config['masternode_voting_private_key'] = ''; From 2ba66623b6265477520792bded18464a5957eed0 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:32:30 +0300 Subject: [PATCH 13/19] log php errors config --- include/init.inc.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/init.inc.php b/include/init.inc.php index aad331c..003e874 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -1,20 +1,23 @@ 1) { die("This application should only be run in the main directory /"); } - -require_once __DIR__.'/Exception.php'; require_once __DIR__.'/config.inc.php'; +if(isset($_config['log_php_errors']) && $_config['log_php_errors'] == true){ + error_reporting(E_ALL); +} else { + error_reporting(0); +} +require_once __DIR__.'/Exception.php'; + require_once __DIR__.'/db.inc.php'; require_once __DIR__.'/functions.inc.php'; require_once __DIR__.'/Blacklist.php'; From c5d8fcf5e1ed5f769a642f2416f34ca4167fd1f6 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:34:01 +0300 Subject: [PATCH 14/19] error reporting config --- sanity.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sanity.php b/sanity.php index c269c95..98ac51b 100755 --- a/sanity.php +++ b/sanity.php @@ -27,7 +27,7 @@ const SANITY_LOCK_PATH = __DIR__.'/tmp/sanity-lock'; set_time_limit(0); -error_reporting(0); + // make sure it's not accessible in the browser if (php_sapi_name() !== 'cli') { @@ -53,7 +53,6 @@ } if ($arg=="dev") { - error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); ini_set("display_errors", "on"); } From 8380804042d1513909ec7d2ec8fa98a2dfafd6d9 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 25 Jul 2024 01:54:47 +0300 Subject: [PATCH 15/19] fail if lock file can't be opened --- sanity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanity.php b/sanity.php index 98ac51b..acfa143 100755 --- a/sanity.php +++ b/sanity.php @@ -37,8 +37,8 @@ require_once __DIR__.'/include/init.inc.php'; // make sure there's only a single sanity process running at the same time -$sanity_lock=fopen(SANITY_LOCK_PATH,'w+'); -if(!flock($sanity_lock, LOCK_EX | LOCK_NB)){ +$sanity_lock=@fopen(SANITY_LOCK_PATH,'w+'); +if($sanity_lock==false || !flock($sanity_lock, LOCK_EX | LOCK_NB)){ die("Sanity lock in place".PHP_EOL); } // set the new sanity lock From a0c2badb71788da81008ac06affab7d3b7980362 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:02:10 +0300 Subject: [PATCH 16/19] fixed balance recheck on submittransaction --- peer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/peer.php b/peer.php index 88ab855..785e015 100755 --- a/peer.php +++ b/peer.php @@ -141,6 +141,8 @@ } $acc = new Account(); $src = $acc->get_address($data['public_key']); + $val = $data['val'] ?? 0; + $fee = $data['fee'] ?? 0; // make sure the sender has enough balance $balance = $db->single("SELECT balance FROM accounts WHERE id=:id", [":id" => $src]); if ($balance < $val + $fee) { From 79781154e7062a1e3a6f138e67b130d38c751814 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:14:47 +0300 Subject: [PATCH 17/19] catch exception if there are no transaction on db->rollback --- include/block.inc.php | 60 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/include/block.inc.php b/include/block.inc.php index d1a207e..a2ee6b0 100755 --- a/include/block.inc.php +++ b/include/block.inc.php @@ -180,7 +180,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif if ($res != 1) { // rollback and exit if it fails _log("Block DB insert failed"); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -190,7 +194,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif if ($res == false) { // rollback and exit if it fails _log("Reward DB insert failed"); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -222,7 +230,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif if ($res != 1) { // rollback and exit if it fails _log("Masternode Cold reward DB insert failed"); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -256,7 +268,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif if ($res != 1) { // rollback and exit if it fails _log("Masternode reward DB insert failed"); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -265,7 +281,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif // rollback and exit if it fails _log("Masternode log DB insert failed"); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -299,7 +319,11 @@ public function add($height, $public_key, $nonce, $data, $date, $signature, $dif // if any fails, rollback if ($res == false) { _log("Rollback block", 3); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } } else { _log("Commiting block", 3); $db->commit(); @@ -1349,7 +1373,11 @@ public function delete($height) $res = $trx->reverse($x['id']); if ($res === false) { _log("A transaction could not be reversed. Delete block failed."); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } // the blockchain has some flaw, we should resync from scratch $current = $this->current(); @@ -1375,7 +1403,11 @@ public function delete($height) $res = $db->run("DELETE FROM blocks WHERE id=:id", [":id" => $x['id']]); if ($res != 1) { _log("Delete block failed."); - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -1409,7 +1441,11 @@ public function delete_id($id) $res = $trx->reverse($x['id']); if ($res === false) { // rollback if you can't reverse the transactions - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } @@ -1417,7 +1453,11 @@ public function delete_id($id) $res = $db->run("DELETE FROM blocks WHERE id=:id", [":id" => $x['id']]); if ($res != 1) { //rollback if you can't delete the block - $db->rollback(); + try { + $db->rollback(); + } Catch (Exception $ex){ + // no transactions made + } $db->exec("UNLOCK TABLES"); return false; } From 3a2292001e8161f120dc67d9765a41abae224c99 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:23:26 +0300 Subject: [PATCH 18/19] initialize hostname config var --- include/init.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/init.inc.php b/include/init.inc.php index 003e874..dd9ea1f 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -100,6 +100,9 @@ $http_host=san_host($_SERVER['HTTP_HOST'] ?? ""); $hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".$http_host; // set the hostname to the current one +if(!isset($_config['hostname'])){ + $_config['hostname']=""; +} if ($hostname != $_config['hostname'] && $http_host != "localhost" && $http_host != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { $db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]); $_config['hostname'] = $hostname; From e5633c2835ef2669c759a189d582f204d960adf6 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:57:24 +0300 Subject: [PATCH 19/19] Update init.inc.php --- include/init.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/init.inc.php b/include/init.inc.php index dd9ea1f..f572fa5 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -103,7 +103,7 @@ if(!isset($_config['hostname'])){ $_config['hostname']=""; } -if ($hostname != $_config['hostname'] && $http_host != "localhost" && $http_host != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { +if ($hostname != $_config['hostname'] && $http_host != "localhost" && $http_host != "127.0.0.1" && $http_host != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { $db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]); $_config['hostname'] = $hostname; }