From 2a4daf1792ba994852ee81d4c8edcd8f4b25c57d Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 5 Jul 2024 13:56:42 +0900 Subject: [PATCH 01/46] Upgrade ain-util package version to v1.2.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c3043ce19..efb7e595f 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "tracker": "node ./tracker-server/index.js" }, "dependencies": { - "@ainblockchain/ain-util": "^1.1.9", + "@ainblockchain/ain-util": "^1.2.0", "@google-cloud/logging-bunyan": "^3.2.0", "@google-cloud/logging-winston": "^4.0.2", "JSONStream": "^1.3.5", diff --git a/yarn.lock b/yarn.lock index 663fbf777..63c8756db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@ainblockchain/ain-util@^1.1.9": - version "1.1.9" - resolved "https://registry.yarnpkg.com/@ainblockchain/ain-util/-/ain-util-1.1.9.tgz#4369547af354d84229c5b0f1fd4e93e8497d6227" - integrity sha512-u3q0h0zwWk+vzZ6VpBZiagVKJbNw/Dw4LVjBAhOvgPCx/E3jHHQCufIMDGqD4wjeBuHVtTAQyMTv7LRPSZFBGg== +"@ainblockchain/ain-util@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@ainblockchain/ain-util/-/ain-util-1.2.0.tgz#d2ac228c729cae9f87e8d43120ab0b4fab9de436" + integrity sha512-M0hjvyOSNurTVW1J5sW2zQoAqhry06OAInN3Mz9ARHde19rV2e23hob9laXQTayFUAYRQ5BZqITW9qtOL6HP7A== dependencies: bip39 "^3.0.4" bn.js "^4.11.8" From 92f3b4eb0332b7e6a4cbe0a521471da347f9d0b0 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 5 Jul 2024 13:57:48 +0900 Subject: [PATCH 02/46] Add some nonce examples in comments --- tools/transfer/sendTransferTx.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/transfer/sendTransferTx.js b/tools/transfer/sendTransferTx.js index 361fdd784..7110bc716 100644 --- a/tools/transfer/sendTransferTx.js +++ b/tools/transfer/sendTransferTx.js @@ -18,6 +18,8 @@ function buildTransferTxBody(fromAddr, toAddr, key, amount, timestamp) { gas_price: 500, timestamp, nonce: -1 +// nonce: -2 +// nonce: 0 } } From 4d9e070d9caecbc540e89ea8702af01dd645f9b4 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 5 Jul 2024 17:16:29 +0900 Subject: [PATCH 03/46] Upgrade ain-util package to v1.2.1 --- package.json | 2 +- tools/account/seedPhraseToAccounts.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index efb7e595f..2f7e4dbef 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "tracker": "node ./tracker-server/index.js" }, "dependencies": { - "@ainblockchain/ain-util": "^1.2.0", + "@ainblockchain/ain-util": "^1.2.1", "@google-cloud/logging-bunyan": "^3.2.0", "@google-cloud/logging-winston": "^4.0.2", "JSONStream": "^1.3.5", diff --git a/tools/account/seedPhraseToAccounts.js b/tools/account/seedPhraseToAccounts.js index c56c9028a..48b6927d0 100644 --- a/tools/account/seedPhraseToAccounts.js +++ b/tools/account/seedPhraseToAccounts.js @@ -12,7 +12,7 @@ async function seedPhraseToAccount(numAccounts) { hidden: true, }]); for (let i = 0; i < numAccounts; i++) { - const account = ainUtil.mnemonicToAccount(input.seedPhrase, i); + const account = ainUtil.mnemonicToAccount(input.seedPhrase, i, 'ETH'); console.log(`\nAccount #${i}`); console.log(account); } From 092ea072a09c07113eb6cae006357e04702d8663 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 5 Jul 2024 17:17:17 +0900 Subject: [PATCH 04/46] Add a note for nonce value to sendTranferTx.js --- tools/transfer/sendTransferTx.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/transfer/sendTransferTx.js b/tools/transfer/sendTransferTx.js index 7110bc716..48a37efe7 100644 --- a/tools/transfer/sendTransferTx.js +++ b/tools/transfer/sendTransferTx.js @@ -17,9 +17,10 @@ function buildTransferTxBody(fromAddr, toAddr, key, amount, timestamp) { }, gas_price: 500, timestamp, + // NOTE(platfowner): Nonce value can be changed manually for ordered or numbered transactions. nonce: -1 -// nonce: -2 -// nonce: 0 + // nonce: -2 + // nonce: N // 0, 1, 2, ... } } From a6b2fd99f7d548cba82623a0508e854587d816bb Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 23 Jul 2024 17:45:30 +0900 Subject: [PATCH 05/46] Add deploy_blockchain_genesis_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 528 ++++++++++++++++++++++++++++ 1 file changed, 528 insertions(+) create mode 100644 deploy_blockchain_genesis_onprem.sh diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh new file mode 100644 index 000000000..ec2bbf0a8 --- /dev/null +++ b/deploy_blockchain_genesis_onprem.sh @@ -0,0 +1,528 @@ +#!/bin/bash + +if [[ $# -lt 4 ]] || [[ $# -gt 10 ]]; then + printf "Usage: bash deploy_blockchain_genesis_onprem.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--kill-only|--skip-kill]\n" + printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 -1 4 --keystore --no-keep-code\n" + 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: = -1 is for tracker\n" + printf "Note: is inclusive\n" + printf "\n" + exit +fi +printf "\n[[[[[ deploy_blockchain_genesis_onprem.sh ]]]]]\n\n" + +if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then + SEASON="$1" + if [[ "$1" = 'mainnet' ]]; then + PROJECT_ID="mainnet-prod-ground" + elif [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]]; then + PROJECT_ID="testnet-prod-ground" + else + PROJECT_ID="testnet-$1-ground" + fi +else + printf "Invalid project/season argument: $1\n" + exit +fi +printf "SEASON=$SEASON\n" +printf "PROJECT_ID=$PROJECT_ID\n" + +GCP_USER="runner" +printf "GCP_USER=$GCP_USER\n" + +number_re='^[0-9]+$' +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 +printf "PARENT_NODE_INDEX_END=$PARENT_NODE_INDEX_END\n" +printf "\n" + + +function parse_options() { + local option="$1" + if [[ $option = '--setup' ]]; then + SETUP_OPTION="$option" + elif [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keystore' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--mnemonic' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--no-chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--kill-only' ]]; then + if [[ "$KILL_OPTION" ]]; then + printf "You cannot use both --skip-kill and --kill-only\n" + exit + fi + KILL_OPTION="$option" + elif [[ $option = '--skip-kill' ]]; then + if [[ "$KILL_OPTION" ]]; then + printf "You cannot use both --skip-kill and --kill-only\n" + exit + fi + KILL_OPTION="$option" + else + printf "Invalid options: $option\n" + exit + fi +} + +# Parse options. +SETUP_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" +CHOWN_DATA_OPTION="--no-chown-data" +KILL_OPTION="" + +ARG_INDEX=5 +while [ $ARG_INDEX -le $# ]; do + parse_options "${!ARG_INDEX}" + ((ARG_INDEX++)) +done +printf "SETUP_OPTION=$SETUP_OPTION\n" +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +printf "KILL_OPTION=$KILL_OPTION\n" + +# Json-RPC-enabled blockchain nodes +JSON_RPC_NODE_INDEX_GE=0 +JSON_RPC_NODE_INDEX_LE=4 +# Rest-Function-enabled blockchain nodes +REST_FUNC_NODE_INDEX_GE=0 +REST_FUNC_NODE_INDEX_LE=2 +# Event-Handler-enabled blockchain nodes +EVENT_HANDLER_NODE_INDEX_GE=0 +EVENT_HANDLER_NODE_INDEX_LE=4 + +printf "\n" +printf "JSON_RPC_NODE_INDEX_GE=$JSON_RPC_NODE_INDEX_GE\n" +printf "JSON_RPC_NODE_INDEX_LE=$JSON_RPC_NODE_INDEX_LE\n" +printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" +printf "REST_FUNC_NODE_INDEX_GE=$REST_FUNC_NODE_INDEX_GE\n" +printf "EVENT_HANDLER_NODE_INDEX_GE=$EVENT_HANDLER_NODE_INDEX_GE\n" +printf "EVENT_HANDLER_NODE_INDEX_LE=$EVENT_HANDLER_NODE_INDEX_LE\n" + +if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then + printf "Must provide an ACCOUNT_INJECTION_OPTION\n" + exit +fi + +# Get confirmation. +if [[ "$SEASON" = "mainnet" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? Enter [mainnet]: " + read CONFIRM + printf "\n" + if [[ ! $CONFIRM = "mainnet" ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +elif [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? Enter [testnet]: " + read CONFIRM + printf "\n" + if [[ ! $CONFIRM = "testnet" ]]; then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +else + printf "\n" + read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r + printf "\n\n" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +fi + +if [[ ! $KILL_OPTION = '--kill-only' ]]; then + # Read node ip addresses + IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then + # Get keystore password + printf "Enter password: " + read -s PASSWORD + printf "\n\n" + + if [[ "$SEASON" = "mainnet" ]]; then + KEYSTORE_DIR="mainnet_prod_keys" + elif [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + KEYSTORE_DIR="testnet_prod_keys" + else + KEYSTORE_DIR="testnet_dev_staging_keys" + fi + elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then + IFS=$'\n' read -d '' -r -a MNEMONIC_LIST < ./testnet_mnemonics/$SEASON.txt + fi +fi + +function inject_account() { + local node_index="$1" + local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + + KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" + { + echo $KEYSTORE_FILE_PATH + sleep 1 + echo $PASSWORD + } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then + local MNEMONIC=${MNEMONIC_LIST[${node_index}]} + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + { + echo $MNEMONIC + sleep 1 + echo 0 + } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + else + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" + if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" + fi + PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') + echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + fi +} + +# deploy files +FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" + +TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" +NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" +NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-node-1-oregon" +NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-node-2-singapore" +NODE_3_TARGET_ADDR="${GCP_USER}@${SEASON}-node-3-iowa" +NODE_4_TARGET_ADDR="${GCP_USER}@${SEASON}-node-4-netherlands" +NODE_5_TARGET_ADDR="${GCP_USER}@${SEASON}-node-5-taiwan" +NODE_6_TARGET_ADDR="${GCP_USER}@${SEASON}-node-6-oregon" +NODE_7_TARGET_ADDR="${GCP_USER}@${SEASON}-node-7-singapore" +NODE_8_TARGET_ADDR="${GCP_USER}@${SEASON}-node-8-iowa" +NODE_9_TARGET_ADDR="${GCP_USER}@${SEASON}-node-9-netherlands" + +TRACKER_ZONE="asia-east1-b" +NODE_0_ZONE="asia-east1-b" +NODE_1_ZONE="us-west1-b" +NODE_2_ZONE="asia-southeast1-b" +NODE_3_ZONE="us-central1-a" +NODE_4_ZONE="europe-west4-a" +NODE_5_ZONE="asia-east1-b" +NODE_6_ZONE="us-west1-b" +NODE_7_ZONE="asia-southeast1-b" +NODE_8_ZONE="us-central1-a" +NODE_9_ZONE="europe-west4-a" + +printf "###############################################################################\n" +printf "# Deploying parent blockchain #\n" +printf "###############################################################################\n\n" + +# deploy files to GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} + gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +if [[ $SETUP_OPTION = "--setup" ]]; then + # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +# install node modules on GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +if [[ $KILL_OPTION = "--skip-kill" ]]; then + printf "\nSkipping process kill...\n" +else + # kill any processes still alive + printf "\nKilling tracker / blockchain node jobs...\n" + + # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi + + if [[ $NUM_SHARDS -gt 0 ]]; then + for i in $(seq $NUM_SHARDS); do + printf "shard #$i\n" + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE + done + fi +fi + +# If --kill-only, do not proceed any further +if [[ $KILL_OPTION = "--kill-only" ]]; then + exit +fi + +printf "\nStarting blockchain servers...\n\n" +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +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_genesis_gcp.sh" + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +else + # restart with existing chains, snapshots, and log files + START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +fi +printf "\n" +printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" +printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" + +# Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 +if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + + printf "\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" + eval $START_TRACKER_CMD +fi + +begin_index=$PARENT_NODE_INDEX_BEGIN +if [[ $begin_index -lt 0 ]]; then + begin_index=0 +fi +if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\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" + else + JSON_RPC_OPTION="" + fi + UPDATE_FRONT_DB_OPTION="--update-front-db" + if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then + REST_FUNC_OPTION="--rest-func" + else + REST_FUNC_OPTION="" + fi + if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then + EVENT_HANDLER_OPTION="--event-handler" + else + EVENT_HANDLER_OPTION="" + fi + + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" + printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" + printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" + printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" + 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" + eval $START_NODE_CMD + sleep 5 + inject_account "$node_index" + done +fi + + +if [[ $NUM_SHARDS -gt 0 ]]; then + for shard_index in $(seq $NUM_SHARDS); do + printf "###############################################################################\n" + printf "# Deploying shard $shard_index blockchain #\n" + printf "###############################################################################\n\n" + + + # generate genesis config files in ./blockchain/shard_$shard_index + if [[ $SETUP_OPTION = "--setup" ]]; then + node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index + fi + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" + + # deploy files to GCP instances + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) + if [[ $SETUP_OPTION = "--setup" ]]; then + printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # install node modules on GCP instances + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, install packages and start up the server + printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" + eval $START_TRACKER_CMD + printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + done +fi From 299acb5bb1c51f702437adc41cff4960b5337b7a Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 25 Jul 2024 14:53:33 +0900 Subject: [PATCH 06/46] Rename: GCP_USER -> ONPREM_USER --- deploy_blockchain_genesis_onprem.sh | 595 ++++++++++++++-------------- 1 file changed, 298 insertions(+), 297 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index ec2bbf0a8..ab001a2a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -29,8 +29,8 @@ fi printf "SEASON=$SEASON\n" printf "PROJECT_ID=$PROJECT_ID\n" -GCP_USER="runner" -printf "GCP_USER=$GCP_USER\n" +ONPREM_USER="nvidia" +printf "ONPREM_USER=$ONPREM_USER\n" number_re='^[0-9]+$' if [[ ! $2 =~ $number_re ]] ; then @@ -218,22 +218,22 @@ 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.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" -TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" -NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" -NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-node-1-oregon" -NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-node-2-singapore" -NODE_3_TARGET_ADDR="${GCP_USER}@${SEASON}-node-3-iowa" -NODE_4_TARGET_ADDR="${GCP_USER}@${SEASON}-node-4-netherlands" -NODE_5_TARGET_ADDR="${GCP_USER}@${SEASON}-node-5-taiwan" -NODE_6_TARGET_ADDR="${GCP_USER}@${SEASON}-node-6-oregon" -NODE_7_TARGET_ADDR="${GCP_USER}@${SEASON}-node-7-singapore" -NODE_8_TARGET_ADDR="${GCP_USER}@${SEASON}-node-8-iowa" -NODE_9_TARGET_ADDR="${GCP_USER}@${SEASON}-node-9-netherlands" - -TRACKER_ZONE="asia-east1-b" +#TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-tracker-taiwan" +NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-0-taiwan" +NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-1-oregon" +NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-2-singapore" +NODE_3_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-3-iowa" +NODE_4_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-4-netherlands" +NODE_5_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-5-taiwan" +NODE_6_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-6-oregon" +NODE_7_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-7-singapore" +NODE_8_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-8-iowa" +NODE_9_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-9-netherlands" + +#TRACKER_ZONE="asia-east1-b" NODE_0_ZONE="asia-east1-b" NODE_1_ZONE="us-west1-b" NODE_2_ZONE="asia-southeast1-b" @@ -245,284 +245,285 @@ NODE_7_ZONE="asia-southeast1-b" NODE_8_ZONE="us-central1-a" NODE_9_ZONE="europe-west4-a" -printf "###############################################################################\n" -printf "# Deploying parent blockchain #\n" -printf "###############################################################################\n\n" - -# deploy files to GCP instances -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} - gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -if [[ $SETUP_OPTION = "--setup" ]]; then - # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -# install node modules on GCP instances -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -if [[ $KILL_OPTION = "--skip-kill" ]]; then - printf "\nSkipping process kill...\n" -else - # kill any processes still alive - printf "\nKilling tracker / blockchain node jobs...\n" - - # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi - - if [[ $NUM_SHARDS -gt 0 ]]; then - for i in $(seq $NUM_SHARDS); do - printf "shard #$i\n" - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" - - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - done - fi -fi - -# If --kill-only, do not proceed any further -if [[ $KILL_OPTION = "--kill-only" ]]; then - exit -fi - -printf "\nStarting blockchain servers...\n\n" -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" -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_genesis_gcp.sh" - START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -else - # restart with existing chains, snapshots, and log files - START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -fi -printf "\n" -printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" -printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" - -# Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 -if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - - printf "\n" - printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" - printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" - printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" - eval $START_TRACKER_CMD -fi - -begin_index=$PARENT_NODE_INDEX_BEGIN -if [[ $begin_index -lt 0 ]]; then - begin_index=0 -fi -if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\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" - else - JSON_RPC_OPTION="" - fi - UPDATE_FRONT_DB_OPTION="--update-front-db" - if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then - REST_FUNC_OPTION="--rest-func" - else - REST_FUNC_OPTION="" - fi - if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then - EVENT_HANDLER_OPTION="--event-handler" - else - EVENT_HANDLER_OPTION="" - fi - - printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" - printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" - printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" - printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" - printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" - printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" - 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" - eval $START_NODE_CMD - sleep 5 - inject_account "$node_index" - done -fi - - -if [[ $NUM_SHARDS -gt 0 ]]; then - for shard_index in $(seq $NUM_SHARDS); do - printf "###############################################################################\n" - printf "# Deploying shard $shard_index blockchain #\n" - printf "###############################################################################\n\n" - - - # generate genesis config files in ./blockchain/shard_$shard_index - if [[ $SETUP_OPTION = "--setup" ]]; then - node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index - fi - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" - - # deploy files to GCP instances - if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) - if [[ $SETUP_OPTION = "--setup" ]]; then - printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # install node modules on GCP instances - if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, install packages and start up the server - printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" - printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" - eval $START_TRACKER_CMD - printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - done -fi +#printf "###############################################################################\n" +#printf "# Deploying parent blockchain #\n" +#printf "###############################################################################\n\n" +# +## deploy files to GCP instances +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +#if [[ $SETUP_OPTION = "--setup" ]]; then +# # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +## install node modules on GCP instances +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +#if [[ $KILL_OPTION = "--skip-kill" ]]; then +# printf "\nSkipping process kill...\n" +#else +# # kill any processes still alive +# printf "\nKilling tracker / blockchain node jobs...\n" +# +# # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +# +# if [[ $NUM_SHARDS -gt 0 ]]; then +# for i in $(seq $NUM_SHARDS); do +# printf "shard #$i\n" +# +# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-tracker-taiwan" +# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-0-taiwan" +# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-1-oregon" +# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-2-singapore" +# +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE +# done +# fi +#fi +# +## If --kill-only, do not proceed any further +#if [[ $KILL_OPTION = "--kill-only" ]]; then +# exit +#fi +# +#printf "\nStarting blockchain servers...\n\n" +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +#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_genesis_gcp.sh" +# START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +#else +# # restart with existing chains, snapshots, and log files +# START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" +# START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +#fi +#printf "\n" +#printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" +#printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" +# +## Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 +#if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# +# printf "\n" +# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +# START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" +# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" +# eval $START_TRACKER_CMD +#fi +# +#begin_index=$PARENT_NODE_INDEX_BEGIN +#if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +#fi +#if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\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" +# else +# JSON_RPC_OPTION="" +# fi +# UPDATE_FRONT_DB_OPTION="--update-front-db" +# if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then +# REST_FUNC_OPTION="--rest-func" +# else +# REST_FUNC_OPTION="" +# fi +# if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then +# EVENT_HANDLER_OPTION="--event-handler" +# else +# EVENT_HANDLER_OPTION="" +# fi +# +# printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +# printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +# printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +# printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" +# printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" +# 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 $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' --project $PROJECT_ID --zone ${!NODE_ZONE}" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# sleep 5 +# inject_account "$node_index" +# done +#fi +# +# +#if [[ $NUM_SHARDS -gt 0 ]]; then +# for shard_index in $(seq $NUM_SHARDS); do +# printf "###############################################################################\n" +# printf "# Deploying shard $shard_index blockchain #\n" +# printf "###############################################################################\n\n" +# +# +# # generate genesis config files in ./blockchain/shard_$shard_index +# if [[ $SETUP_OPTION = "--setup" ]]; then +# node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index +# fi +# +# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" +# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" +# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" +# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" +# +# # deploy files to GCP instances +# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +# if [[ $SETUP_OPTION = "--setup" ]]; then +# printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # install node modules on GCP instances +# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # ssh into each instance, install packages and start up the server +# printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" +# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" +# eval $START_TRACKER_CMD +# printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# done +#fi +# \ No newline at end of file From df3e7668ac6d6bc33c9fc34d083e177ee46ed0e8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 09:45:25 +0900 Subject: [PATCH 07/46] Tweak some variable names --- config_client_api_ip_whitelist.sh | 16 ++++++++-------- config_node_param.sh | 16 ++++++++-------- deploy_blockchain_genesis_gcp.sh | 24 ++++++++++++------------ deploy_blockchain_genesis_onprem.sh | 24 ++++++++++++------------ deploy_blockchain_incremental_gcp.sh | 28 ++++++++++++++-------------- deploy_blockchain_sandbox_gcp.sh | 10 +++++----- inject_node_account.js | 2 +- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/config_client_api_ip_whitelist.sh b/config_client_api_ip_whitelist.sh index 1e0773737..85a0781de 100644 --- a/config_client_api_ip_whitelist.sh +++ b/config_client_api_ip_whitelist.sh @@ -64,12 +64,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt # Get keystore password -printf "Enter password: " -read -s PASSWORD +printf "Enter keystore password: " +read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then CHAIN_ID="1" @@ -96,19 +96,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" function config_node() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} - printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" + printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$IP_ADDR'" fi printf "\n" printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n" - eval "echo $PASSWORD | $CONFIG_NODE_CMD" + eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } for j in `seq $(( 0 )) $(( 9 ))`; do diff --git a/config_node_param.sh b/config_node_param.sh index 698423e79..55679bf4e 100644 --- a/config_node_param.sh +++ b/config_node_param.sh @@ -73,12 +73,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt # Get keystore password -printf "Enter password: " -read -s PASSWORD +printf "Enter keystore password: " +read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then CHAIN_ID="1" @@ -107,19 +107,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" function config_node() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} - printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" + printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'" fi printf "\n" printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n" - eval "echo $PASSWORD | $CONFIG_NODE_CMD" + eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } for j in `seq $(( 0 )) $(( 9 ))`; do diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 72d4d6eab..a17d29b09 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -163,12 +163,12 @@ else fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then - # Read node ip addresses - IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + # Read node urls + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ "$SEASON" = "mainnet" ]]; then @@ -185,35 +185,35 @@ fi function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi } diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index ab001a2a0..cb203cd26 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -163,12 +163,12 @@ else fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then - # Read node ip addresses - IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + # Read node urls + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ "$SEASON" = "mainnet" ]]; then @@ -185,35 +185,35 @@ fi function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi } diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index a76939487..84e6a156c 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -148,12 +148,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then KEYSTORE_DIR="mainnet_prod_keys" @@ -286,37 +286,37 @@ function deploy_node() { # 4. Inject node account sleep 5 if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} printf "\n* >> Initializing account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi # 5. Wait until node is synced diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index c1679ed28..f6982ff8e 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -90,17 +90,17 @@ then [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION } # GCP node address diff --git a/inject_node_account.js b/inject_node_account.js index d0784efee..53088988e 100644 --- a/inject_node_account.js +++ b/inject_node_account.js @@ -61,7 +61,7 @@ async function injectAccount(endpointUrl, accountInjectionOption) { }) properties.push({ name: 'password', - description: 'Enter password:', + description: 'Enter keystore password:', hidden: true }) break; From 3bbd6cad1655d269027328714495b1aa8a390a14 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:14:08 +0900 Subject: [PATCH 08/46] Add file deploy part for onpremise --- deploy_blockchain_genesis_onprem.sh | 76 +++++++++++------------------ 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index cb203cd26..9f058f2d9 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -164,7 +164,10 @@ fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls - IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_onprem.txt + # Read node ip addresses and passwords + IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt + IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " @@ -221,59 +224,38 @@ function inject_account() { #FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" -#TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-tracker-taiwan" -NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-0-taiwan" -NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-1-oregon" -NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-2-singapore" -NODE_3_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-3-iowa" -NODE_4_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-4-netherlands" -NODE_5_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-5-taiwan" -NODE_6_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-6-oregon" -NODE_7_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-7-singapore" -NODE_8_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-8-iowa" -NODE_9_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-9-netherlands" +printf "###############################################################################\n" +printf "# Deploying parent blockchain #\n" +printf "###############################################################################\n\n" -#TRACKER_ZONE="asia-east1-b" -NODE_0_ZONE="asia-east1-b" -NODE_1_ZONE="us-west1-b" -NODE_2_ZONE="asia-southeast1-b" -NODE_3_ZONE="us-central1-a" -NODE_4_ZONE="europe-west4-a" -NODE_5_ZONE="asia-east1-b" -NODE_6_ZONE="us-west1-b" -NODE_7_ZONE="asia-southeast1-b" -NODE_8_ZONE="us-central1-a" -NODE_9_ZONE="europe-west4-a" - -#printf "###############################################################################\n" -#printf "# Deploying parent blockchain #\n" -#printf "###############################################################################\n\n" -# -## deploy files to GCP instances -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# deploy files to GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE # gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} -# gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + printf "NODE_LOGIN_PW=${NODE_LOGIN_PW}\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/ + #sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "ls -la" + done + fi +fi + ## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) #if [[ $SETUP_OPTION = "--setup" ]]; then # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 From 50a1add718d04246231299061b4b473944241330 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:30:44 +0900 Subject: [PATCH 09/46] Tweak filename: setup_blockchain_ubuntu_gcp.sh --- README.md | 4 ++-- deploy_blockchain_genesis_gcp.sh | 16 ++++++++-------- deploy_blockchain_genesis_onprem.sh | 16 ++++++++-------- deploy_blockchain_incremental_gcp.sh | 8 ++++---- deploy_blockchain_sandbox_gcp.sh | 4 ++-- deploy_test_gcp.sh | 4 ++-- ...n_ubuntu.sh => setup_blockchain_ubuntu_gcp.sh | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) rename setup_blockchain_ubuntu.sh => setup_blockchain_ubuntu_gcp.sh (96%) diff --git a/README.md b/README.md index abe9ebad3..9bd5db8db 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer ``` - Set up Ubuntu machine (if it's on a new VM) ``` -bash setup_blockchain_ubuntu.sh +bash setup_blockchain_ubuntu_gcp.sh ``` - Start tracker server job ``` @@ -136,7 +136,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer ``` - Set up Ubuntu machine (if it's on a new VM) ``` -bash setup_blockchain_ubuntu.sh +bash setup_blockchain_ubuntu_gcp.sh ``` - Start Node server job (set shard index to 0 if you're running a root chain node) ``` diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index a17d29b09..580e097e2 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -218,8 +218,8 @@ 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.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +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" TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" @@ -279,7 +279,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE fi begin_index=$PARENT_NODE_INDEX_BEGIN @@ -292,7 +292,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then NODE_ZONE=NODE_${node_index}_ZONE printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} done fi fi @@ -486,13 +486,13 @@ if [[ $NUM_SHARDS -gt 0 ]]; then # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $SETUP_OPTION = "--setup" ]]; then printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE fi # install node modules on GCP instances diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 9f058f2d9..cf8256a6c 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -221,8 +221,8 @@ 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.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +#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" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -261,7 +261,7 @@ fi # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi # # begin_index=$PARENT_NODE_INDEX_BEGIN @@ -274,7 +274,7 @@ fi # NODE_ZONE=NODE_${node_index}_ZONE # # printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} # done # fi #fi @@ -468,13 +468,13 @@ fi # # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) # if [[ $SETUP_OPTION = "--setup" ]]; then # printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE # printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE # printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE # fi # # # install node modules on GCP instances diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 84e6a156c..d64b9b054 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -166,8 +166,8 @@ elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then IFS=$'\n' read -d '' -r -a MNEMONIC_LIST < ./testnet_mnemonics/$SEASON.txt fi -FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +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" NUM_SHARD_NODES=3 @@ -204,7 +204,7 @@ function deploy_tracker() { if [[ $SETUP_OPTION = "--setup" ]]; then # 2. Set up tracker printf "\n\n[[[ Setting up tracker ]]]\n\n" - SETUP_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $TRACKER_ZONE" + SETUP_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone $TRACKER_ZONE" printf "SETUP_CMD=$SETUP_CMD\n\n" eval $SETUP_CMD fi @@ -243,7 +243,7 @@ function deploy_node() { if [[ $SETUP_OPTION = "--setup" ]]; then # 2. Set up node printf "\n\n<<< Setting up node $node_index >>>\n\n" - SETUP_CMD="gcloud compute ssh $node_target_addr --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $node_zone" + SETUP_CMD="gcloud compute ssh $node_target_addr --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone $node_zone" printf "SETUP_CMD=$SETUP_CMD\n\n" eval $SETUP_CMD fi diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index f6982ff8e..e12f7c1be 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -308,7 +308,7 @@ NODE_98_ZONE="us-central1-a" NODE_99_ZONE="europe-west4-a" # deploy files -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.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_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" # Work in progress spinner spin="-\|/" @@ -380,7 +380,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE - SETUP_BLOCKCHAIN_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '. setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone ${!NODE_ZONE}" + SETUP_BLOCKCHAIN_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '. setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone ${!NODE_ZONE}" # NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose # printf "SETUP_BLOCKCHAIN_CMD=$SETUP_BLOCKCHAIN_CMD\n" if [[ $index < "$(($NUM_NODES - 1))" ]]; then diff --git a/deploy_test_gcp.sh b/deploy_test_gcp.sh index c604d88bf..3e1e59b4f 100644 --- a/deploy_test_gcp.sh +++ b/deploy_test_gcp.sh @@ -92,7 +92,7 @@ function stop_servers() { } # deploy files -FILES_FOR_TEST="afan_client/ blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ test/ tools/ tracker-server/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh stop_local_blockchain.sh" +FILES_FOR_TEST="afan_client/ blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ test/ tools/ tracker-server/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh stop_local_blockchain.sh" printf "\n" PROJECT_ID="testnet-dev-ground" @@ -129,7 +129,7 @@ function deploy_test() { # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $SETUP_OPTION = "--setup" ]]; then printf "\n >> Setting up instance [$instance_index] ($test_target_addr) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" - gcloud compute ssh ${test_target_addr} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${TEST_ZONE} + gcloud compute ssh ${test_target_addr} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${TEST_ZONE} fi if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then diff --git a/setup_blockchain_ubuntu.sh b/setup_blockchain_ubuntu_gcp.sh similarity index 96% rename from setup_blockchain_ubuntu.sh rename to setup_blockchain_ubuntu_gcp.sh index a230b78a1..adeb6800b 100644 --- a/setup_blockchain_ubuntu.sh +++ b/setup_blockchain_ubuntu_gcp.sh @@ -1,6 +1,6 @@ #!/bin/bash -printf "\n[[[[[ setup_blockchain_ubuntu.sh ]]]]]\n\n" +printf "\n[[[[[ setup_blockchain_ubuntu_gcp.sh ]]]]]\n\n" printf '\n[[ Upgrading apt.. ]]\n' sudo apt update From 01f5e81a155c85bf3e84c8967cd74e62c922a947 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:33:07 +0900 Subject: [PATCH 10/46] Add setup_blockchain_ubuntu_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 16 ++++----- setup_blockchain_ubuntu_onprem.sh | 56 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 setup_blockchain_ubuntu_onprem.sh diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index cf8256a6c..fef8971a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -221,8 +221,8 @@ 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_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_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -261,7 +261,7 @@ fi # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi # # begin_index=$PARENT_NODE_INDEX_BEGIN @@ -274,7 +274,7 @@ fi # NODE_ZONE=NODE_${node_index}_ZONE # # printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} # done # fi #fi @@ -468,13 +468,13 @@ fi # # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) # if [[ $SETUP_OPTION = "--setup" ]]; then # printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_0_ZONE # printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_1_ZONE # printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_2_ZONE # fi # # # install node modules on GCP instances diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh new file mode 100644 index 000000000..19572bae1 --- /dev/null +++ b/setup_blockchain_ubuntu_onprem.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" + +printf '\n[[ Upgrading apt.. ]]\n' +sudo apt update +# skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) +sudo apt-get --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade + +printf '\n[[ Uninstalling NodeJS.. ]]\n' +sudo apt-get -y purge nodejs +sudo apt-get -y autoremove + +printf '\n[[ Installing NodeJS.. ]]\n' +sudo apt update +sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates +curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - +# skip prompting for daemon restart (see https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services) +sudo NEEDRESTART_MODE=a apt -y install nodejs + +printf 'node -v\n' +node -v + +printf 'npm --version\n' +npm --version + + +printf '\n[[ Installing yarn.. ]]\n' +sudo npm install -g yarn + +printf 'yarn --version\n' +sudo yarn --version + + +printf '\n[[ Installing make.. ]]\n' +sudo apt update +# skip prompting for daemon restart (see https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services) +sudo NEEDRESTART_MODE=a apt-get install -y build-essential + +printf 'make --version\n' +make --version + + +printf '\n[[ Installing vim.. ]]\n' +sudo apt update +sudo apt install -y vim + +printf 'vim --version\n' +vim --version + +printf '\n[[ Installing jq.. ]]\n' +sudo apt update +sudo apt install -y jq + +printf 'jq --version\n' +jq --version \ No newline at end of file From a69deefd07425371e9e346c9599d0089ddba72be Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:38:34 +0900 Subject: [PATCH 11/46] Add ubuntu setup part for onpremise --- deploy_blockchain_genesis_onprem.sh | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index fef8971a0..946f2e76f 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -247,38 +247,38 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" - printf "NODE_LOGIN_PW=${NODE_LOGIN_PW}\n" - printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\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/ - #sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "ls -la" done fi fi -## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -#if [[ $SETUP_OPTION = "--setup" ]]; then +# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +if [[ $SETUP_OPTION = "--setup" ]]; then # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${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" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + done + fi +fi + ## install node modules on GCP instances #if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 From f85aca985c0eb838de4595df26a9e034033e2a52 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 11:18:42 +0900 Subject: [PATCH 12/46] Fix on-premise ubuntu setup --- setup_blockchain_ubuntu_onprem.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index 19572bae1..f2627bc27 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -7,6 +7,10 @@ sudo apt update # skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) sudo apt-get --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade +# needed for on-premise nvidia machines +printf '\n[ apt --fix-broken install ]\n' +sudo apt -y --fix-broken install + printf '\n[[ Uninstalling NodeJS.. ]]\n' sudo apt-get -y purge nodejs sudo apt-get -y autoremove From 3f53f78984ef2b6e1eb771fef93b1734cd93130f Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 11:24:27 +0900 Subject: [PATCH 13/46] Add yarn install part for onpremise --- deploy_blockchain_genesis_onprem.sh | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 946f2e76f..74911cd86 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -279,29 +279,31 @@ if [[ $SETUP_OPTION = "--setup" ]]; then fi fi -## install node modules on GCP instances -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# install node modules on GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${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 ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" + done + fi +fi + #if [[ $KILL_OPTION = "--skip-kill" ]]; then # printf "\nSkipping process kill...\n" #else From bc3959df986dfecb41afbbf522fb44f33905a482 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 13:21:18 +0900 Subject: [PATCH 14/46] Add process kill part for onpremise --- deploy_blockchain_genesis_onprem.sh | 81 ++++++++++++----------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 74911cd86..64b46511e 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -162,12 +162,13 @@ else fi fi +# Read node ip addresses and passwords +IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt +IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt + if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_onprem.txt - # Read node ip addresses and passwords - IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt - IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " @@ -298,60 +299,46 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then 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" + printf "\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" -#else -# # kill any processes still alive -# printf "\nKilling tracker / blockchain node jobs...\n" -# +if [[ $KILL_OPTION = "--skip-kill" ]]; then + printf "\nSkipping process kill...\n" +else + # kill any processes still alive + printf "\nKilling tracker / blockchain node jobs...\n" + # # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -# -# if [[ $NUM_SHARDS -gt 0 ]]; then -# for i in $(seq $NUM_SHARDS); do -# printf "shard #$i\n" -# -# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-tracker-taiwan" -# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-0-taiwan" -# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-1-oregon" -# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-2-singapore" -# -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE -# done -# fi -#fi -# -## If --kill-only, do not proceed any further -#if [[ $KILL_OPTION = "--kill-only" ]]; then -# exit -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${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" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo killall node" + done + fi +fi + +# If --kill-only, do not proceed any further +if [[ $KILL_OPTION = "--kill-only" ]]; then + exit +fi + #printf "\nStarting blockchain servers...\n\n" #if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" From 240aa8051e5ddf4f578c67debe20e1545a242c57 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 14:47:34 +0900 Subject: [PATCH 15/46] Add start job part for onpremise --- deploy_blockchain_genesis_onprem.sh | 213 +++++++++------------------- 1 file changed, 68 insertions(+), 145 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 64b46511e..4be729b04 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -339,28 +339,28 @@ if [[ $KILL_OPTION = "--kill-only" ]]; then exit fi -#printf "\nStarting blockchain servers...\n\n" -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" -#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 +printf "\nStarting blockchain servers...\n\n" +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +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_genesis_gcp.sh" -# START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -#else -# # restart with existing chains, snapshots, and log files + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +else + # restart with existing chains, snapshots, and log files # START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" -# START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -#fi -#printf "\n" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +fi +printf "\n" #printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" -#printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" -# +printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" + ## Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 #if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" @@ -372,129 +372,52 @@ fi # printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" # eval $START_TRACKER_CMD #fi -# -#begin_index=$PARENT_NODE_INDEX_BEGIN -#if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -#fi -#if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\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" -# else -# JSON_RPC_OPTION="" -# fi -# UPDATE_FRONT_DB_OPTION="--update-front-db" -# if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then -# REST_FUNC_OPTION="--rest-func" -# else -# REST_FUNC_OPTION="" -# fi -# if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then -# EVENT_HANDLER_OPTION="--event-handler" -# else -# EVENT_HANDLER_OPTION="" -# fi -# -# printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" -# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" -# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" -# printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" -# printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" -# printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" -# printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" -# 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 $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' --project $PROJECT_ID --zone ${!NODE_ZONE}" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# sleep 5 -# inject_account "$node_index" -# done -#fi -# -# -#if [[ $NUM_SHARDS -gt 0 ]]; then -# for shard_index in $(seq $NUM_SHARDS); do -# printf "###############################################################################\n" -# printf "# Deploying shard $shard_index blockchain #\n" -# printf "###############################################################################\n\n" -# -# -# # generate genesis config files in ./blockchain/shard_$shard_index -# if [[ $SETUP_OPTION = "--setup" ]]; then -# node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index -# fi -# -# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" -# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" -# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" -# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" -# -# # deploy files to GCP instances -# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE -# gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -# if [[ $SETUP_OPTION = "--setup" ]]; then -# printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # install node modules on GCP instances -# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # ssh into each instance, install packages and start up the server -# printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" -# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" -# eval $START_TRACKER_CMD -# printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# done -#fi -# \ No newline at end of file + +begin_index=$PARENT_NODE_INDEX_BEGIN +if [[ $begin_index -lt 0 ]]; then + begin_index=0 +fi +if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${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* >> 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" + else + JSON_RPC_OPTION="" + fi + UPDATE_FRONT_DB_OPTION="--update-front-db" + if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then + REST_FUNC_OPTION="--rest-func" + else + REST_FUNC_OPTION="" + fi + if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then + EVENT_HANDLER_OPTION="--event-handler" + else + EVENT_HANDLER_OPTION="" + fi + + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" + printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" + printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" + printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" + printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" + printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" + + printf "\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 "START_NODE_CMD=$START_NODE_CMD\n" + eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + sleep 5 + inject_account "$node_index" + done +fi From a154436a566433d472cc77f82f494fde02f74404 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:11:10 +0900 Subject: [PATCH 16/46] Fix sudo blocking issue in ubuntu setup --- deploy_blockchain_genesis_onprem.sh | 2 +- setup_blockchain_ubuntu_onprem.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 4be729b04..e81044e2c 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -275,7 +275,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + 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 diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index f2627bc27..b7b145a6e 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -2,6 +2,15 @@ printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" +# Get keystore password +printf "Enter keystore password: " +read -s NODE_LOGIN_PW +printf "\n\n" + +# needed for on-premise nvidia machines +# do sudo once with a dummy command +echo $NODE_LOGIN_PW | sudo -S ls -la + printf '\n[[ Upgrading apt.. ]]\n' sudo apt update # skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) From 9ac388fc0a15679ed2d2d1bde4f7fcb8bf3b2377 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:31:03 +0900 Subject: [PATCH 17/46] Add start_node_genesis_onprem.sh --- start_node_genesis_onprem.sh | 332 +++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 start_node_genesis_onprem.sh diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh new file mode 100644 index 000000000..04ffe6faa --- /dev/null +++ b/start_node_genesis_onprem.sh @@ -0,0 +1,332 @@ +#!/bin/bash + +# NOTE(minsulee2): Since exit really exits terminals, those are replaced to return 1. +if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then + printf "Usage: bash start_node_genesis_onprem.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler]\n" + printf "Example: bash start_node_genesis_onprem.sh spring gcp_user 0 0 --keystore --no-keep-code --full-sync --no-chown-data\n" + printf "\n" + return 1 +fi +printf "\n[[[[[ start_node_genesis_onprem.sh ]]]]]\n\n" + +function parse_options() { + local option="$1" + if [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keystore' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--mnemonic' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--no-chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--json-rpc' ]]; then + JSON_RPC_OPTION="$option" + elif [[ $option = '--update-front-db' ]]; then + UPDATE_FRONT_DB_OPTION="$option" + elif [[ $option = '--rest-func' ]]; then + REST_FUNC_OPTION="$option" + elif [[ $option = '--event-handler' ]]; then + EVENT_HANDLER_OPTION="$option" + else + printf "Invalid options: $option\n" + return 1 + fi +} + +# Parse options. +SEASON="$1" +GCP_USER="$2" + +number_re='^[0-9]+$' +if ! [[ $3 =~ $number_re ]] ; then + printf "Invalid argument: $3\n" + return 1 +fi +SHARD_INDEX="$3" + +if ! [[ $4 =~ $number_re ]] ; then + printf "Invalid argument: $4\n" + return 1 +fi +# NOTE(minsulee2): Sandbox has 100 nodes. +if [[ "$4" -lt 0 ]] || [[ "$4" -gt 100 ]]; then + printf "Invalid argument: $4\n" + return 1 +fi +NODE_INDEX="$4" + +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" +CHOWN_DATA_OPTION="--no-chown-data" +JSON_RPC_OPTION="" +UPDATE_FRONT_DB_OPTION="" +REST_FUNC_OPTION="" +EVENT_HANDLER_OPTION="" + +ARG_INDEX=5 +while [ $ARG_INDEX -le $# ]; do + parse_options "${!ARG_INDEX}" + ((ARG_INDEX++)) +done + +printf "SEASON=$SEASON\n" +printf "GCP_USER=$GCP_USER\n" +printf "SHARD_INDEX=$SHARD_INDEX\n" +printf "NODE_INDEX=$NODE_INDEX\n" +printf "\n" + +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" +printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" +printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" +printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" + +# Peer-whitelisting-enabled blockchain nodes +# Peer whitelisting is disabled now with 5 core blockchain nodes on GCP. +#PEER_WHITELIST_NODE_INDEX_GE=0 +#PEER_WHITELIST_NODE_INDEX_LE=4 +PEER_WHITELIST_NODE_INDEX_GE=-1 +PEER_WHITELIST_NODE_INDEX_LE=-1 + +printf "\n" +printf "PEER_WHITELIST_NODE_INDEX_GE=$PEER_WHITELIST_NODE_INDEX_GE\n" +printf "PEER_WHITELIST_NODE_INDEX_LE=$PEER_WHITELIST_NODE_INDEX_LE\n" + +# NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. +if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then + printf 'Invalid account injection option\n' + return 1 +fi + +if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then + printf "Must provide an ACCOUNT_INJECTION_OPTION\n" + return 1 +fi + +if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then + export ACCOUNT_INJECTION_OPTION=keystore +elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then + export ACCOUNT_INJECTION_OPTION=mnemonic +else + export ACCOUNT_INJECTION_OPTION=private_key +fi +if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then + export SYNC_MODE=full +else + export SYNC_MODE=fast +fi +if [[ $SEASON = "staging" ]] || [[ $SEASON = "exp" ]]; then + # staging: for performance test pipeline + # exp: for performance test + export ENABLE_EXPRESS_RATE_LIMIT=false +else + export ENABLE_EXPRESS_RATE_LIMIT=true +fi +if [[ $JSON_RPC_OPTION ]]; then + export ENABLE_JSON_RPC_API=true +else + export ENABLE_JSON_RPC_API=false +fi +if [[ $UPDATE_FRONT_DB_OPTION ]]; then + export UPDATE_NEW_FINAL_FRONT_DB_WITH_TX_POOL=true +else + export UPDATE_NEW_FINAL_FRONT_DB_WITH_TX_POOL=false +fi +if [[ $REST_FUNC_OPTION ]]; then + export ENABLE_REST_FUNCTION_CALL=true +else + export ENABLE_REST_FUNCTION_CALL=false +fi +if [[ $EVENT_HANDLER_OPTION ]]; then + export ENABLE_EVENT_HANDLER=true +else + export ENABLE_EVENT_HANDLER=false +fi + +printf '\n' +printf 'Killing old jobs..\n' +sudo killall node +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf '\n' + printf 'Setting up new working directory..\n' + sudo rm -rf /home/ain-blockchain* + CODE_CMD="cd ~; sudo mv ain-blockchain /home; sudo chmod -R 777 /home/ain-blockchain; sudo chown -R $GCP_USER:$GCP_USER /home/ain-blockchain; cd /home/ain-blockchain" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD +else + printf '\n' + printf 'Reusing existing working directory..\n' + OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) + printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R $GCP_USER:$GCP_USER $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD +fi +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + printf '\n' + printf 'Setting up new data directory..\n' + sudo rm -rf /home/ain_blockchain_data/chains + sudo rm -rf /home/ain_blockchain_data/snapshots + sudo rm -rf /home/ain_blockchain_data/logs + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD +else + printf 'Reusing existing data directory..\n' + if [[ $CHOWN_DATA_OPTION = "--no-chown-data" ]]; then + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod 777 /home/ain_blockchain_data; sudo chown $GCP_USER:$GCP_USER /home/ain_blockchain_data" + else + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/ain_blockchain_data" + fi + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD +fi + + +if [[ $SEASON = 'mainnet' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/mainnet-prod + export PEER_CANDIDATE_JSON_RPC_URL="http://104.199.237.250:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000C63907F7Aeca56A72F5a4F7cd00EfFCF11c3A,0x001C3C9C4a5669eCD8b78946f6fa5549b33362F8,0x002C76f0aeA9Ba615428d9dF7fedEC6f8ed5369f,0x003C9d091584fEC96bC3bD8423c884680BEAaf4E,0x004C4328B6c2ABF7c4Df897a8124b36E3f00a2FC,0x005C99Db64845e5BF24cd152b22c932989479907,0x006C672861e9DBb09232307c17Be6554BC90687c,0x007C36bf5D0F77836eE138EEAc8df7051b43209b,0x008C287187a5626D0a25DbD67327B36AC55B998E,0x009C66DBce144003f8C4B859fFFce78F80fDD639" + fi +elif [[ $SEASON = 'summer' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export TRACKER_UPDATE_JSON_RPC_URL="http://35.194.172.106:8080/json-rpc" + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.169.78:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000AF024FEDb636294867bEff390bCE6ef9C5fc4,0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d,0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211,0x003AD6FdB06684175e7D95EcC36758B014517E4b,0x004A2550661c8a306207C9dabb279d5701fFD66e,0x005A3c55EcE1A593b761D408B6E6BC778E0a638B,0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe,0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74,0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba,0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD" + fi +elif [[ $SEASON = 'spring' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export PEER_CANDIDATE_JSON_RPC_URL="http://35.221.184.48:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000AF024FEDb636294867bEff390bCE6ef9C5fc4,0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d,0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211,0x003AD6FdB06684175e7D95EcC36758B014517E4b,0x004A2550661c8a306207C9dabb279d5701fFD66e,0x005A3c55EcE1A593b761D408B6E6BC778E0a638B,0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe,0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74,0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba,0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD" + fi +elif [[ "$SEASON" = "sandbox" ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-sandbox + if [[ $NODE_INDEX -lt 10 ]]; then + # Nodes 10 & above will use https://sandbox-api.ainetwork.ai/json-rpc. + export PEER_CANDIDATE_JSON_RPC_URL="http://130.211.244.169:8080/json-rpc" + fi + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'staging' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-staging + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.139.219:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'exp' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-exp + export PEER_CANDIDATE_JSON_RPC_URL="http://34.81.178.195:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'dev' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-dev + if [[ $SHARD_INDEX = 0 ]]; then + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.235.180:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi + elif [[ $SHARD_INDEX = 1 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.187.153.22:8080/json-rpc" # dev-shard-1-tracker-ip + elif [[ $SHARD_INDEX = 2 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.203.104:8080/json-rpc" # dev-shard-2-tracker-ip + elif [[ $SHARD_INDEX = 3 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.189.174.17:8080/json-rpc" # dev-shard-3-tracker-ip + elif [[ $SHARD_INDEX = 4 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.164.158:8080/json-rpc" # dev-shard-4-tracker-ip + elif [[ $SHARD_INDEX = 5 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.46.65:8080/json-rpc" # dev-shard-5-tracker-ip + elif [[ $SHARD_INDEX = 6 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.210.171:8080/json-rpc" # dev-shard-6-tracker-ip + elif [[ $SHARD_INDEX = 7 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.222.121:8080/json-rpc" # dev-shard-7-tracker-ip + elif [[ $SHARD_INDEX = 8 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.200.95:8080/json-rpc" # dev-shard-8-tracker-ip + elif [[ $SHARD_INDEX = 9 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.216.199:8080/json-rpc" # dev-shard-9-tracker-ip + elif [[ $SHARD_INDEX = 10 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.161.85:8080/json-rpc" # dev-shard-10-tracker-ip + elif [[ $SHARD_INDEX = 11 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.194.239.169:8080/json-rpc" # dev-shard-11-tracker-ip + elif [[ $SHARD_INDEX = 12 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.185.156.22:8080/json-rpc" # dev-shard-12-tracker-ip + elif [[ $SHARD_INDEX = 13 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.247.143:8080/json-rpc" # dev-shard-13-tracker-ip + elif [[ $SHARD_INDEX = 14 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.226.47:8080/json-rpc" # dev-shard-14-tracker-ip + elif [[ $SHARD_INDEX = 15 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.61.23:8080/json-rpc" # dev-shard-15-tracker-ip + elif [[ $SHARD_INDEX = 16 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.66.41:8080/json-rpc" # dev-shard-16-tracker-ip + elif [[ $SHARD_INDEX = 17 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.143.18:8080/json-rpc" # dev-shard-17-tracker-ip + elif [[ $SHARD_INDEX = 18 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.58.137:8080/json-rpc" # dev-shard-18-tracker-ip + elif [[ $SHARD_INDEX = 19 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.249.104:8080/json-rpc" # dev-shard-19-tracker-ip + elif [[ $SHARD_INDEX = 20 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.201.248.92:8080/json-rpc" # dev-shard-20-tracker-ip + else + printf "Invalid shard ID argument: $SHARD_INDEX\n" + return 1 + fi + if [[ $SHARD_INDEX -gt 0 ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/sim-shard + fi +else + printf "Invalid season argument: $SEASON\n" + return 1 +fi + +printf "\n" +printf "TRACKER_UPDATE_JSON_RPC_URL=$TRACKER_UPDATE_JSON_RPC_URL\n" +printf "BLOCKCHAIN_CONFIGS_DIR=$BLOCKCHAIN_CONFIGS_DIR\n" +printf "PEER_CANDIDATE_JSON_RPC_URL=$PEER_CANDIDATE_JSON_RPC_URL\n" +printf "PEER_WHITELIST=$PEER_WHITELIST\n" + +export STAKE=100000 +printf "STAKE=$STAKE\n" +export LOG_BANDAGE_INFO=true +printf "LOG_BANDAGE_INFO=$LOG_BANDAGE_INFO\n" +# uncomment and set value when necessary +#export TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=124440 # summer +#printf "TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=$TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER\n" + +if [[ "$SEASON" = "sandbox" ]]; then + MAX_OLD_SPACE_SIZE_MB=11000 +else + MAX_OLD_SPACE_SIZE_MB=55000 +fi + +printf "\nStarting up Blockchain Node server..\n\n" +START_CMD="nohup node --async-stack-traces --max-old-space-size=$MAX_OLD_SPACE_SIZE_MB client/index.js >/dev/null 2>error_logs.txt &" +printf "\nSTART_CMD=$START_CMD\n" +printf "START_CMD=$START_CMD\n" >> start_commands.txt +eval $START_CMD + + +printf "\nBlockchain Node server [$SEASON $SHARD_INDEX $NODE_INDEX] is now up!\n\n" From 0d2c2cbf2ba50dd2bf4abbc8f146a915007316f5 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:43:06 +0900 Subject: [PATCH 18/46] Use start_node_genesis_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 14 ++++++++------ setup_blockchain_ubuntu_onprem.sh | 7 +++---- start_node_genesis_onprem.sh | 9 +++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index e81044e2c..b317a23fd 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -223,7 +223,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_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_onprem.sh start_node_genesis_onprem.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -351,11 +351,11 @@ if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then 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_genesis_gcp.sh" - START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" else # restart with existing chains, snapshots, and log files # START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" fi printf "\n" #printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" @@ -414,9 +414,11 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\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 "START_NODE_CMD=$START_NODE_CMD\n" - eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + #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'" + #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 "START_NODE_CMD=$START_NODE_CMD\n" + #eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) 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" sleep 5 inject_account "$node_index" done diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index b7b145a6e..7943e579b 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -2,12 +2,11 @@ printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" -# Get keystore password -printf "Enter keystore password: " +# needed for on-premise nvidia machines +# Get node login password +printf "Enter node login password: " read -s NODE_LOGIN_PW printf "\n\n" - -# needed for on-premise nvidia machines # do sudo once with a dummy command echo $NODE_LOGIN_PW | sudo -S ls -la diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index 04ffe6faa..b16e40c49 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -7,6 +7,15 @@ if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then printf "\n" return 1 fi + +# needed for on-premise nvidia machines +# Get node login password +printf "Enter node login password: " +read -s NODE_LOGIN_PW +printf "\n\n" +# do sudo once with a dummy command +echo $NODE_LOGIN_PW | sudo -S ls -la + printf "\n[[[[[ start_node_genesis_onprem.sh ]]]]]\n\n" function parse_options() { From 61ae9f354058e2b5b1500a584881386b73be4447 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 17:27:51 +0900 Subject: [PATCH 19/46] Fix start node part for onpremise --- deploy_blockchain_genesis_onprem.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index b317a23fd..1d88be7a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -414,11 +414,9 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\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'" - #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 "START_NODE_CMD=$START_NODE_CMD\n" - #eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" - echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) 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" + 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 "START_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" done From e69bab5afb7480c54341d8160c4d568bfe23e4b8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 18:00:53 +0900 Subject: [PATCH 20/46] Check --setup option along with --no-keep-code option --- deploy_blockchain_genesis_gcp.sh | 6 ++++++ deploy_blockchain_genesis_onprem.sh | 6 ++++++ deploy_blockchain_incremental_gcp.sh | 5 +++++ deploy_blockchain_sandbox_gcp.sh | 6 ++++++ deploy_test_gcp.sh | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 580e097e2..90a6509ff 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -104,6 +104,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 1d88be7a0..b2850ea54 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -104,6 +104,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index d64b9b054..f2ad47dec 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -91,6 +91,11 @@ while [ $ARG_INDEX -le $# ]; do ((ARG_INDEX++)) done +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index e12f7c1be..3bec26142 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -74,6 +74,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" diff --git a/deploy_test_gcp.sh b/deploy_test_gcp.sh index 3e1e59b4f..b88394daf 100644 --- a/deploy_test_gcp.sh +++ b/deploy_test_gcp.sh @@ -63,6 +63,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "CAT_LOG_OPTION=$CAT_LOG_OPTION\n" printf "STOP_ONLY_OPTION=$STOP_ONLY_OPTION\n" From f14baeba0120c2cc367c2407d7c19a7cc3eb0698 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 29 Jul 2024 11:20:13 +0900 Subject: [PATCH 21/46] Add -v option to ssh --- deploy_blockchain_genesis_onprem.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index b2850ea54..4f42d4180 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -281,7 +281,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then 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 ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + 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" done fi fi @@ -306,7 +306,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then 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 ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" done fi fi @@ -335,7 +335,7 @@ else printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo killall node" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo killall node" done fi fi @@ -420,7 +420,7 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\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'" + 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" eval "echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" sleep 5 From a1a385e4907c2b779f53ccef2ebef4a05345ddb1 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 29 Jul 2024 14:43:09 +0900 Subject: [PATCH 22/46] Use ONPREM_USER --- deploy_blockchain_genesis_onprem.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 4f42d4180..809461a41 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -250,7 +250,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + 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" @@ -275,7 +275,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + 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" @@ -300,7 +300,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + 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" @@ -329,7 +329,7 @@ else fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + 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" @@ -385,7 +385,7 @@ if [[ $begin_index -lt 0 ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + 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" From 3f9bfc671430518b96e4ddaf8686968dfe513f90 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 29 Jul 2024 16:06:07 +0900 Subject: [PATCH 23/46] Set HOSTING_ENV=comcom for on-premise node jobs --- start_node_genesis_onprem.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index b16e40c49..a99615efd 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -324,6 +324,9 @@ printf "LOG_BANDAGE_INFO=$LOG_BANDAGE_INFO\n" # uncomment and set value when necessary #export TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=124440 # summer #printf "TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=$TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER\n" +# on-premise nodes run with "comcom" hosting env +export HOSTING_ENV="comcom" +printf "HOSTING_ENV=$HOSTING_ENV\n" if [[ "$SEASON" = "sandbox" ]]; then MAX_OLD_SPACE_SIZE_MB=11000 From 1c9876e7fbf974c861421cbfef03f54a1b95e873 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 1 Aug 2024 18:38:02 +0900 Subject: [PATCH 24/46] Fix sudo password issue of kill jobs command --- deploy_blockchain_genesis_onprem.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 809461a41..ef6cbb9e8 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -335,7 +335,7 @@ else printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo killall node" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo -S killall node" done fi fi From 56a12ce9c3ef9ae66fe1b5e3809faa0b97ef3519 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 1 Aug 2024 18:57:20 +0900 Subject: [PATCH 25/46] Fix sudo password issue of removing old data command --- deploy_blockchain_genesis_onprem.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index ef6cbb9e8..916ca2fd0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -351,18 +351,9 @@ 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_genesis_gcp.sh" - START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" -else - # restart with existing chains, snapshots, and log files -# START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" -fi + +#START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" +START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" printf "\n" #printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" @@ -390,6 +381,15 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g 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" + + CHAINS_DIR=/home/ain_blockchain_data/chains + SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots + LOGS_DIR=/home/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" + fi + printf "\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 From a1b32b9f02de3ab09814561ada57f70314480d7a Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 1 Aug 2024 20:01:26 +0900 Subject: [PATCH 26/46] Tweak printing order --- deploy_blockchain_genesis_gcp.sh | 2 +- deploy_blockchain_genesis_onprem.sh | 2 +- deploy_blockchain_incremental_gcp.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 90a6509ff..78b670338 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -131,8 +131,8 @@ EVENT_HANDLER_NODE_INDEX_LE=4 printf "\n" printf "JSON_RPC_NODE_INDEX_GE=$JSON_RPC_NODE_INDEX_GE\n" printf "JSON_RPC_NODE_INDEX_LE=$JSON_RPC_NODE_INDEX_LE\n" -printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "REST_FUNC_NODE_INDEX_GE=$REST_FUNC_NODE_INDEX_GE\n" +printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "EVENT_HANDLER_NODE_INDEX_GE=$EVENT_HANDLER_NODE_INDEX_GE\n" printf "EVENT_HANDLER_NODE_INDEX_LE=$EVENT_HANDLER_NODE_INDEX_LE\n" diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 916ca2fd0..5272966f0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -131,8 +131,8 @@ EVENT_HANDLER_NODE_INDEX_LE=4 printf "\n" printf "JSON_RPC_NODE_INDEX_GE=$JSON_RPC_NODE_INDEX_GE\n" printf "JSON_RPC_NODE_INDEX_LE=$JSON_RPC_NODE_INDEX_LE\n" -printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "REST_FUNC_NODE_INDEX_GE=$REST_FUNC_NODE_INDEX_GE\n" +printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "EVENT_HANDLER_NODE_INDEX_GE=$EVENT_HANDLER_NODE_INDEX_GE\n" printf "EVENT_HANDLER_NODE_INDEX_LE=$EVENT_HANDLER_NODE_INDEX_LE\n" diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index f2ad47dec..0c0e71165 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -116,8 +116,8 @@ EVENT_HANDLER_NODE_INDEX_LE=4 printf "\n" printf "JSON_RPC_NODE_INDEX_GE=$JSON_RPC_NODE_INDEX_GE\n" printf "JSON_RPC_NODE_INDEX_LE=$JSON_RPC_NODE_INDEX_LE\n" -printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "REST_FUNC_NODE_INDEX_GE=$REST_FUNC_NODE_INDEX_GE\n" +printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" printf "EVENT_HANDLER_NODE_INDEX_GE=$EVENT_HANDLER_NODE_INDEX_GE\n" printf "EVENT_HANDLER_NODE_INDEX_LE=$EVENT_HANDLER_NODE_INDEX_LE\n" From 916bd41af4a394f9240c845d29d01ab5e69bb645 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 1 Aug 2024 21:23:53 +0900 Subject: [PATCH 27/46] Fix PEER_CANDIDATE_JSON_RPC_URL for genesis onprem deploy --- start_node_genesis_onprem.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index a99615efd..f0c9c41f3 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -242,7 +242,7 @@ elif [[ "$SEASON" = "sandbox" ]]; then fi elif [[ $SEASON = 'staging' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-staging - export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.139.219:8080/json-rpc" + export PEER_CANDIDATE_JSON_RPC_URL="http://101.202.37.2:8080/json-rpc" if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" fi From 93ee5ad966bc8a0d2d8b0bb3ff60182d46e6b425 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 5 Aug 2024 11:30:56 +0900 Subject: [PATCH 28/46] Add p2p ip address whitelisting --- p2p/p2p-util.js | 11 +++++-- test/unit/p2p-util.test.js | 62 +++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/p2p/p2p-util.js b/p2p/p2p-util.js index 53cf1cfef..17d833253 100644 --- a/p2p/p2p-util.js +++ b/p2p/p2p-util.js @@ -178,6 +178,12 @@ class P2pUtil { return CommonUtil.isValidIpV4(ipAddress) || CommonUtil.isValidIpV6(ipAddress); } + // NOTE(platfowner): Need whitelisting due to the internal networking config of comcom hosting env. + static isWhitelistedIpAddress(ipAddress) { + const whitelistedIpAddressRegex = /192.168.\d+.2/gm; + return CommonUtil.isString(ipAddress) ? whitelistedIpAddressRegex.test(ipAddress) : false; + } + /** * Returns true if the socket ip address is the same as the given p2p url ip address, * false otherwise. @@ -187,9 +193,10 @@ class P2pUtil { static checkIpAddressFromPeerInfo(ipAddressFromSocket, ipAddressFromPeerInfo) { if (!P2pUtil.isValidIpAddress(ipAddressFromSocket) || !P2pUtil.isValidIpAddress(ipAddressFromPeerInfo)) { - return false; + return false; } else { - return ip.isEqual(ipAddressFromSocket, ipAddressFromPeerInfo); + return ip.isEqual(ipAddressFromSocket, ipAddressFromPeerInfo) + || P2pUtil.isWhitelistedIpAddress(ipAddressFromSocket); } } diff --git a/test/unit/p2p-util.test.js b/test/unit/p2p-util.test.js index e1454d0d1..915241f16 100644 --- a/test/unit/p2p-util.test.js +++ b/test/unit/p2p-util.test.js @@ -376,7 +376,7 @@ describe("P2P Util", () => { expect(util.isValidIpAddress(url5)).to.be.false; }); - it("returns true if valid ip address is set", () => { + it("returns true if valid ip address is given", () => { const ipV4 = '172.20.10.2'; const ipV6 = '::ffff:172.20.10.2'; @@ -385,6 +385,52 @@ describe("P2P Util", () => { }); }); + describe("isWhitelistedIpAddress", () => { + it("returns false if invalid ipAddress is given", () => { + const stringValue = 'stringValue'; + const numberValue = 123456789; + const booleanValue = true; + const nullValue = null; + const undefinedValue = undefined; + const arrayValue = []; + const objectValue = {}; + const url1 = 'ainetwork.ai'; + const url2 = 'https://*.ainetwork.ai'; + const url3 = 'http://172.16.0.36:8080'; + const url4 = 'http://172.16.0.36'; + const url5 = 'http://172.16.0.36:8080/json-rpc'; + const ipAddr1 = '172.16.0.36'; + const ipAddr2 = '::ffff:172.16.0.36'; + + expect(util.isWhitelistedIpAddress(stringValue)).to.be.false; + expect(util.isWhitelistedIpAddress(numberValue)).to.be.false; + expect(util.isWhitelistedIpAddress(booleanValue)).to.be.false; + expect(util.isWhitelistedIpAddress(nullValue)).to.be.false; + expect(util.isWhitelistedIpAddress(undefinedValue)).to.be.false; + expect(util.isWhitelistedIpAddress(arrayValue)).to.be.false; + expect(util.isWhitelistedIpAddress(objectValue)).to.be.false; + expect(util.isWhitelistedIpAddress(url1)).to.be.false; + expect(util.isWhitelistedIpAddress(url2)).to.be.false; + expect(util.isWhitelistedIpAddress(url3)).to.be.false; + expect(util.isWhitelistedIpAddress(url4)).to.be.false; + expect(util.isWhitelistedIpAddress(url5)).to.be.false; + expect(util.isWhitelistedIpAddress(ipAddr1)).to.be.false; + expect(util.isWhitelistedIpAddress(ipAddr2)).to.be.false; + }); + + it("returns true if whitelisted ip address is given", () => { + const ipV4Addr1 = '192.168.92.2'; + const ipV4Addr2 = '192.168.93.2'; + const ipV6Addr1 = '::ffff:192.168.92.2'; + const ipV6Addr2 = '::ffff:192.168.93.2'; + + expect(util.isWhitelistedIpAddress(ipV4Addr1)).to.be.true; + expect(util.isWhitelistedIpAddress(ipV4Addr2)).to.be.true; + expect(util.isWhitelistedIpAddress(ipV6Addr1)).to.be.true; + expect(util.isWhitelistedIpAddress(ipV6Addr2)).to.be.true; + }); + }); + describe("checkIpAddressFromPeerInfo", () => { it("returns false if the give ip addresses are not the same", () => { const ip1 = '172.20.10.1'; @@ -406,6 +452,20 @@ describe("P2P Util", () => { expect(util.checkIpAddressFromPeerInfo(ipV4, ipV6)).to.be.true; }); + + it("returns true for whitelisted ip addresses", () => { + const ip1 = '::ffff:192.168.92.2'; + const ip2 = '101.202.37.2'; + + expect(util.checkIpAddressFromPeerInfo(ip1, ip2)).to.be.true; + }); + + it("returns false for non-whitelisted ip addresses", () => { + const ip1 = '::ffff:101.202.37.2'; + const ip2 = '192.168.92.2'; + + expect(util.checkIpAddressFromPeerInfo(ip1, ip2)).to.be.false; + }); }); describe("isValidJsonRpcUrl", () => { From 61a8aa9a7f4d7fac077db0caed41298288e0a79e Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 13:07:44 +0900 Subject: [PATCH 29/46] Add getEventHandlerStatus() --- event-handler/index.js | 24 +++++++++++++++++++++--- node/index.js | 4 ++++ p2p/server.js | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/event-handler/index.js b/event-handler/index.js index aa0077ef4..9b94cdc3c 100644 --- a/event-handler/index.js +++ b/event-handler/index.js @@ -9,9 +9,7 @@ const EventFilter = require('./event-filter'); const BlockchainEvent = require('./blockchain-event'); const EventHandlerError = require('./event-handler-error'); const { EventHandlerErrorCode } = require('../common/result-code'); -const { - NodeConfigs, -} = require('../common/constants'); +const { NodeConfigs } = require('../common/constants'); class EventHandler { constructor(node) { @@ -28,6 +26,26 @@ class EventHandler { this.run(); } + getEventHandlerStatus() { + return { + isEnabled: true, + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: this.eventChannelManager.getNumEventChannels(), + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: this.getNumEventFilters(), + }; + } + + static getDefaultEventHandlerStatus() { + return { + isEnabled: false, + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: 0, + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: 0, + }; + } + run() { const LOG_HEADER = 'run'; this.eventChannelManager.startListening(); diff --git a/node/index.js b/node/index.js index 902eef579..8c4a53860 100644 --- a/node/index.js +++ b/node/index.js @@ -77,6 +77,10 @@ class BlockchainNode { } } + getEventHandlerStatus() { + return this.eh ? this.eh.getEventHandlerStatus() : EventHandler.getDefaultEventHandlerStatus(); + } + setAccount(account) { this.account = account; this.bootstrapAccount = null; diff --git a/p2p/server.js b/p2p/server.js index e58b97211..3b6fdf1af 100644 --- a/p2p/server.js +++ b/p2p/server.js @@ -197,6 +197,7 @@ class P2pServer { nonce: this.node.getNonce(), dbStatus: this.getDbStatus(), stateVersionStatus: this.getStateVersionStatus(), + eventHandlerStatus: this.node.getEventHandlerStatus(), }; } From f3b48827334db2aa2ff43e860808ff5268138d51 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 13:29:34 +0900 Subject: [PATCH 30/46] Update tests --- test/unit/p2p.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/p2p.test.js b/test/unit/p2p.test.js index 079f58cbc..b9a6a224a 100644 --- a/test/unit/p2p.test.js +++ b/test/unit/p2p.test.js @@ -222,6 +222,13 @@ describe("P2p", () => { numVersions: 4, versionList: 'erased', finalVersion: 'FINAL:0' + }, + eventHandlerStatus: { + isEnabled: false, + maxNumEventChannels: 10, + maxNumEventFilters: 20, + numEventChannels: 0, + numEventFilters: 0, } }); }); From c5f71789698618dcf5851217b7c40aee6bfbc3ea Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 18:06:21 +0900 Subject: [PATCH 31/46] Reuse existing ip addresses in event handler --- event-handler/event-channel-manager.js | 5 ++--- json_rpc/event-handler.js | 6 +++--- test/unit/event-handler.test.js | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index a57d1245e..c9b700089 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -23,12 +23,11 @@ class EventChannelManager { this.heartbeatInterval = null; } - async getNetworkInfo() { - const ipAddr = await getIpAddress(NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL); + getNetworkInfo() { + const ipAddr = (NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL) ? this.node.ipAddrInternal : this.node.ipAddrExternal; const eventHandlerUrl = new URL(`ws://${ipAddr}:${NodeConfigs.EVENT_HANDLER_PORT}`); return { url: eventHandlerUrl.toString(), - port: NodeConfigs.EVENT_HANDLER_PORT, maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, numEventChannels: this.getNumEventChannels(), maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, diff --git a/json_rpc/event-handler.js b/json_rpc/event-handler.js index 7141ab6a8..9efb47b65 100644 --- a/json_rpc/event-handler.js +++ b/json_rpc/event-handler.js @@ -8,12 +8,12 @@ const { JSON_RPC_METHODS } = require('./constants'); module.exports = function getEventHandlerApis(eventHandler) { return { // NOTE(cshcomcom): Async function doesn't need a done parameter. (Ref: https://www.npmjs.com/package/jayson#promises) - [JSON_RPC_METHODS.NET_GET_EVENT_HANDLER_NETWORK_INFO]: async function(args) { + [JSON_RPC_METHODS.NET_GET_EVENT_HANDLER_NETWORK_INFO]: function(args, done) { const beginTime = Date.now(); - const result = await eventHandler.eventChannelManager.getNetworkInfo(); + const result = eventHandler.eventChannelManager.getNetworkInfo(); const latency = Date.now() - beginTime; trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - return JsonRpcUtil.addProtocolVersion({ result }); + done(null, JsonRpcUtil.addProtocolVersion({ result })); }, [JSON_RPC_METHODS.AIN_GET_EVENT_HANDLER_FILTER_INFO]: function(args, done) { diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 93400af85..4b8fdadfc 100644 --- a/test/unit/event-handler.test.js +++ b/test/unit/event-handler.test.js @@ -372,14 +372,13 @@ describe('EventHandler Test', () => { it('getNetworkInfo', async () => { const intIp = await getIpAddress(true); const intUrl = new URL(`ws://${intIp}:${NodeConfigs.EVENT_HANDLER_PORT}`); - const networkInfo = await eventChannelManager.getNetworkInfo(); + const networkInfo = eventChannelManager.getNetworkInfo(); assert.deepEqual(networkInfo, { + url: intUrl.toString(), maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, numEventChannels: 0, maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: 0, - url: intUrl.toString(), - port: NodeConfigs.EVENT_HANDLER_PORT, }); }); }); From 109292a34e56d8d4b311334a6239f4b8c4a7d485 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 18:07:26 +0900 Subject: [PATCH 32/46] Include more in the event handler status --- event-handler/index.js | 20 ++++++++++++-------- test/unit/p2p.test.js | 15 +++++++++++---- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/event-handler/index.js b/event-handler/index.js index 9b94cdc3c..81d8042fc 100644 --- a/event-handler/index.js +++ b/event-handler/index.js @@ -29,20 +29,24 @@ class EventHandler { getEventHandlerStatus() { return { isEnabled: true, - maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, - numEventChannels: this.eventChannelManager.getNumEventChannels(), - maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, - numEventFilters: this.getNumEventFilters(), + networkInfo: this.eventChannelManager.getNetworkInfo(), + filterInfo: this.getFilterInfo(), + channelInfo: this.eventChannelManager.getChannelInfo(), }; } static getDefaultEventHandlerStatus() { return { isEnabled: false, - maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, - numEventChannels: 0, - maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, - numEventFilters: 0, + networkInfo: { + url: "", + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: 0, + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: 0, + }, + filterInfo: {}, + channelInfo: {}, }; } diff --git a/test/unit/p2p.test.js b/test/unit/p2p.test.js index b9a6a224a..a17b6a82c 100644 --- a/test/unit/p2p.test.js +++ b/test/unit/p2p.test.js @@ -225,10 +225,17 @@ describe("P2p", () => { }, eventHandlerStatus: { isEnabled: false, - maxNumEventChannels: 10, - maxNumEventFilters: 20, - numEventChannels: 0, - numEventFilters: 0, + networkInfo: { + url: "", + maxNumEventChannels: 10, + numEventChannels: 0, + maxNumEventFilters: 20, + numEventFilters: 0, + }, + filterInfo: { + }, + channelInfo: { + }, } }); }); From 2b7b861ed1ff5c4def29b77f58e76c7568b906fc Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 18:59:09 +0900 Subject: [PATCH 33/46] Fix broken tests --- test/unit/event-handler.test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 4b8fdadfc..830f52095 100644 --- a/test/unit/event-handler.test.js +++ b/test/unit/event-handler.test.js @@ -26,6 +26,8 @@ class MockWebSockect { } describe('EventHandler Test', () => { + let ipAddrInternal = null; + let ipAddrExternal = null; let eventHandler = null; let node = null; const origianlfilterDeletionTimeout = NodeConfigs.EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS; @@ -35,6 +37,9 @@ describe('EventHandler Test', () => { // NOTE(ehgmsdk20): Reduce EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS for faster test NodeConfigs.EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS = 10000; node = new BlockchainNode(); + ipAddrInternal = await getIpAddress(true); + ipAddrExternal = await getIpAddress(false); + node.setIpAddresses(ipAddrInternal, ipAddrExternal); eventHandler = node.eh; }); @@ -370,11 +375,10 @@ describe('EventHandler Test', () => { }) it('getNetworkInfo', async () => { - const intIp = await getIpAddress(true); - const intUrl = new URL(`ws://${intIp}:${NodeConfigs.EVENT_HANDLER_PORT}`); + const eventHandlerUrl = new URL(`ws://${ipAddrInternal}:${NodeConfigs.EVENT_HANDLER_PORT}`); const networkInfo = eventChannelManager.getNetworkInfo(); assert.deepEqual(networkInfo, { - url: intUrl.toString(), + url: eventHandlerUrl.toString(), maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, numEventChannels: 0, maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, From 92615b5c0e7e0fae9ba672c487c1467d738677dd Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 13:24:07 +0900 Subject: [PATCH 34/46] Add EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS node config parameter --- blockchain-configs/afan-shard/node_params.json | 1 + blockchain-configs/base/node_params.json | 1 + blockchain-configs/he-shard/node_params.json | 1 + blockchain-configs/mainnet-prod/node_params.json | 1 + blockchain-configs/sim-shard/node_params.json | 1 + blockchain-configs/testnet-dev/node_params.json | 1 + blockchain-configs/testnet-exp/node_params.json | 1 + blockchain-configs/testnet-prod/node_params.json | 1 + blockchain-configs/testnet-sandbox/node_params.json | 1 + blockchain-configs/testnet-staging/node_params.json | 1 + 10 files changed, 10 insertions(+) diff --git a/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index 78c5dab93..39dc161d2 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/base/node_params.json b/blockchain-configs/base/node_params.json index 6b43df148..3382f8f74 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/he-shard/node_params.json b/blockchain-configs/he-shard/node_params.json index 612b441f9..5a8db9077 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/mainnet-prod/node_params.json b/blockchain-configs/mainnet-prod/node_params.json index 9a7743e73..761577214 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -27,6 +27,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/sim-shard/node_params.json b/blockchain-configs/sim-shard/node_params.json index ec274b413..1104cf520 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-dev/node_params.json b/blockchain-configs/testnet-dev/node_params.json index ec1ba0a0b..c9b13d139 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-exp/node_params.json b/blockchain-configs/testnet-exp/node_params.json index 4144f6548..8a0cda0a9 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-prod/node_params.json b/blockchain-configs/testnet-prod/node_params.json index 016e85803..750f6a28b 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-sandbox/node_params.json b/blockchain-configs/testnet-sandbox/node_params.json index 7e41c7c0c..438f6911a 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-staging/node_params.json b/blockchain-configs/testnet-staging/node_params.json index 088ff3a39..f20c979a2 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, From e0e280ae1f1132047aac21077ef5170b82b92a4b Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 19:21:30 +0900 Subject: [PATCH 35/46] Terminate websocket when there are errors in making connection --- event-handler/event-channel-manager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index c9b700089..1b62a4b3d 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -67,12 +67,14 @@ class EventChannelManager { const LOG_HEADER = 'handleConnection'; try { if (this.getNumEventChannels() >= NodeConfigs.MAX_NUM_EVENT_CHANNELS) { + webSocket.terminate(); throw new EventHandlerError(EventHandlerErrorCode.EVENT_CHANNEL_EXCEEDS_SIZE_LIMIT, `The number of event channels exceeds its limit ` + `(${NodeConfigs.MAX_NUM_EVENT_CHANNELS})`); } const channelId = Date.now(); // NOTE: Only used in blockchain if (this.channels[channelId]) { // TODO(cshcomcom): Retry logic. + webSocket.terminate(); throw new EventHandlerError(EventHandlerErrorCode.DUPLICATED_CHANNEL_ID, `Channel ID ${channelId} is already in use`); } From 21f8d580fa6814a704777a0cdb4d42b4cb796b4b Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 20:02:19 +0900 Subject: [PATCH 36/46] Add EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS node config param --- blockchain-configs/afan-shard/node_params.json | 1 + blockchain-configs/base/node_params.json | 1 + blockchain-configs/he-shard/node_params.json | 1 + blockchain-configs/mainnet-prod/node_params.json | 1 + blockchain-configs/sim-shard/node_params.json | 1 + blockchain-configs/testnet-dev/node_params.json | 1 + blockchain-configs/testnet-exp/node_params.json | 1 + blockchain-configs/testnet-prod/node_params.json | 1 + blockchain-configs/testnet-sandbox/node_params.json | 1 + blockchain-configs/testnet-staging/node_params.json | 1 + 10 files changed, 10 insertions(+) diff --git a/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index 39dc161d2..3106838b3 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/base/node_params.json b/blockchain-configs/base/node_params.json index 3382f8f74..66a44caf4 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/he-shard/node_params.json b/blockchain-configs/he-shard/node_params.json index 5a8db9077..4b566ce35 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/mainnet-prod/node_params.json b/blockchain-configs/mainnet-prod/node_params.json index 761577214..6a1887d0b 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -27,6 +27,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/sim-shard/node_params.json b/blockchain-configs/sim-shard/node_params.json index 1104cf520..c4fd4920c 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/testnet-dev/node_params.json b/blockchain-configs/testnet-dev/node_params.json index c9b13d139..3a384e85c 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/testnet-exp/node_params.json b/blockchain-configs/testnet-exp/node_params.json index 8a0cda0a9..7fe684a48 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/testnet-prod/node_params.json b/blockchain-configs/testnet-prod/node_params.json index 750f6a28b..a60dd1927 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/testnet-sandbox/node_params.json b/blockchain-configs/testnet-sandbox/node_params.json index 438f6911a..1227ed8d1 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, diff --git a/blockchain-configs/testnet-staging/node_params.json b/blockchain-configs/testnet-staging/node_params.json index f20c979a2..787cbc358 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -28,6 +28,7 @@ "ENABLE_REST_FUNCTION_CALL": false, "ENABLE_STATUS_REPORT_TO_TRACKER": true, "ENABLE_TX_SIG_VERIF_WORKAROUND": false, + "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, From 058694292598c66e86c80f59cd2cd6f86790a263 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 20:33:47 +0900 Subject: [PATCH 37/46] Add event handler channel idle checking logic --- event-handler/event-channel-manager.js | 24 +++++++++++++++++++++++- event-handler/event-channel.js | 6 ++++++ test/unit/event-handler.test.js | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index 1b62a4b3d..2f97e5b76 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -21,6 +21,7 @@ class EventChannelManager { this.channels = {}; // [channelId]: Channel this.filterIdToChannelId = {}; // [globalFilterId]: channelId this.heartbeatInterval = null; + this.idleCheckInterval = null; } getNetworkInfo() { @@ -32,6 +33,7 @@ class EventChannelManager { numEventChannels: this.getNumEventChannels(), maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: this.node.eh.getNumEventFilters(), + channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS, } } @@ -61,6 +63,7 @@ class EventChannelManager { this.handleConnection(ws); }); this.startHeartbeat(this.wsServer); + this.startIdleCheck(); } handleConnection(webSocket) { @@ -101,6 +104,7 @@ class EventChannelManager { if (messageType === BlockchainEventMessageTypes.PONG) { this.handlePong(webSocket); } else { + channel.setLastMessagingTimeMs(Date.now()); this.handleMessage(channel, messageType, messageData); } } catch (err) { @@ -310,6 +314,7 @@ class EventChannelManager { close() { const LOG_HEADER = 'close'; this.stopHeartbeat(); + this.stopIdleCheck(); this.wsServer.close(() => { logger.info(`[${LOG_HEADER}] Closed event channel manager's socket`); }); @@ -342,7 +347,20 @@ class EventChannelManager { ws.isAlive = false; this.sendPing(ws); }); - }, NodeConfigs.EVENT_HANDLER_HEARTBEAT_INTERVAL_MS || 15000); + }, NodeConfigs.EVENT_HANDLER_HEARTBEAT_INTERVAL_MS); + } + + startIdleCheck() { + this.idleCheckInterval = setInterval(() => { + for (const channel of Object.values(this.channels)) { + const idleTimeMs = Date.now() - channel.lastMessagingTimeMs; + if (idleTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS * 1000) { + logger.info(`[${LOG_HEADER}] Closing idle channel: `, channel.toObject()); + channel.webSocket.terminate(); + this.closeChannel(channel); + } + } + }, NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS); } sendPing(webSocket) { @@ -353,6 +371,10 @@ class EventChannelManager { stopHeartbeat() { clearInterval(this.heartbeatInterval); } + + stopIdleCheck() { + clearInterval(this.idleCheckInterval); + } } module.exports = EventChannelManager; diff --git a/event-handler/event-channel.js b/event-handler/event-channel.js index aceb88014..b916ce989 100644 --- a/event-handler/event-channel.js +++ b/event-handler/event-channel.js @@ -3,6 +3,11 @@ class EventChannel { this.id = id; this.webSocket = webSocket; this.eventFilterIds = new Set(); + this.lastMessagingTimeMs = Date.now(); + } + + setLastMessagingTimeMs(timeMs) { + this.lastMessagingTimeMs = timeMs; } getFilterIdsSize() { @@ -25,6 +30,7 @@ class EventChannel { return { id: this.id, eventFilterIds: [...this.eventFilterIds], + lastMessagingTimeMs: this.lastMessagingTimeMs, }; } } diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 830f52095..543c360fb 100644 --- a/test/unit/event-handler.test.js +++ b/test/unit/event-handler.test.js @@ -383,6 +383,7 @@ describe('EventHandler Test', () => { numEventChannels: 0, maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: 0, + channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS, }); }); }); From 3e282378496294ec4db0725fffed61978f372c80 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 21:15:30 +0900 Subject: [PATCH 38/46] Add remoteUrl and idleTimeMs to channel info --- common/network-util.js | 8 +++++++- event-handler/event-channel-manager.js | 4 ++-- event-handler/event-channel.js | 5 +++++ p2p/server.js | 10 +++------- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/common/network-util.js b/common/network-util.js index cfca678ec..7878ba39c 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -143,10 +143,16 @@ function getIpAddress(internal = false) { }); } +// NOTE(minsulee2): This builds the URL using a client socket in the server side. +function buildRemoteUrlFromSocket(socket) { + return `${socket._socket.remoteAddress}:${socket._socket.remotePort}`; +} + module.exports = { sendTxAndWaitForFinalization, sendSignedTx, signAndSendTx, sendGetRequest, - getIpAddress + getIpAddress, + buildRemoteUrlFromSocket, }; diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index 2f97e5b76..0bd688d67 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -1,7 +1,6 @@ const logger = new (require('../logger'))('EVENT_CHANNEL_MANAGER'); const EventChannel = require('./event-channel'); const ws = require('ws'); -const { getIpAddress } = require('../common/network-util'); const { BlockchainEventMessageTypes, NodeConfigs, @@ -351,11 +350,12 @@ class EventChannelManager { } startIdleCheck() { + const LOG_HEADER = 'startIdleCheck'; this.idleCheckInterval = setInterval(() => { for (const channel of Object.values(this.channels)) { const idleTimeMs = Date.now() - channel.lastMessagingTimeMs; if (idleTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS * 1000) { - logger.info(`[${LOG_HEADER}] Closing idle channel: `, channel.toObject()); + logger.info(`[${LOG_HEADER}] Closing idle channel: ${JSON.stringify(channel.toObject())}`); channel.webSocket.terminate(); this.closeChannel(channel); } diff --git a/event-handler/event-channel.js b/event-handler/event-channel.js index b916ce989..97a8d35ca 100644 --- a/event-handler/event-channel.js +++ b/event-handler/event-channel.js @@ -1,7 +1,10 @@ +const { buildRemoteUrlFromSocket } = require('../common/network-util'); + class EventChannel { constructor(id, webSocket) { this.id = id; this.webSocket = webSocket; + this.remoteUrl = buildRemoteUrlFromSocket(webSocket); this.eventFilterIds = new Set(); this.lastMessagingTimeMs = Date.now(); } @@ -29,8 +32,10 @@ class EventChannel { toObject() { return { id: this.id, + remoteUrl: this.remoteUrl, eventFilterIds: [...this.eventFilterIds], lastMessagingTimeMs: this.lastMessagingTimeMs, + idleTimeMs: Date.now() - this.lastMessagingTimeMs, }; } } diff --git a/p2p/server.js b/p2p/server.js index 3b6fdf1af..dc800d5a4 100644 --- a/p2p/server.js +++ b/p2p/server.js @@ -12,6 +12,7 @@ const sizeof = require('object-sizeof'); const Consensus = require('../consensus'); const Transaction = require('../tx-pool/transaction'); const VersionUtil = require('../common/version-util'); +const { buildRemoteUrlFromSocket } = require('../common/network-util'); const { DevFlags, BlockchainConsts, @@ -88,7 +89,7 @@ class P2pServer { } }); this.wsServer.on('connection', (socket) => { - const url = this.buildRemoteUrlFromSocket(socket); + const url = buildRemoteUrlFromSocket(socket); P2pUtil.addPeerConnection(this.peerConnectionsInProgress, url); if (Object.keys(this.inbound).length + this.peerConnectionsInProgress.size <= NodeConfigs.MAX_NUM_INBOUND_CONNECTION) { @@ -106,11 +107,6 @@ class P2pServer { this.urls = this.initUrls(); } - // NOTE(minsulee2): This builds the URL using a client socket in the server side. - buildRemoteUrlFromSocket(socket) { - return `${socket._socket.remoteAddress}:${socket._socket.remotePort}`; - } - getNodeAddress() { return this.node.account ? this.node.account.address : null; } @@ -721,7 +717,7 @@ class P2pServer { }); socket.on('close', () => { - const url = this.buildRemoteUrlFromSocket(socket); + const url = buildRemoteUrlFromSocket(socket); P2pUtil.removeFromPeerConnectionsInProgress(this.peerConnectionsInProgress, url); const address = P2pUtil.getAddressFromSocket(this.inbound, socket); P2pUtil.closeSocketSafe(this.inbound, socket); From 30cd90bbb32ad2bd0eaa96a0dfd63340ff683747 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 21:48:24 +0900 Subject: [PATCH 39/46] Fix buildRemoteUrlFromSocket() --- common/network-util.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/network-util.js b/common/network-util.js index 7878ba39c..81a004682 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -145,7 +145,9 @@ function getIpAddress(internal = false) { // NOTE(minsulee2): This builds the URL using a client socket in the server side. function buildRemoteUrlFromSocket(socket) { - return `${socket._socket.remoteAddress}:${socket._socket.remotePort}`; + const remoteAddress = _.get(socket, '_socket.remoteAddress', ''); + const remotePort = _.get(socket, '_socket.remotePort', ''); + return `${remoteAddress}:${remotePort}`; } module.exports = { From ade1d7298c5c08ccc27ca3bbfa721e46eb8469cc Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Aug 2024 22:17:43 +0900 Subject: [PATCH 40/46] Use external ip address in the network info --- event-handler/event-channel-manager.js | 2 +- test/unit/event-handler.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index 0bd688d67..6a4802a9c 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -24,7 +24,7 @@ class EventChannelManager { } getNetworkInfo() { - const ipAddr = (NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL) ? this.node.ipAddrInternal : this.node.ipAddrExternal; + const ipAddr = this.node.ipAddrExternal; const eventHandlerUrl = new URL(`ws://${ipAddr}:${NodeConfigs.EVENT_HANDLER_PORT}`); return { url: eventHandlerUrl.toString(), diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 543c360fb..579ed6bed 100644 --- a/test/unit/event-handler.test.js +++ b/test/unit/event-handler.test.js @@ -375,7 +375,7 @@ describe('EventHandler Test', () => { }) it('getNetworkInfo', async () => { - const eventHandlerUrl = new URL(`ws://${ipAddrInternal}:${NodeConfigs.EVENT_HANDLER_PORT}`); + const eventHandlerUrl = new URL(`ws://${ipAddrExternal}:${NodeConfigs.EVENT_HANDLER_PORT}`); const networkInfo = eventChannelManager.getNetworkInfo(); assert.deepEqual(networkInfo, { url: eventHandlerUrl.toString(), From 942b8849a9fea14bbd2f1bfafa00372d4959b174 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 09:40:05 +0900 Subject: [PATCH 41/46] Add channelLifeTimeMs and channelIdleTimeMs to channel status --- event-handler/event-channel-manager.js | 33 +++++++++++++++++++++++++- event-handler/event-channel.js | 15 ++++++++++-- event-handler/index.js | 27 +++++++++++++++++---- test/unit/event-handler.test.js | 1 - test/unit/p2p.test.js | 13 ++++++++-- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index 6a4802a9c..a5d40bf52 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -32,7 +32,18 @@ class EventChannelManager { numEventChannels: this.getNumEventChannels(), maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: this.node.eh.getNumEventFilters(), + } + } + + getChannelStatus() { + const channelStats = this.getChannelStats(); + return { + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: this.getNumEventChannels(), channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS, + maxChannelLifeTimeMs: channelStats.maxLifeTimeMs, + maxChannelIdleTimeMs: channelStats.maxIdleTimeMs, + channelInfo: this.getChannelInfo(), } } @@ -40,6 +51,26 @@ class EventChannelManager { return Object.keys(this.channels).length; } + getChannelStats() { + let maxLifeTimeMs = 0; + let maxIdleTimeMs = 0; + for (const channel of Object.values(this.channels)) { + const lifeTimeMs = channel.getLifeTimeMs(); + const idleTimeMs = channel.getIdleTimeMs(); + if (lifeTimeMs > maxLifeTimeMs) { + maxLifeTimeMs = lifeTimeMs; + } + if (idleTimeMs > maxIdleTimeMs) { + maxIdleTimeMs = idleTimeMs; + } + } + + return { + maxLifeTimeMs: maxLifeTimeMs, + maxIdleTimeMs: maxIdleTimeMs, + } + } + getChannelInfo() { const channelInfo = {}; for (const [channelId, channel] of Object.entries(this.channels)) { @@ -353,7 +384,7 @@ class EventChannelManager { const LOG_HEADER = 'startIdleCheck'; this.idleCheckInterval = setInterval(() => { for (const channel of Object.values(this.channels)) { - const idleTimeMs = Date.now() - channel.lastMessagingTimeMs; + const idleTimeMs = channel.getIdleTimeMs(); if (idleTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS * 1000) { logger.info(`[${LOG_HEADER}] Closing idle channel: ${JSON.stringify(channel.toObject())}`); channel.webSocket.terminate(); diff --git a/event-handler/event-channel.js b/event-handler/event-channel.js index 97a8d35ca..797e360ab 100644 --- a/event-handler/event-channel.js +++ b/event-handler/event-channel.js @@ -6,7 +6,9 @@ class EventChannel { this.webSocket = webSocket; this.remoteUrl = buildRemoteUrlFromSocket(webSocket); this.eventFilterIds = new Set(); - this.lastMessagingTimeMs = Date.now(); + const curTimeMs = Date.now(); + this.creationTimeMs = curTimeMs; + this.lastMessagingTimeMs = curTimeMs; } setLastMessagingTimeMs(timeMs) { @@ -29,13 +31,22 @@ class EventChannel { return this.eventFilterIds.delete(filterId); } + getLifeTimeMs() { + return Date.now() - this.creationTimeMs; + } + + getIdleTimeMs() { + return Date.now() - this.lastMessagingTimeMs; + } + toObject() { return { id: this.id, remoteUrl: this.remoteUrl, eventFilterIds: [...this.eventFilterIds], lastMessagingTimeMs: this.lastMessagingTimeMs, - idleTimeMs: Date.now() - this.lastMessagingTimeMs, + lifeTimeMs: this.getLifeTimeMs(), + idleTimeMs: this.getIdleTimeMs(), }; } } diff --git a/event-handler/index.js b/event-handler/index.js index 81d8042fc..61bf76d03 100644 --- a/event-handler/index.js +++ b/event-handler/index.js @@ -30,8 +30,8 @@ class EventHandler { return { isEnabled: true, networkInfo: this.eventChannelManager.getNetworkInfo(), - filterInfo: this.getFilterInfo(), - channelInfo: this.eventChannelManager.getChannelInfo(), + channelStatus: this.eventChannelManager.getChannelStatus(), + filterStatus: this.getFilterStatus(), }; } @@ -45,8 +45,19 @@ class EventHandler { maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: 0, }, - filterInfo: {}, - channelInfo: {}, + channelStatus: { + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: 0, + channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS, + maxChannelLifeTimeMs: 0, + maxChannelIdleTimeMs: 0, + channelInfo: {}, + }, + filterStatus: { + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: 0, + filterInfo: {}, + }, }; } @@ -66,6 +77,14 @@ class EventHandler { return true; } + getFilterStatus() { + return { + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: this.getNumEventFilters(), + filterInfo: this.getFilterInfo(), + }; + } + getNumEventFilters() { return Object.keys(this.eventFilters).length; } diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 579ed6bed..cad39c565 100644 --- a/test/unit/event-handler.test.js +++ b/test/unit/event-handler.test.js @@ -383,7 +383,6 @@ describe('EventHandler Test', () => { numEventChannels: 0, maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, numEventFilters: 0, - channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS, }); }); }); diff --git a/test/unit/p2p.test.js b/test/unit/p2p.test.js index a17b6a82c..32cccd515 100644 --- a/test/unit/p2p.test.js +++ b/test/unit/p2p.test.js @@ -232,9 +232,18 @@ describe("P2p", () => { maxNumEventFilters: 20, numEventFilters: 0, }, - filterInfo: { + channelStatus: { + maxNumEventChannels: 10, + numEventChannels: 0, + channelIdleTimeLimitSecs: 600, + maxChannelIdleTimeMs: 0, + maxChannelLifeTimeMs: 0, + channelInfo: {}, }, - channelInfo: { + filterStatus: { + maxNumEventFilters: 20, + numEventFilters: 0, + filterInfo: {}, }, } }); From b3fcce620976d04ececca9db731115aa2f20c6ee Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 09:52:54 +0900 Subject: [PATCH 42/46] Apply life time check to event handler channels --- blockchain-configs/afan-shard/node_params.json | 1 + blockchain-configs/base/node_params.json | 1 + blockchain-configs/he-shard/node_params.json | 1 + blockchain-configs/mainnet-prod/node_params.json | 1 + blockchain-configs/sim-shard/node_params.json | 1 + blockchain-configs/testnet-dev/node_params.json | 1 + blockchain-configs/testnet-exp/node_params.json | 1 + blockchain-configs/testnet-prod/node_params.json | 1 + blockchain-configs/testnet-sandbox/node_params.json | 1 + blockchain-configs/testnet-staging/node_params.json | 1 + event-handler/event-channel-manager.js | 8 +++++++- 11 files changed, 17 insertions(+), 1 deletion(-) diff --git a/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index 3106838b3..503b1d188 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/base/node_params.json b/blockchain-configs/base/node_params.json index 66a44caf4..479935dc9 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/he-shard/node_params.json b/blockchain-configs/he-shard/node_params.json index 4b566ce35..a5db179a9 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/mainnet-prod/node_params.json b/blockchain-configs/mainnet-prod/node_params.json index 6a1887d0b..3a632eb80 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -29,6 +29,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/sim-shard/node_params.json b/blockchain-configs/sim-shard/node_params.json index c4fd4920c..6dbdf0934 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-dev/node_params.json b/blockchain-configs/testnet-dev/node_params.json index 3a384e85c..78a8a2e2e 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-exp/node_params.json b/blockchain-configs/testnet-exp/node_params.json index 7fe684a48..4d1b941ae 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-prod/node_params.json b/blockchain-configs/testnet-prod/node_params.json index a60dd1927..12ace5ef3 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-sandbox/node_params.json b/blockchain-configs/testnet-sandbox/node_params.json index 1227ed8d1..42ad83925 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/blockchain-configs/testnet-staging/node_params.json b/blockchain-configs/testnet-staging/node_params.json index 787cbc358..6de815392 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -30,6 +30,7 @@ "ENABLE_TX_SIG_VERIF_WORKAROUND": false, "EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS": 10000, "EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS": 600, + "EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index a5d40bf52..32f0a108a 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -386,7 +386,13 @@ class EventChannelManager { for (const channel of Object.values(this.channels)) { const idleTimeMs = channel.getIdleTimeMs(); if (idleTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS * 1000) { - logger.info(`[${LOG_HEADER}] Closing idle channel: ${JSON.stringify(channel.toObject())}`); + logger.info(`[${LOG_HEADER}] Closing long-idle channel: ${JSON.stringify(channel.toObject())}`); + channel.webSocket.terminate(); + this.closeChannel(channel); + } + const lifeTimeMs = channel.getLifeTimeMs(); + if (lifeTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS * 1000) { + logger.info(`[${LOG_HEADER}] Closing long-life channel: ${JSON.stringify(channel.toObject())}`); channel.webSocket.terminate(); this.closeChannel(channel); } From 3d8d103d87ec6b6aba14655fb62c37f35dd4dc34 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 11:23:56 +0900 Subject: [PATCH 43/46] Remove some dup code --- event-handler/event-channel-manager.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index 32f0a108a..3d6891595 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -353,7 +353,7 @@ class EventChannelManager { closeChannel(channel) { const LOG_HEADER = 'closeChannel'; try { - logger.info(`[${LOG_HEADER}] Close channel ${channel.id}`); + logger.info(`[${LOG_HEADER}] Closing channel ${channel.id}`); channel.webSocket.terminate(); const filterIds = channel.getAllFilterIds(); for (const filterId of filterIds) { @@ -363,7 +363,7 @@ class EventChannelManager { } delete this.channels[channel.id]; } catch (err) { - logger.error(`[${LOG_HEADER}] Error while close channel (channelId: ${channel.id}, ` + + logger.error(`[${LOG_HEADER}] Error while closing channel (channelId: ${channel.id}, ` + `message:${err.message})`); } } @@ -387,13 +387,11 @@ class EventChannelManager { const idleTimeMs = channel.getIdleTimeMs(); if (idleTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS * 1000) { logger.info(`[${LOG_HEADER}] Closing long-idle channel: ${JSON.stringify(channel.toObject())}`); - channel.webSocket.terminate(); this.closeChannel(channel); } const lifeTimeMs = channel.getLifeTimeMs(); if (lifeTimeMs > NodeConfigs.EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS * 1000) { logger.info(`[${LOG_HEADER}] Closing long-life channel: ${JSON.stringify(channel.toObject())}`); - channel.webSocket.terminate(); this.closeChannel(channel); } } From 3851e4ec4c73e8d143b83a344c7d17567ee226f9 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 14:44:50 +0900 Subject: [PATCH 44/46] Increase MAX_NUM_EVENT_CHANNELS and MAX_NUM_EVENT_FILTERS --- blockchain-configs/afan-shard/node_params.json | 4 ++-- blockchain-configs/base/node_params.json | 4 ++-- blockchain-configs/he-shard/node_params.json | 4 ++-- blockchain-configs/mainnet-prod/node_params.json | 4 ++-- blockchain-configs/sim-shard/node_params.json | 4 ++-- blockchain-configs/testnet-dev/node_params.json | 4 ++-- blockchain-configs/testnet-exp/node_params.json | 4 ++-- blockchain-configs/testnet-prod/node_params.json | 4 ++-- blockchain-configs/testnet-sandbox/node_params.json | 4 ++-- blockchain-configs/testnet-staging/node_params.json | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index 503b1d188..bd5d7036f 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 3, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/base/node_params.json b/blockchain-configs/base/node_params.json index 479935dc9..ecde6da71 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/he-shard/node_params.json b/blockchain-configs/he-shard/node_params.json index a5db179a9..68a07aa5c 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/mainnet-prod/node_params.json b/blockchain-configs/mainnet-prod/node_params.json index 3a632eb80..a7b7d410c 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -45,8 +45,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/sim-shard/node_params.json b/blockchain-configs/sim-shard/node_params.json index 6dbdf0934..c6b316c98 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/testnet-dev/node_params.json b/blockchain-configs/testnet-dev/node_params.json index 78a8a2e2e..8413a0637 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/testnet-exp/node_params.json b/blockchain-configs/testnet-exp/node_params.json index 4d1b941ae..a29a0365d 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/testnet-prod/node_params.json b/blockchain-configs/testnet-prod/node_params.json index 12ace5ef3..92c2445ed 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/testnet-sandbox/node_params.json b/blockchain-configs/testnet-sandbox/node_params.json index 42ad83925..a656eb622 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, diff --git a/blockchain-configs/testnet-staging/node_params.json b/blockchain-configs/testnet-staging/node_params.json index 6de815392..99d10ddf6 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -46,8 +46,8 @@ "MAX_FINALIZED_BLOCK_INFO_ON_MEM": 1000, "MAX_JSON_RPC_API_READ_RATE_LIMIT": 10, "MAX_JSON_RPC_API_WRITE_RATE_LIMIT": 1, - "MAX_NUM_EVENT_CHANNELS": 10, - "MAX_NUM_EVENT_FILTERS": 20, + "MAX_NUM_EVENT_CHANNELS": 20, + "MAX_NUM_EVENT_FILTERS": 40, "MAX_NUM_EVENT_FILTERS_PER_CHANNEL": 5, "MAX_NUM_INBOUND_CONNECTION": 6, "MAX_NUM_SNAPSHOTS": 10, From 2f3f9547186533b7d1251ef6734adabeb0682615 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 14:45:08 +0900 Subject: [PATCH 45/46] Update tests --- test/unit/p2p.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/p2p.test.js b/test/unit/p2p.test.js index 32cccd515..a304fa729 100644 --- a/test/unit/p2p.test.js +++ b/test/unit/p2p.test.js @@ -227,13 +227,13 @@ describe("P2p", () => { isEnabled: false, networkInfo: { url: "", - maxNumEventChannels: 10, + maxNumEventChannels: 20, numEventChannels: 0, - maxNumEventFilters: 20, + maxNumEventFilters: 40, numEventFilters: 0, }, channelStatus: { - maxNumEventChannels: 10, + maxNumEventChannels: 20, numEventChannels: 0, channelIdleTimeLimitSecs: 600, maxChannelIdleTimeMs: 0, @@ -241,7 +241,7 @@ describe("P2p", () => { channelInfo: {}, }, filterStatus: { - maxNumEventFilters: 20, + maxNumEventFilters: 40, numEventFilters: 0, filterInfo: {}, }, From fbc322614617a74dc29cde04b591ec1fa03a4ba3 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 9 Aug 2024 17:05:38 +0900 Subject: [PATCH 46/46] Upgrade package version to v1.4.0 --- client/protocol_versions.json | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/protocol_versions.json b/client/protocol_versions.json index 271fa237c..7c2edee79 100644 --- a/client/protocol_versions.json +++ b/client/protocol_versions.json @@ -146,5 +146,8 @@ }, "1.3.1": { "min": "1.0.0" + }, + "1.4.0": { + "min": "1.0.0" } } \ No newline at end of file diff --git a/package.json b/package.json index 2f7e4dbef..fdbac58bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ain-blockchain", "description": "AI Network Blockchain", - "version": "1.3.1", + "version": "1.4.0", "private": true, "license": "MIT", "author": "dev@ainetwork.ai",