Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/fix script #100

Merged
merged 12 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 74 additions & 4 deletions scripts/testing/setup_localnet_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)
Expand Down Expand Up @@ -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
Expand All @@ -279,27 +300,29 @@ 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 \
--from=validator \
--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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions scripts/testing/variables.sh.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
NEW_BINARY="/tmp/elysd-061"
PROPOSAL_ID="11"
UPGRADE_HEIGHT="770650"