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

handle vote account already exists #37

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
47 changes: 34 additions & 13 deletions k8s-cluster/src/scripts/validator-startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ SOLANA_RPC_URL="http://$BOOTSTRAP_RPC_ADDRESS"
# Identity file
IDENTITY_FILE=$identity

vote_account_already_exists=false

# Function to run a Solana command with retries. need reties because sometimes dns resolver fails
# if pod dies and starts up again it may try to create a vote account or something that already exists
run_solana_command() {
Expand All @@ -299,11 +301,24 @@ run_solana_command() {
for ((retry_count = 1; retry_count <= MAX_RETRIES; retry_count++)); do
echo "Attempt $retry_count for: $description"

if $command; then
echo "Command succeeded: $description"
return 0
# Capture both stdout and stderr in $output
output=$($command 2>&1)
status=$?

if [ $status -eq 0 ]; then
echo "Command succeeded: $description"
return 0
else
echo "Command failed for: $description (Exit status $?)"
echo "Command failed for: $description (Exit status $status)"
echo "$output" # Print the output which includes the error

# Check for specific error message
if [[ "$output" == *"Vote account"*"already exists"* ]]; then
echo "Vote account already exists. Continuing without exiting."
vote_account_already_exists=true
return 0
fi

if [ "$retry_count" -lt $MAX_RETRIES ]; then
echo "Retrying in $RETRY_DELAY seconds..."
sleep $RETRY_DELAY
Expand All @@ -322,18 +337,24 @@ if ! run_solana_command "solana -u $SOLANA_RPC_URL airdrop $node_sol $IDENTITY_F
fi

if ! run_solana_command "solana -u $SOLANA_RPC_URL create-vote-account --allow-unsafe-authorized-withdrawer vote.json $IDENTITY_FILE $IDENTITY_FILE -k $IDENTITY_FILE" "Create Vote Account"; then
echo "Create vote account failed."
exit 1
if $vote_account_already_exists; then
echo "Vote account already exists. Skipping remaining commands."
else
echo "Create vote account failed."
exit 1
fi
fi

if ! run_solana_command "solana -u $SOLANA_RPC_URL create-stake-account stake.json $stake_sol -k $IDENTITY_FILE" "Create Stake Account"; then
echo "Create stake account failed."
exit 1
fi
if [ "$vote_account_already_exists" != true ]; then
if ! run_solana_command "solana -u $SOLANA_RPC_URL create-stake-account stake.json $stake_sol -k $IDENTITY_FILE" "Create Stake Account"; then
echo "Create stake account failed."
exit 1
fi

if ! run_solana_command "solana -u $SOLANA_RPC_URL delegate-stake stake.json vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then
echo "Delegate stake command failed."
exit 1
if ! run_solana_command "solana -u $SOLANA_RPC_URL delegate-stake stake.json vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then
echo "Delegate stake command failed."
exit 1
fi
fi

echo "All commands succeeded. Running solana-validator next..."
Expand Down