From 7cec6d01c112f9e0e86a9a08fa68f87afae3f586 Mon Sep 17 00:00:00 2001 From: Savinda Senevirathne Date: Wed, 17 Mar 2021 12:17:50 +0530 Subject: [PATCH] Changes for unstable consensus. (#272) * Return empty hash when set or vector is empty in crypto. * Changing diff --git a/src/crypto.cpp b/src/crypto.cpp index 165db650..b1156f47 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -161,6 +161,11 @@ namespace crypto std::string hash; hash.resize(BLAKE3_OUT_LEN); + if (sw_vect.empty()) + { + return hash; + } + // Init stream hashing. blake3_hasher hasher; blake3_hasher_init(&hasher); @@ -183,6 +188,11 @@ namespace crypto std::string hash; hash.resize(BLAKE3_OUT_LEN); + if (sw_set.empty()) + { + return hash; + } + // Init stream hashing. blake3_hasher hasher; blake3_hasher_init(&hasher); diff --git a/src/p2p/p2p.hpp b/src/p2p/p2p.hpp index e425534c..f13b1cb3 100644 --- a/src/p2p/p2p.hpp +++ b/src/p2p/p2p.hpp @@ -45,7 +45,7 @@ namespace p2p bool operator<(const sequence_hash &seq_hash) const { - return seq_no < seq_hash.seq_no || hash < seq_hash.hash; + return (seq_no == seq_hash.seq_no) ? hash < seq_hash.hash : seq_no < seq_hash.seq_no; } const std::string to_string() diff --git a/test/vm-cluster/cluster.sh b/test/vm-cluster/cluster.sh index 233fe195..269a9f89 100755 --- a/test/vm-cluster/cluster.sh +++ b/test/vm-cluster/cluster.sh @@ -36,9 +36,9 @@ else fi contconfig=$(jq -r ".contracts[] | select(.name == \"${CONTRACT}\") | .config" $conf) -if [ "$contconfig" = "" ]; then +if [ "$contconfig" = "" ] || [ "$contconfig" = "{}" ]; then # Apply default config. - contconfig="{user: {'port': 8080 }, mesh:{ 'port': 22860}, 'contract': {'roundtime': 2000 }, 'log':{'loglevel': 'dbg', 'loggers':['console','file']}}" + contconfig="{\"user\": {\"port\": 8080}, \"mesh\":{ \"port\": 22860}, \"contract\": {\"roundtime\": 2000 }, \"log\":{\"loglevel\": \"dbg\", \"loggers\":[\"console\",\"file\"]}}" fi vmpass=$(jq -r '.vmpass' $conf) @@ -237,11 +237,12 @@ if [ $mode = "ssl" ]; then fi if [ $mode = "lcl" ]; then + command="$contdir/lcl.sh" for (( i=0; i<$vmcount; i++ )) do vmaddr=${vmaddrs[i]} let nodeid=$i+1 - echo "node$nodeid:" $(sshpass -p $vmpass ssh $vmuser@$vmaddr ls -v $contdir/hist | tail -1) & + echo "node"$nodeid":" $(sshpass -p $vmpass ssh $vmuser@$vmaddr $command) & done wait exit 0 diff --git a/test/vm-cluster/setup-hp.sh b/test/vm-cluster/setup-hp.sh index 45fa5531..00a919ca 100755 --- a/test/vm-cluster/setup-hp.sh +++ b/test/vm-cluster/setup-hp.sh @@ -13,6 +13,10 @@ then sudo swapon /swapfile fi +# Getting updates if any +echo "Checking for updates..." +sudo apt-get update + if [ -x "$(command -v node)" ]; then echo "NodeJs already installed." else @@ -33,6 +37,14 @@ else sudo cp $basedir/hpfiles/bin/fusermount3 /usr/local/bin/ fi +if [ -x "$(command -v sqlite3)" ]; then + echo "SQLite already installed." +else + echo "Installing SQLite..." + sudo apt-get install -y sqlite3 libsqlite3-dev +fi + + # Remove existing contract dir. sudo rm -r $contdir > /dev/null 2>&1 @@ -70,6 +82,11 @@ if [ $mode = "new" ] || [ $mode = "reconfig" ]; then echo "sudo kill \$($contdir/getpid.sh hpcore hpfs hpws)" > $contdir/kill.sh sudo chmod +x $contdir/kill.sh + # Create lcl.sh script + echo "max_shard_no=\$(ls -v $contdir/ledger_fs/seed/primary/ | tail -2 | head -1)" > $contdir/lcl.sh + echo "echo \"select seq_no, ledger_hash from ledger order by seq_no DESC limit 1;\" | sqlite3 $contdir/ledger_fs/seed/primary/\$max_shard_no/ledger.sqlite" >> $contdir/lcl.sh + sudo chmod +x $contdir/lcl.sh + # Configure .screenrc pushd $contdir > /dev/null 2>&1 echo "chdir $contdir" >> hp.screenrc