Skip to content

Commit

Permalink
Merge pull request #1316 from ainblockchain/feature/platfowner/feature
Browse files Browse the repository at this point in the history
Add incremental blockchain deploy scripts for onprem machines
  • Loading branch information
platfowner authored Sep 4, 2024
2 parents b71b22a + 525839b commit 6c22202
Show file tree
Hide file tree
Showing 12 changed files with 785 additions and 61 deletions.
2 changes: 1 addition & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ app.get('/metrics', async (req, res, next) => {
.end();
});

// Used in wait_until_node_sync_gcp.sh
// Used in wait_until_node_sync.sh
app.get('/last_block_number', (req, res, next) => {
const beginTime = Date.now();
const result = node.bc.lastBlockNumber();
Expand Down
5 changes: 2 additions & 3 deletions deploy_blockchain_genesis_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function inject_account() {

# deploy files
FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync.sh stop_local_blockchain.sh"

TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan"
NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan"
Expand Down Expand Up @@ -446,9 +446,8 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g
printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n"
printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n"

printf "\n"
START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $GCP_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}"
printf "START_NODE_CMD=$START_NODE_CMD\n"
printf "\nSTART_NODE_CMD=$START_NODE_CMD\n"
eval $START_NODE_CMD
sleep 5
inject_account "$node_index"
Expand Down
53 changes: 23 additions & 30 deletions deploy_blockchain_genesis_onprem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [[ $# -lt 4 ]] || [[ $# -gt 10 ]]; then
printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 0 0 --keystore --keep-code\n"
printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 -1 -1 --setup --keystore --no-keep-code\n"
printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 0 0 --setup --keystore --no-keep-code\n"
printf "Note: <Parent Node Index Begin> = -1 is for tracker\n"
#printf "Note: <Parent Node Index Begin> = -1 is for tracker\n"
printf "Note: <Parent Node Index End> is inclusive\n"
printf "\n"
exit
Expand All @@ -29,8 +29,6 @@ if [[ ! $2 =~ $number_re ]] ; then
printf "Invalid <# of Shards> argument: $2\n"
exit
fi
NUM_SHARDS=$2
printf "NUM_SHARDS=$NUM_SHARDS\n"
PARENT_NODE_INDEX_BEGIN=$3
printf "PARENT_NODE_INDEX_BEGIN=$PARENT_NODE_INDEX_BEGIN\n"
PARENT_NODE_INDEX_END=$4
Expand Down Expand Up @@ -221,7 +219,7 @@ function inject_account() {

# deploy files
#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_onprem.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_onprem.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_onprem.sh start_node_incremental_onprem.sh wait_until_node_sync.sh stop_local_blockchain.sh"

printf "###############################################################################\n"
printf "# Deploying parent blockchain #\n"
Expand All @@ -244,11 +242,12 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do
NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}"
NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}"
printf "\n"
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"

printf "\n* >> Deploying files for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -rv $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/
printf "\n\n* >> Deploying files for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
printf "FILES_FOR_NODE=${FILES_FOR_NODE}\n\n"

echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh $NODE_TARGET_ADDR "sudo -S rm -rf ~/ain-blockchain; mkdir ~/ain-blockchain; chmod -R 777 ~/ain-blockchain"
sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -r $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/
done
fi
fi
Expand All @@ -269,11 +268,10 @@ if [[ $SETUP_OPTION = "--setup" ]]; then
for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do
NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}"
NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}"
printf "\n"
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"

printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh"
printf "\n\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"

echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh"
done
fi
fi
Expand All @@ -294,20 +292,19 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do
NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}"
NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}"
printf "\n"
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"

printf "\n* >> Installing node modules for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines"
printf "\n\n* >> Installing node modules for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"

sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines"
done
fi
fi

if [[ $KILL_OPTION = "--skip-kill" ]]; then
printf "\nSkipping process kill...\n"
printf "\n\nSkipping process kill...\n"
else
# kill any processes still alive
printf "\nKilling tracker / blockchain node jobs...\n"
printf "\n\nKilling tracker / blockchain node jobs...\n"

# # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1
# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then
Expand All @@ -323,11 +320,10 @@ else
for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do
NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}"
NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}"
printf "\n"
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"

printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n"
echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo -S killall node"

echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo -S pkill -f client/${SEASON}-ain-blockchain-index.js"
done
fi
fi
Expand All @@ -337,7 +333,7 @@ if [[ $KILL_OPTION = "--kill-only" ]]; then
exit
fi

printf "\nStarting blockchain servers...\n\n"
printf "\n\nStarting blockchain servers...\n\n"
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain"
else
Expand Down Expand Up @@ -370,19 +366,17 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g
for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do
NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}"
NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}"
printf "\n"
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"

if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then
printf "\n* >> Removing old data for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
printf "\n\n* >> Removing old data for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"

CHAINS_DIR=/home/${SEASON}/ain_blockchain_data/chains
SNAPSHOTS_DIR=/home/${SEASON}/ain_blockchain_data/snapshots
LOGS_DIR=/home/${SEASON}/ain_blockchain_data/logs
echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo -S rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR"
echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo -S rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR"
fi

printf "\n* >> Starting parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"
printf "\n\n* >> Starting parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"

if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then
JSON_RPC_OPTION="--json-rpc"
Expand Down Expand Up @@ -411,9 +405,8 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g
printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n"
printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n"

printf "\n"
START_NODE_CMD="ssh -v ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'"
printf "START_NODE_CMD=$START_NODE_CMD\n"
START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'"
printf "\nSTART_NODE_CMD=$START_NODE_CMD\n"
eval "echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}"
sleep 5
inject_account "$node_index"
Expand Down
18 changes: 4 additions & 14 deletions deploy_blockchain_incremental_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then
fi

FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync.sh stop_local_blockchain.sh"

NUM_SHARD_NODES=3

Expand Down Expand Up @@ -326,7 +326,7 @@ function deploy_node() {

# 5. Wait until node is synced
printf "\n\n<<< Waiting until node $node_index is synced >>>\n\n"
WAIT_CMD="gcloud compute ssh $node_target_addr --command 'cd \$(find /home/ain-blockchain* -maxdepth 0 -type d); . wait_until_node_sync_gcp.sh' --project $PROJECT_ID --zone $node_zone"
WAIT_CMD="gcloud compute ssh $node_target_addr --command 'cd \$(find /home/ain-blockchain* -maxdepth 0 -type d); . wait_until_node_sync.sh' --project $PROJECT_ID --zone $node_zone"
printf "WAIT_CMD=$WAIT_CMD\n\n"
eval $WAIT_CMD
}
Expand Down Expand Up @@ -355,18 +355,8 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
else
GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)"
fi
if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then
# restart after removing chains, snapshots, and log files (but keep the keys)
CHAINS_DIR=/home/ain_blockchain_data/chains
SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots
LOGS_DIR=/home/ain_blockchain_data/logs
START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_incremental_gcp.sh"
START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_incremental_gcp.sh"
else
# restart with existing chains, snapshots, and log files
START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_incremental_gcp.sh"
START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_incremental_gcp.sh"
fi
START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_incremental_gcp.sh"
START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_incremental_gcp.sh"

# Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1
if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then
Expand Down
Loading

0 comments on commit 6c22202

Please sign in to comment.