1
1
#! /bin/bash
2
2
3
- # Update your system packages
4
- install_mac () {
5
- # Ensure Homebrew is installed
6
- which brew > /dev/null
7
- if [ $? -ne 0 ]; then
8
- echo " Installing Homebrew..."
9
- /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) "
3
+ # Section 1: Build/Install
4
+ # This section is for first-time setup and installations.
5
+
6
+ install_dependencies () {
7
+ # Function to install packages on macOS
8
+ install_mac () {
9
+ which brew > /dev/null
10
+ if [ $? -ne 0 ]; then
11
+ echo " Installing Homebrew..."
12
+ /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) "
13
+ fi
14
+ echo " Updating Homebrew packages..."
15
+ brew update
16
+ echo " Installing required packages..."
17
+ brew install make llvm curl libssl protobuf tmux
18
+ }
19
+
20
+ # Function to install packages on Ubuntu/Debian
21
+ install_ubuntu () {
22
+ echo " Updating system packages..."
23
+ sudo apt update
24
+ echo " Installing required packages..."
25
+ sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler tmux
26
+ }
27
+
28
+ # Detect OS and call the appropriate function
29
+ if [[ " $OSTYPE " == " darwin" * ]]; then
30
+ install_mac
31
+ elif [[ " $OSTYPE " == " linux-gnu" * ]]; then
32
+ install_ubuntu
33
+ else
34
+ echo " Unsupported operating system."
35
+ exit 1
10
36
fi
11
37
12
- echo " Updating Homebrew packages... "
13
- brew update
38
+ # Install rust and cargo
39
+ curl --proto ' =https ' --tlsv1.2 -sSf https://sh.rustup.rs | sh
14
40
15
- echo " Installing required packages... "
16
- brew install make llvm curl libssl protobuf tmux
41
+ # Update your shell's source to include Cargo's path
42
+ source " $HOME /.cargo/env "
17
43
}
18
44
19
- # Function to install packages on Ubuntu/Debian
20
- install_ubuntu () {
21
- echo " Updating system packages..."
22
- sudo apt update
23
-
24
- echo " Installing required packages..."
25
- sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler tmux
26
- }
27
-
28
- # Detect OS and call the appropriate function
29
- if [[ " $OSTYPE " == " darwin" * ]]; then
30
- install_mac
31
- elif [[ " $OSTYPE " == " linux-gnu" * ]]; then
32
- install_ubuntu
33
- else
34
- echo " Unsupported operating system."
35
- fi
36
-
37
- # Install rust and cargo
38
- curl --proto ' =https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
39
-
40
- # Update your shell's source to include Cargo's path
41
- source " $HOME /.cargo/env"
42
-
43
- # Clone subtensor and enter the directory
44
- cd ../
45
- if [ ! -d " subtensor" ]; then
46
- git clone https://github.com/opentensor/subtensor.git
45
+ # Call install_dependencies only if it's the first time running the script
46
+ if [ ! -f " .dependencies_installed" ]; then
47
+ install_dependencies
48
+ touch .dependencies_installed
47
49
fi
48
- cd subtensor
49
- git pull
50
-
51
- # Update to the nightly version of rust
52
- ./scripts/init.sh
53
50
54
- # Navigate to your project directory
55
- cd ../bittensor-subnet-template
56
51
57
- # Install the bittensor-subnet-template python package
58
- python -m pip install -e .
52
+ # Section 2: Test/Run
53
+ # This section is for running and testing the setup .
59
54
60
55
# Create a coldkey for the owner role
61
56
wallet=${1:- owner}
62
57
63
- btcli wallet new_coldkey --wallet.name $wallet --no_password --no_prompt
64
-
65
- # Set up the miner's wallets
66
- btcli wallet new_coldkey --wallet.name miner --no_password --no_prompt
67
- btcli wallet new_hotkey --wallet.name miner --wallet.hotkey default --no_prompt
58
+ # Logic for setting up and running the environment
59
+ setup_environment () {
60
+ # Clone subtensor and enter the directory
61
+ if [ ! -d " subtensor" ]; then
62
+ git clone https://github.com/opentensor/subtensor.git
63
+ fi
64
+ cd subtensor
65
+ git pull
66
+
67
+ # Update to the nightly version of rust
68
+ ./scripts/init.sh
69
+
70
+ cd ../bittensor-subnet-template
71
+
72
+ # Install the bittensor-subnet-template python package
73
+ python -m pip install -e .
74
+
75
+ # Create and set up wallets
76
+ # This section can be skipped if wallets are already set up
77
+ if [ ! -f " .wallets_setup" ]; then
78
+ btcli wallet new_coldkey --wallet.name $wallet --no_password --no_prompt
79
+ btcli wallet new_coldkey --wallet.name miner --no_password --no_prompt
80
+ btcli wallet new_hotkey --wallet.name miner --wallet.hotkey default --no_prompt
81
+ btcli wallet new_coldkey --wallet.name validator --no_password --no_prompt
82
+ btcli wallet new_hotkey --wallet.name validator --wallet.hotkey default --no_prompt
83
+ touch .wallets_setup
84
+ fi
68
85
69
- # Set up the validator's wallets
70
- btcli wallet new_coldkey --wallet.name validator --no_password --no_prompt
71
- btcli wallet new_hotkey --wallet.name validator --wallet.hotkey default --no_prompt
86
+ }
72
87
88
+ # Call setup_environment every time
89
+ setup_environment
73
90
74
91
# # Setup localnet
92
+ # assumes we are in the bittensor-subnet-template/ directory
75
93
# Initialize your local subtensor chain in development mode. This command will set up and run a local subtensor network.
76
94
cd ../subtensor
77
95
78
96
# Start a new tmux session and create a new pane, but do not switch to it
79
- echo " FEATURES='pow-faucet runtime-benchmarks' BT_DEFAULT_TOKEN_WALLET=$( cat ~ /.bittensor/wallets/owner /coldkeypub.txt | grep -oP ' "ss58Address": "\K[^"]+' ) bash scripts/localnet.sh" >> setup_and_run.sh
97
+ echo " FEATURES='pow-faucet runtime-benchmarks' BT_DEFAULT_TOKEN_WALLET=$( cat ~ /.bittensor/wallets/$wallet /coldkeypub.txt | grep -oP ' "ss58Address": "\K[^"]+' ) bash scripts/localnet.sh" >> setup_and_run.sh
80
98
chmod +x setup_and_run.sh
81
99
tmux new-session -d -s localnet -n ' localnet'
82
100
tmux send-keys -t localnet ' bash ../subtensor/setup_and_run.sh' C-m
@@ -85,15 +103,15 @@ tmux send-keys -t localnet 'bash ../subtensor/setup_and_run.sh' C-m
85
103
echo " >> localnet.sh is running in a detached tmux session named 'localnet'"
86
104
echo " >> You can attach to this session with: tmux attach-session -t localnet"
87
105
88
- # Register a subnet
89
- btcli subnet create --wallet.name owner --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt
106
+ # Register a subnet (this needs to be run each time we start a new local chain)
107
+ btcli subnet create --wallet.name $wallet --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt
90
108
91
109
# Transfer tokens to miner and validator coldkeys
92
110
export BT_MINER_TOKEN_WALLET=$( cat ~ /.bittensor/wallets/miner/coldkeypub.txt | grep -oP ' "ss58Address": "\K[^"]+' )
93
111
export BT_VALIDATOR_TOKEN_WALLET=$( cat ~ /.bittensor/wallets/validator/coldkeypub.txt | grep -oP ' "ss58Address": "\K[^"]+' )
94
112
95
- btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name owner --dest $BT_MINER_TOKEN_WALLET --amount 1000 --no_prompt
96
- btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name owner --dest $BT_VALIDATOR_TOKEN_WALLET --amount 10000 --no_prompt
113
+ btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name $wallet --dest $BT_MINER_TOKEN_WALLET --amount 1000 --no_prompt
114
+ btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name $wallet --dest $BT_VALIDATOR_TOKEN_WALLET --amount 10000 --no_prompt
97
115
98
116
# Register wallet hotkeys to subnet
99
117
btcli subnet register --wallet.name miner --netuid 1 --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt
0 commit comments