diff --git a/scripts/testing/setup_localnet_nodes.sh b/scripts/testing/setup_localnet_nodes.sh index c000e1cd2..6e72605d2 100755 --- a/scripts/testing/setup_localnet_nodes.sh +++ b/scripts/testing/setup_localnet_nodes.sh @@ -48,7 +48,7 @@ prompt_to_stop_screens() { case $choice in [Yy]*) for screen_name in "${existing_screens[@]}"; do - screen -S "$screen_name" -X quit + screen -S "${screen_name}" -X stuff "^C" done ;; [Nn]*) @@ -266,6 +266,27 @@ start_nodes_in_screens() { done } +# Function to start nodes in separate screen sessions with new binary version +prompt_start_nodes_in_screens_with_new_binary_version() { + read -p "Do you want to start the nodes with the new binary version? (y/n): " choice + case $choice in + [Yy]*) + for folder in "${NODE_FOLDERS[@]}"; do + echo "Starting $folder node in a screen session..." + + screen -dmS "$folder" "${NEW_BINARY}" start --home "/tmp/$folder" + sleep 1 + done + ;; + [Nn]*) + echo "Skipping node startup with new binary version." + ;; + *) + echo "Invalid choice. Skipping node startup with new binary version." + ;; + esac +} + # Function to display all screen sessions display_screen_sessions() { screen -ls @@ -279,10 +300,11 @@ display_screen_sessions() { submit_upgrade_proposal() { local first_folder="${NODE_FOLDERS[0]}" + echo "Submitting software upgrade proposal..." ${BINARY} tx gov submit-legacy-proposal software-upgrade \ ${NEW_VERSION} \ --deposit=10000000uelys \ - --upgrade-height=770750 \ + --upgrade-height=${UPGRADE_HEIGHT} \ --title="${NEW_VERSION}" \ --description="${NEW_VERSION}" \ --no-validate \ @@ -290,16 +312,17 @@ submit_upgrade_proposal() { --fees=100000uelys \ --gas=auto \ --home="/tmp/${first_folder}" \ - -y + -y >/dev/null 2>&1 for folder in "${NODE_FOLDERS[@]}"; do + echo "Voting on software upgrade proposal for $folder node..." ${BINARY} tx gov vote \ ${PROPOSAL_ID} \ yes \ --from=validator \ --fees=100000uelys \ --home="/tmp/${folder}" \ - -y + -y >/dev/null 2>&1 done } @@ -319,6 +342,37 @@ prompt_to_submit_software_upgrade() { esac } +# Function to check if port is open +check_port_open() { + local port=$1 + nc -z localhost "$port" >/dev/null 2>&1 +} + +# Wait for all RPC ports to become available +wait_for_rpc_ports() { + local timeout=60 + local interval=5 + local counter=0 + + echo "Waiting for RPC ports to become available..." + + for port in "${NODE_RPC_PORTS[@]}"; do + until check_port_open "$port" || [ "$counter" -eq "$timeout" ]; do + counter=$((counter + interval)) + sleep "$interval" + done + + if [ "$counter" -eq "$timeout" ]; then + echo "Timeout: Failed to connect to RPC port $port." + exit 1 + fi + + echo "RPC port $port is now open." + done + + echo "All RPC ports are open." +} + # Main script execution # Load environment variables @@ -346,6 +400,10 @@ required_variables=( "CHAIN_ID" "SNAPSHOT_URL" "SNAPSHOT_PATH" + "NEW_VERSION" + "NEW_BINARY" + "PROPOSAL_ID" + "UPGRADE_HEIGHT" ) # Check if screen is installed @@ -387,8 +445,20 @@ start_nodes_in_screens # Display all screen sessions display_screen_sessions +# Wait for RPC ports +wait_for_rpc_ports + +# Continue with the next steps of your script +echo "Proceeding with the next steps..." + # Prompt user to submit a software upgrade proposal prompt_to_submit_software_upgrade +# Check if any of the named screens exist and prompt to stop them +prompt_to_stop_screens + +# Prompt to start nodes with new binary version +prompt_start_nodes_in_screens_with_new_binary_version + # Check if any of the named screens exist and prompt to stop them prompt_to_stop_screens \ No newline at end of file diff --git a/scripts/testing/variables.sh.example b/scripts/testing/variables.sh.example index 26aa0cfc8..a7e1abbf0 100644 --- a/scripts/testing/variables.sh.example +++ b/scripts/testing/variables.sh.example @@ -73,9 +73,11 @@ VALIDATOR_ACCOUNT_PASSPHRASES=( "" ) -BINARY="/tmp/elysd" +BINARY="/tmp/elysd-053" CHAIN_ID="elystestnet-1" SNAPSHOT_URL="https://snapshots.polkachu.com/testnet-snapshots/elys/elys_770630.tar.lz4" SNAPSHOT_PATH="/tmp/elys_testnet_snapshot.tar.lz4" NEW_VERSION="v0.6.1" -PROPOSAL_ID="11" \ No newline at end of file +NEW_BINARY="/tmp/elysd-061" +PROPOSAL_ID="11" +UPGRADE_HEIGHT="770650" \ No newline at end of file