Last active
July 3, 2020 18:51
-
-
Save CrackerHax/2f1c287c0b54487e2f8519749ae03738 to your computer and use it in GitHub Desktop.
Bash script for running multiple Fusenet validator nodes on a single server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
START_NODE_NUM=1 | |
END_NODE_NUM=3 | |
ENV_FILE=".env" | |
HOMEPATH="/home/fuse" | |
function getAndUpdateBlockNumbers { | |
#CURL the api calls and extract the current blocks | |
FUSEBLOCK=$((`curl -s --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST $HOME_RPC_URL | grep -o "\w*0x\w*"`)) | |
ETHBLOCK=$((`curl -s --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST $FOREIGN_RPC_URL:8545 | grep -o "\w*0x\w*"`)) | |
echo "Current fuse block: $FUSEBLOCK" | |
echo "Current eth block: $ETHBLOCK" | |
if [[ "$ETHBLOCK" == 0 ]]; then | |
echo "Could not pull mainnet block please check your foreign RPC config" | |
exit 1 | |
fi | |
if [[ "$FUSEBLOCK" == 0 ]]; then | |
echo "Could not pull fuse block please check your fuse RPC config" | |
exit 1 | |
fi | |
#Open the env file and replace the exsisting block numbers with the new ones. | |
#NOTE: this assumes that the env file only contains one line for HOME/FOREIGN_START_BLOCK | |
sed -i "s/^HOME_START_BLOCK.*/HOME_START_BLOCK=${FUSEBLOCK}/" "$ENV_FILE" | |
sed -i "s/^FOREIGN_START_BLOCK.*/FOREIGN_START_BLOCK=${ETHBLOCK}/" "$ENV_FILE" | |
echo -e "\nUpdating block numbers in $ENV_FILE" | |
} | |
for (( c=$START_NODE_NUM; c<=$END_NODE_NUM; c++ )) | |
do | |
ENV_FILE="$HOMEPATH/nodes/fuse-validator$c/.env" | |
export $(grep -v '^#' "$ENV_FILE" | xargs) | |
echo "updating block numbers" | |
getAndUpdateBlockNumbers | |
echo "done updating block numbers" | |
cd "$HOMEPATH/nodes/fuse-validator$c/" | |
echo "running quickstart" | |
/bin/bash "./quickstart.sh" | |
echo "$ENV_FILE" | |
echo "/bin/bash fuse-validator$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Validator node directories should be named /home/WhateverYourUsernameis/fuse-validatorX
e.g.:
/home/myname/fuse-validator1
/home/myname/fuse-validator2
/home/myname/fuse-validator3
START_NODE_NUM must be your first node (1 in this example)
END_NODE_NUM must be your last node (3 in this example)
HOMEPATH should be the path to the main directory where all validators are kept