Skip to content

Instantly share code, notes, and snippets.

@STEVLTH
Created October 1, 2023 13:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save STEVLTH/7f5304452115660f3ec85e729bb4a29e to your computer and use it in GitHub Desktop.
Save STEVLTH/7f5304452115660f3ec85e729bb4a29e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Solana validator remote identity transfer script v1.0
#
# Before starting, both validators must be running and caught up.
# For the best experience, use ssh keys without a password.
#
# Created: 30 Sep 2023 by STEVLTH
# Discord: .stevlth
# Telegram: https://t.me/STEVLTH
########## CONFIG ######################################################
SOLANA_PATH="/root/.local/share/solana/install/active_release/bin" # Solana binary directory.
STAKED_IDENTITY="" # The path to the JSON file on your laptop, not on the server!!!
UNSTAKED_IDENTITY="" # The path to the JSON file on your laptop, not on the server!!! It will be created by this script.
SERVER_LEDGER_PATH="" # Make sure the ledger paths are the same on both servers, or consider creating a symlink for convenience.
SERVER_TOWER_PATH=$SERVER_LEDGER_PATH # By default, the tower file is stored in the ledger directory, but you can use a custom path. Make sure the paths to the tower file are the same on both servers.
SERVER_FROM="" # user@IP - the server running Solana validator with the STAKED identity.
SERVER_TO="" # user@IP - the server running Solana validator with the UNSTAKED identity.
########## END CONFIG ##################################################
echo -e "You are going to transfer $(solana address -k $STAKED_IDENTITY) (STAKED identity)\nFROM $SERVER_FROM\nTO $SERVER_TO"
echo
while true; do
read -p "Are you sure? " yn
case $yn in
[Yy]* ) echo; echo "Starting..."; break;;
[Nn]* ) echo; echo "Aborting..."; exit;;
* ) echo; echo "Please enter Yes(y) or No(n).";;
esac
done
echo
solana-keygen new -s --no-bip39-passphrase --force -o $UNSTAKED_IDENTITY
echo "New UNSTAKED identity: $(solana address -k $UNSTAKED_IDENTITY)"
echo
echo "SET UNSTAKED identity to $SERVER_FROM..."
ssh $SERVER_FROM "$SOLANA_PATH/solana-validator --ledger $SERVER_LEDGER_PATH set-identity" < $UNSTAKED_IDENTITY
echo "REMOVE all authorized voters from $SERVER_FROM..."
ssh $SERVER_FROM "$SOLANA_PATH/solana-validator --ledger $SERVER_LEDGER_PATH authorized-voter remove-all"
echo
echo "Copy tower file from $SERVER_FROM..."
scp $SERVER_FROM:$SERVER_TOWER_PATH/tower-1_9-$(solana address -k $STAKED_IDENTITY).bin $HOME
echo "Copy tower file to $SERVER_TO..."
scp $HOME/tower-1_9-$(solana address -k $STAKED_IDENTITY).bin $SERVER_TO:$SERVER_TOWER_PATH
echo
echo "SET STAKED identity to $SERVER_TO..."
ssh $SERVER_TO "$SOLANA_PATH/solana-validator --ledger $SERVER_LEDGER_PATH set-identity" < $STAKED_IDENTITY
echo "SET STAKED authorized voter to $SERVER_TO..."
ssh $SERVER_TO "$SOLANA_PATH/solana-validator --ledger $SERVER_LEDGER_PATH authorized-voter add" < $STAKED_IDENTITY
echo
echo "DONE"
@STEVLTH
Copy link
Author

STEVLTH commented Oct 1, 2023

You don't need to waste time executing commands separately on each server.
Just run this script on your laptop and voila.

Output:

$ ./solana-validator-transfer-identity.sh

You are going to transfer 93Q99nhdKjuSe6WNXgMBbC3s8QVQEAoHKt91PNRkUkMn (STAKED identity)
FROM root@104.37.190.102
TO root@165.140.87.18

Are you sure? y

Starting...

Wrote new keypair to /home/stevlth/unstaked-identity.json
New UNSTAKED identity: 48R1cTZVqf3L4iU28jW69YjzsMW8NVby1kZWNy1PJW4L

SET UNSTAKED identity to root@104.37.190.102...
New validator identity: 48R1cTZVqf3L4iU28jW69YjzsMW8NVby1kZWNy1PJW4L
REMOVE all authorized voters from root@104.37.190.102...
All authorized voters removed

Copy tower file from root@104.37.190.102...
tower-1_9-93Q99nhdKjuSe6WNXgMBbC3s8QVQEAoHKt91PNRkUkMn.bin                                                                                                                            100% 4181    33.6KB/s   00:00
Copy tower file to root@165.140.87.18...
tower-1_9-93Q99nhdKjuSe6WNXgMBbC3s8QVQEAoHKt91PNRkUkMn.bin                                                                                                                            100% 4181    91.4KB/s   00:00

SET STAKED identity to root@165.140.87.18...
New validator identity: 93Q99nhdKjuSe6WNXgMBbC3s8QVQEAoHKt91PNRkUkMn
SET STAKED authorized voter to root@165.140.87.18...
Adding authorized voter: 93Q99nhdKjuSe6WNXgMBbC3s8QVQEAoHKt91PNRkUkMn

DONE

The execution of the script takes up to 60 seconds depending on the position of the stars in the Alpha Centauri star system.

real    0m22.068s
user    0m0.106s
sys     0m0.087s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment