Files
hpcore/cluster-create.sh
Ravidu Lashan 1238e96423 State synchronization logic (#67)
* Added flat buffer state message request

* Added state vote

* Added state to ledger history and did necessary changes

* Completed receiveing state request

* State read/write helpers.

* Added new fbs schema

* Added more state_store helper methods.

* Started processing response

* Fixed compile errors

* Added get file length.

* Handled state content response

* Statefs code cleanup and fixes.

* Completed response handling

* Completed changes in handling state response

* State sync integration fixes.

* Fuse mount waiting logic.

* Fixed state syncing issues

* state sync fixes

* fixes

* State sync fixes.

* Fixed fs entries retrieval issues.

* changed desync logic

* Added directory helper functions.

* Handled return statemetns from statefs

* Fixed state folder deletion.

* handled errors from statefs

* Working for small files

* Got state sync working.

* Removed cout.

* Fixed catering for stae issue

* Fixed block hash map flatbuf issue.

* Added expected hash

* Added helpers for expected hash comparison.

* Improved state req/resp awaiting logic.

* Fixes.

* Fixes.

* Block request ordering fix.

* Removed couts

* Closed non-closed file descriptors

* Minor fixes.

* Cluster create script changes.

* Fixed reset time off issue.
2019-12-13 10:20:41 +05:30

119 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# Generate contract sub-directories within this script directory for the given no. of cluster nodes.
# Usage (to generate 8-node cluster): ./cluster-create.sh 8
# Validate the node count arg.
if [ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null; then
echo "Generating a Hot Pocket cluster of ${1} node(s)..."
else
echo "Error: Please provide number of nodes."
exit 1
fi
# Delete and recreate 'hpcluster' directory.
rm -rf hpcluster > /dev/null 2>&1
mkdir hpcluster
clusterloc="./hpcluster"
pushd $clusterloc > /dev/null 2>&1
# Create contract directories for all nodes in the cluster.
ncount=$1
for (( i=0; i<$ncount; i++ ))
do
let n=$i+1
let peerport=22860+$n
let pubport=8080+$n
# Create contract dir named "node<i>"
../build/hpcore new "node${n}" > /dev/null 2>&1
pushd ./node$n/cfg > /dev/null 2>&1
# Use NodeJs to manipulate HP json configuration.
mv hp.cfg tmp.json # nodejs needs file extension to be .json
# Collect each node pubkey and peer ports for later processing.
pubkeys[i]=$(node -p "require('./tmp.json').pubkeyhex")
# During hosting we use docker virtual dns instead of IP address.
# So each node is reachable via 'node<id>' name.
peers[i]="node${n}:${peerport}"
# Update contract config.
node -p "JSON.stringify({...require('./tmp.json'), \
binary: '/usr/local/bin/node', \
binargs: './bin/contract.js', \
peerport: ${peerport}, \
pubport: ${pubport}, \
roundtime: 1000, \
loglevel: 'debug', \
loggers:['console', 'file'] \
}, null, 2)" > hp.cfg
rm tmp.json
# Generate ssl certs
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout tlskey.pem -out tlscert.pem \
-subj "/C=AU/ST=ST/L=L/O=O/OU=OU/CN=localhost/emailAddress=hpnode${n}@example" > /dev/null 2>&1
popd > /dev/null 2>&1
# Copy the contract executable.
mkdir ./node$n/bin
cp ../examples/echocontract/contract.js ./node$n/bin/contract.js
done
# Function to generate JSON array string while skiping a given index.
function joinarr {
arrname=$1[@]
arr=("${!arrname}")
skip=$2
j=0
str="["
for (( i=0; i<$ncount; i++ ))
do
let prevlast=$ncount-2
if [ "$i" != "$skip" ]
then
str="$str'${arr[i]}'"
if [ $j -lt $prevlast ]
then
str="$str,"
fi
let j=j+1
fi
done
str="$str]"
echo $str
}
# Loop through all nodes hp.cfg and inject peer and unl lists (skip self node).
for (( j=0; j<$ncount; j++ ))
do
let n=$j+1
mypeers=$(joinarr peers $j)
myunl=$(joinarr pubkeys $j)
pushd ./node$n/cfg > /dev/null 2>&1
mv hp.cfg tmp.json # nodejs needs file extension to be .json
node -p "JSON.stringify({...require('./tmp.json'),peers:${mypeers},unl:${myunl}}, null, 2)" > hp.cfg
rm tmp.json
popd > /dev/null 2>&1
done
popd > /dev/null 2>&1
# Create docker virtual network named 'hpnet'
# All nodes will communicate with each other via this network.
docker network create --driver bridge hpnet > /dev/null 2>&1
echo "Cluster generated at ${clusterloc}"
echo "Use \"./cluster-start.sh <nodeid>\" to run each node."
exit 0