From 0d2bd3b419ed271a6e183fc20eef497eb3f88e61 Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 17 Sep 2020 21:13:17 +0300 Subject: [PATCH 1/3] Update functions.inc.php --- include/functions.inc.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/functions.inc.php b/include/functions.inc.php index 4c3ceb9..a87f807 100755 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -250,6 +250,11 @@ function ec_verify($data, $signature, $key) } return false; } +// verify the validity of an url +function isValidURL($url) +{ + return preg_match('|^(ht)?(f)?tp(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); +} // POST data to an URL (usualy peer). The data is an array, json encoded with is sent as $_POST['data'] function peer_post($url, $data = [], $timeout = 60, $debug = false) @@ -258,6 +263,9 @@ function peer_post($url, $data = [], $timeout = 60, $debug = false) if ($debug) { echo "\nPeer post: $url\n"; } + if (!isValidURL($url)) { + return false; + } $postdata = http_build_query( [ 'data' => json_encode($data), From a5356346e68cf9a1635e14bf23d865c237a7944f Mon Sep 17 00:00:00 2001 From: arionum <34399752+arionum@users.noreply.github.com> Date: Thu, 17 Sep 2020 21:15:10 +0300 Subject: [PATCH 2/3] Update init.inc.php moving to alpha 6 --- 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 3352f64..9cf9756 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -1,6 +1,6 @@ Date: Tue, 10 Nov 2020 15:30:48 +0200 Subject: [PATCH 3/3] Update sanity.php sync fixes --- sanity.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sanity.php b/sanity.php index 7320e34..567fa5c 100755 --- a/sanity.php +++ b/sanity.php @@ -239,7 +239,9 @@ $most_common = ""; $most_common_size = 0; $most_common_height = 0; $total_active_peers = 0; - +$largest_most_common = ""; +$largest_most_common_size = 0; +$largest_most_common_height = 0; // checking peers @@ -427,6 +429,11 @@ foreach ($r as $x) { $most_common_size = $blocks_count[$data['id']]; $most_common_height = $data['height']; } + if ($blocks_count[$data['id']] > $largest_most_common_size && $data['height'] > $current['height']) { + $largest_most_common = $data['id']; + $largest_most_common_size = $blocks_count[$data['id']]; + $largest_most_common_height = $data['height']; + } // set the largest height block if ($data['height'] > $largest_height) { $largest_height = $data['height']; @@ -462,6 +469,9 @@ echo "Most common block size: $most_common_size\n"; echo "Most common height: $most_common_height\n\n"; echo "Longest chain height: $largest_height\n"; echo "Longest chain size: $largest_size\n\n"; +echo "Larger Most common: $largest_most_common\n"; +echo "Larger Most common block size: $largest_most_common_size\n"; +echo "Larger Most common height: $largest_most_common_height\n\n"; echo "Total size: $total_active_peers\n\n"; echo "Current block: $current[height]\n"; @@ -480,11 +490,18 @@ if($largest_height-$most_common_height>100&&$largest_size==1&&$current['id']==$l } // if there's a single node with over 100 blocks ahead on a single peer, use the most common block -if($largest_height-$most_common_height>100&&$largest_size==1){ - _log("Longest chain is way ahead, using most common block"); - $largest_height=$most_common_height; - $largest_size=$most_common_size; - $largest_height_block=$most_common; +if($largest_height-$most_common_height>100 && $largest_size==1){ + if($current['id']==$most_common && $largest_most_common_size>3){ + _log("Longest chain is way ahead, using largest most common block"); + $largest_height=$largest_most_common_height; + $largest_size=$largest_most_common_size; + $largest_height_block=$largest_most_common; + } else { + _log("Longest chain is way ahead, using most common block"); + $largest_height=$most_common_height; + $largest_size=$most_common_size; + $largest_height_block=$most_common; + } } @@ -600,6 +617,10 @@ if ($current['height'] < $largest_height && $largest_height > 1) { } // if current still doesn't match the data, something went wrong if ($data['id'] != $current['id']) { + if($largest_size==1){ + //blacklisting the peer if it's the largest height on a broken blockchain + $db->run("UPDATE peers SET blacklisted=UNIX_TIMESTAMP()+1800 WHERE hostname=:host LIMIT 1",[':host'=>$host]); + } continue; } // start syncing all blocks