forked from RaoFoundation/bittensor-subnet-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall_validator.sh
More file actions
executable file
·100 lines (76 loc) · 2.75 KB
/
Copy pathinstall_validator.sh
File metadata and controls
executable file
·100 lines (76 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -euxo pipefail
if [ $# -ne 2 ]
then
>&2 echo "USAGE: ./install_validator.sh SSH_DESTINATION HOTKEY_PATH"
exit 1
fi
SSH_DESTINATION="$1"
LOCAL_HOTKEY_PATH=$(realpath "$2")
LOCAL_COLDKEY_PUB_PATH=$(dirname "$(dirname "$LOCAL_HOTKEY_PATH")")/coldkeypub.txt
if [ ! -f "$LOCAL_HOTKEY_PATH" ]; then
>&2 echo "Given HOTKEY_PATH does not exist"
exit 1
fi
HOTKEY_NAME=$(basename "$LOCAL_HOTKEY_PATH")
WALLET_NAME=$(basename "$(dirname "$(dirname "$LOCAL_HOTKEY_PATH")")")
# set default names if they contain special characters
[[ $HOTKEY_NAME =~ ['$#!;*?&()<>'\"\'] ]] && HOTKEY_NAME=default
[[ $WALLET_NAME =~ ['$#!;*?&()<>'\"\'] ]] && WALLET_NAME=mywallet
REMOTE_HOTKEY_PATH=".bittensor/wallets/$WALLET_NAME/hotkeys/$HOTKEY_NAME"
REMOTE_COLDKEY_PUB_PATH=".bittensor/wallets/$WALLET_NAME/coldkeypub.txt"
REMOTE_HOTKEY_DIR=$(dirname "$REMOTE_HOTKEY_PATH")
# Copy the wallet files to the server
ssh "$SSH_DESTINATION" "mkdir -p $REMOTE_HOTKEY_DIR"
scp "$LOCAL_HOTKEY_PATH" "$SSH_DESTINATION:$REMOTE_HOTKEY_PATH"
scp "$LOCAL_COLDKEY_PUB_PATH" "$SSH_DESTINATION:$REMOTE_COLDKEY_PUB_PATH"
# Set PYTHONPATH locally, ensuring it's always defined
export PYTHONPATH="${HOME}/score-predict${PYTHONPATH:+:$PYTHONPATH}"
# Install necessary software and set up the validator
ssh "$SSH_DESTINATION" <<ENDSSH
set -euxo pipefail
WALLET_NAME="$WALLET_NAME"
HOTKEY_NAME="$HOTKEY_NAME"
REMOTE_PYTHONPATH="\$HOME/score-predict\${PYTHONPATH:+:\$PYTHONPATH}"
# Update and install dependencies
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv git
# Clone the repository
git clone https://github.com/score-protocol/score-predict.git
cd score-predict
# Set up virtual environment
python3 -m venv venv
source venv/bin/activate
# Install requirements
pip install -r requirements.txt
# Manual patch for bittensor testnet
# cd ..
# git clone https://github.com/opentensor/bittensor.git
# cd bittensor
# git checkout release/7.1.1
# pip install -e .
# cd ../score-predict
# Set up PYTHONPATH
# echo "export PYTHONPATH=\"\$REMOTE_PYTHONPATH\"" >> ~/.bashrc
# source ~/.bashrc
# Install pm2
sudo apt-get install -y nodejs npm
sudo npm install pm2 -g
# Create a startup script
cat > start_validator.sh <<EOF
#!/bin/bash
source \$HOME/score-predict/venv/bin/activate
export PYTHONPATH="\$REMOTE_PYTHONPATH"
python neurons/validator.py --netuid 44 --wallet.name $WALLET_NAME --wallet.hotkey $HOTKEY_NAME
EOF
chmod +x start_validator.sh
# Start the validator using the startup script
pm2 start ./start_validator.sh --name validator
# Start the auto-updater
pm2 start validator_auto_update.sh --name validator-updater --interpreter bash -- validator
# Save the pm2 configuration
pm2 save
# Set up pm2 to start on boot
pm2 startup
ENDSSH
echo "Validator installed and started successfully!"