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/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index 78c5dab93..bd5d7036f 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 6b43df148..ecde6da71 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 612b441f9..68a07aa5c 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 9a7743e73..a7b7d410c 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -27,6 +27,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -42,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 ec274b413..c6b316c98 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 ec1ba0a0b..8413a0637 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 4144f6548..a29a0365d 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 016e85803..92c2445ed 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 7e41c7c0c..a656eb622 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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 088ff3a39..99d10ddf6 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -28,6 +28,9 @@ "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_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600, "EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000, "EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000, "EVENT_HANDLER_PORT": 5100, @@ -43,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/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/common/network-util.js b/common/network-util.js index cfca678ec..81a004682 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -143,10 +143,18 @@ function getIpAddress(internal = false) { }); } +// NOTE(minsulee2): This builds the URL using a client socket in the server side. +function buildRemoteUrlFromSocket(socket) { + const remoteAddress = _.get(socket, '_socket.remoteAddress', ''); + const remotePort = _.get(socket, '_socket.remotePort', ''); + return `${remoteAddress}:${remotePort}`; +} + module.exports = { sendTxAndWaitForFinalization, sendSignedTx, signAndSendTx, sendGetRequest, - getIpAddress + getIpAddress, + buildRemoteUrlFromSocket, }; 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..78b670338 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" @@ -125,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" @@ -163,12 +169,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,41 +191,41 @@ 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 } # 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 +285,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 +298,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 +492,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 new file mode 100644 index 000000000..5272966f0 --- /dev/null +++ b/deploy_blockchain_genesis_onprem.sh @@ -0,0 +1,429 @@ +#!/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" + +ONPREM_USER="nvidia" +printf "ONPREM_USER=$ONPREM_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 + +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" +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_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" + +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 + +# 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 + if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then + # Get keystore password + printf "Enter keystore password: " + read -s KEYSTORE_PW + 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_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_url='$node_url'\n" + + KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" + { + echo $KEYSTORE_FILE_PATH + sleep 1 + 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_url='$node_url'\n" + { + echo $MNEMONIC + sleep 1 + echo 0 + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION + else + printf "\n* >> Injecting an account for node $node_index ********************\n\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_url $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_onprem.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_onprem.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" + +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="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Deploying files for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -rv $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/ + 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_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="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + 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="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Installing node modules for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" + 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="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo -S killall node" + 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 + +#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" + +## 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="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + printf "\n* >> Removing old data for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + + 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 + 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 -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 + inject_account "$node_index" + done +fi diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index a76939487..0c0e71165 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" @@ -111,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" @@ -148,12 +153,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" @@ -166,8 +171,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 +209,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 +248,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 @@ -286,37 +291,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..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" @@ -90,17 +96,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 @@ -308,7 +314,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 +386,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..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" @@ -92,7 +98,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 +135,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/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index a57d1245e..3d6891595 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, @@ -21,14 +20,14 @@ class EventChannelManager { this.channels = {}; // [channelId]: Channel this.filterIdToChannelId = {}; // [globalFilterId]: channelId this.heartbeatInterval = null; + this.idleCheckInterval = null; } - async getNetworkInfo() { - const ipAddr = await getIpAddress(NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL); + getNetworkInfo() { + const ipAddr = 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, @@ -36,10 +35,42 @@ class EventChannelManager { } } + 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(), + } + } + getNumEventChannels() { 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)) { @@ -62,18 +93,21 @@ class EventChannelManager { this.handleConnection(ws); }); this.startHeartbeat(this.wsServer); + this.startIdleCheck(); } handleConnection(webSocket) { 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`); } @@ -100,6 +134,7 @@ class EventChannelManager { if (messageType === BlockchainEventMessageTypes.PONG) { this.handlePong(webSocket); } else { + channel.setLastMessagingTimeMs(Date.now()); this.handleMessage(channel, messageType, messageData); } } catch (err) { @@ -309,6 +344,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`); }); @@ -317,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) { @@ -327,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})`); } } @@ -341,7 +377,25 @@ class EventChannelManager { ws.isAlive = false; this.sendPing(ws); }); - }, NodeConfigs.EVENT_HANDLER_HEARTBEAT_INTERVAL_MS || 15000); + }, NodeConfigs.EVENT_HANDLER_HEARTBEAT_INTERVAL_MS); + } + + startIdleCheck() { + const LOG_HEADER = 'startIdleCheck'; + this.idleCheckInterval = setInterval(() => { + 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 long-idle channel: ${JSON.stringify(channel.toObject())}`); + 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())}`); + this.closeChannel(channel); + } + } + }, NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_CHECK_INTERVAL_MS); } sendPing(webSocket) { @@ -352,6 +406,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..797e360ab 100644 --- a/event-handler/event-channel.js +++ b/event-handler/event-channel.js @@ -1,8 +1,18 @@ +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(); + const curTimeMs = Date.now(); + this.creationTimeMs = curTimeMs; + this.lastMessagingTimeMs = curTimeMs; + } + + setLastMessagingTimeMs(timeMs) { + this.lastMessagingTimeMs = timeMs; } getFilterIdsSize() { @@ -21,10 +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, + lifeTimeMs: this.getLifeTimeMs(), + idleTimeMs: this.getIdleTimeMs(), }; } } diff --git a/event-handler/index.js b/event-handler/index.js index aa0077ef4..61bf76d03 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,41 @@ class EventHandler { this.run(); } + getEventHandlerStatus() { + return { + isEnabled: true, + networkInfo: this.eventChannelManager.getNetworkInfo(), + channelStatus: this.eventChannelManager.getChannelStatus(), + filterStatus: this.getFilterStatus(), + }; + } + + static getDefaultEventHandlerStatus() { + return { + isEnabled: false, + networkInfo: { + url: "", + maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS, + numEventChannels: 0, + maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS, + numEventFilters: 0, + }, + 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: {}, + }, + }; + } + run() { const LOG_HEADER = 'run'; this.eventChannelManager.startListening(); @@ -44,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/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; 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/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/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/p2p/server.js b/p2p/server.js index e58b97211..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; } @@ -197,6 +193,7 @@ class P2pServer { nonce: this.node.getNonce(), dbStatus: this.getDbStatus(), stateVersionStatus: this.getStateVersionStatus(), + eventHandlerStatus: this.node.getEventHandlerStatus(), }; } @@ -720,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); diff --git a/package.json b/package.json index bf35494c8..8cd857d9a 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", @@ -56,7 +56,7 @@ "tracker": "node ./tracker-server/index.js" }, "dependencies": { - "@ainblockchain/ain-util": "^1.1.9", + "@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/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 diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh new file mode 100644 index 000000000..7943e579b --- /dev/null +++ b/setup_blockchain_ubuntu_onprem.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" + +# 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[[ 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 + +# 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 + +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 diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh new file mode 100644 index 000000000..f0c9c41f3 --- /dev/null +++ b/start_node_genesis_onprem.sh @@ -0,0 +1,344 @@ +#!/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 + +# 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() { + 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://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 +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" +# 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 +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" diff --git a/test/unit/event-handler.test.js b/test/unit/event-handler.test.js index 93400af85..cad39c565 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,16 +375,14 @@ 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 eventHandlerUrl = new URL(`ws://${ipAddrExternal}:${NodeConfigs.EVENT_HANDLER_PORT}`); + const networkInfo = eventChannelManager.getNetworkInfo(); assert.deepEqual(networkInfo, { + url: eventHandlerUrl.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, }); }); }); 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", () => { diff --git a/test/unit/p2p.test.js b/test/unit/p2p.test.js index 079f58cbc..a304fa729 100644 --- a/test/unit/p2p.test.js +++ b/test/unit/p2p.test.js @@ -222,6 +222,29 @@ describe("P2p", () => { numVersions: 4, versionList: 'erased', finalVersion: 'FINAL:0' + }, + eventHandlerStatus: { + isEnabled: false, + networkInfo: { + url: "", + maxNumEventChannels: 20, + numEventChannels: 0, + maxNumEventFilters: 40, + numEventFilters: 0, + }, + channelStatus: { + maxNumEventChannels: 20, + numEventChannels: 0, + channelIdleTimeLimitSecs: 600, + maxChannelIdleTimeMs: 0, + maxChannelLifeTimeMs: 0, + channelInfo: {}, + }, + filterStatus: { + maxNumEventFilters: 40, + numEventFilters: 0, + filterInfo: {}, + }, } }); }); 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); } diff --git a/tools/transfer/sendTransferTx.js b/tools/transfer/sendTransferTx.js index 361fdd784..48a37efe7 100644 --- a/tools/transfer/sendTransferTx.js +++ b/tools/transfer/sendTransferTx.js @@ -17,7 +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: N // 0, 1, 2, ... } } diff --git a/yarn.lock b/yarn.lock index 52cb47b4a..c941b1185 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"