Skip to content

Commit

Permalink
now have subnet, miner, and validator all registering and running
Browse files Browse the repository at this point in the history
  • Loading branch information
5u6r054 committed Jun 25, 2024
1 parent 7c105db commit 59fe8a0
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 97 deletions.
21 changes: 16 additions & 5 deletions docker/miner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ RUN apt-get update && \
RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install --upgrade pip && \
/opt/bittensor-venv/bin/pip install bittensor==7.2.0 && \
/opt/bittensor-venv/bin/pip install bittensor[torch]
/opt/bittensor-venv/bin/pip install bittensor[torch] && \
/opt/bittensor-venv/bin/pip install python-dotenv

# Copy the miner creation script
COPY scripts/run_faucet.sh /usr/local/bin/run_faucet.sh
# Copy the scripts
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_miner.sh /usr/local/bin/create_miner.sh

# Make the script executable
RUN chmod +x /usr/local/bin/create_miner.sh

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_miner.sh"]
# Copy the neurons and masa directories
COPY neurons /app/neurons
COPY masa /app/masa
COPY requirements.txt /app/requirements.txt
RUN /opt/bittensor-venv/bin/pip install -r /app/requirements.txt

# Set the working directory
WORKDIR /app

# Set the PATH to include the virtual environment
ENV PYTHONPATH="/opt/bittensor-venv/bin:/app:$PYTHONPATH"
ENV PATH="/opt/bittensor-venv/bin:$PATH"

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_miner.sh"]

# Add a command to keep the container running
CMD ["tail", "-f", "/dev/null"]
2 changes: 1 addition & 1 deletion docker/subnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install bittensor[torch]

# Copy the subnet creation script
COPY scripts/run_faucet.sh /usr/local/bin/run_faucet.sh
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_subnet.sh /usr/local/bin/create_subnet.sh

# Make the script executable
Expand Down
21 changes: 16 additions & 5 deletions docker/validator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ RUN apt-get update && \
RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install --upgrade pip && \
/opt/bittensor-venv/bin/pip install bittensor==7.2.0 && \
/opt/bittensor-venv/bin/pip install bittensor[torch]
/opt/bittensor-venv/bin/pip install bittensor[torch] && \
/opt/bittensor-venv/bin/pip install python-dotenv

# Copy the validator creation script
COPY scripts/run_faucet.sh /usr/local/bin/run_faucet.sh
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_validator.sh /usr/local/bin/create_validator.sh

# Copy the neurons and masa directories
COPY neurons /app/neurons
COPY masa /app/masa
COPY requirements.txt /app/requirements.txt
RUN /opt/bittensor-venv/bin/pip install -r /app/requirements.txt

# Set the working directory
WORKDIR /app

# Set the PATH to include the virtual environment
ENV PYTHONPATH="/opt/bittensor-venv/bin:/app:$PYTHONPATH"
ENV PATH="/opt/bittensor-venv/bin:$PATH"

# Make the script executable
RUN chmod +x /usr/local/bin/create_validator.sh

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_validator.sh"]

# Set the PATH to include the virtual environment
ENV PATH="/opt/bittensor-venv/bin:$PATH"

# Add a command to keep the container running
CMD ["tail", "-f", "/dev/null"]
28 changes: 25 additions & 3 deletions scripts/create_miner.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

# Activate the virtual environment
source /opt/bittensor-venv/bin/activate

# Use environment variables for passwords
COLDKEY_PASSWORD=${COLDKEY_PASSWORD:-'default_coldkey_password'}
HOTKEY_PASSWORD=${HOTKEY_PASSWORD:-'default_hotkey_password'}

# Import the run_faucet function
source run_faucet.sh
# Import the shared functions
source functions.sh

# Create and fund miner wallets
#
Expand All @@ -20,4 +23,23 @@ run_faucet miner || { echo "Faucet failed for miner wallet"; exit 1; }

echo "Wallets for miner created, and faucet used successfully."

tail -f /dev/null
# Wait for subnet 1 to be created
echo "Waiting for subnet 1 to be created..."
while ! check_subnet_exists; do
echo "Subnet 1 not found. Waiting 15 seconds before checking again..."
sleep 15
done
echo "Subnet 1 has been created. Proceeding with registration."

# Attempt to register the validator and start it
if register_node miner; then
echo "Miner registration successful. Starting the miner..."
# Start the miner
python /app/neurons/miner.py --netuid 1 --subtensor.chain_endpoint ws://subtensor_machine:9946 --wallet.name miner --wallet.hotkey miner_hotkey --axon.port 8091
else
echo "Miner registration failed. Not starting the validator."
fi

deactivate

tail -f /dev/null
4 changes: 2 additions & 2 deletions scripts/create_subnet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Import run_faucet()
source run_faucet.sh
# Import shared functions
source functions.sh

# Create and fund owner wallets
#
Expand Down
59 changes: 13 additions & 46 deletions scripts/create_validator.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#!/bin/bash

# Activate the virtual environment
source /opt/bittensor-venv/bin/activate

# Use environment variables for passwords
COLDKEY_PASSWORD=${COLDKEY_PASSWORD:-'default_coldkey_password'}
HOTKEY_PASSWORD=${HOTKEY_PASSWORD:-'default_hotkey_password'}

# Import run_faucet()
source run_faucet.sh

# Function to check if subnet 1 exists
check_subnet_exists() {
local output
output=$(btcli subnet list --subtensor.chain_endpoint ws://subtensor_machine:9945)
echo "Current subnet list:"
echo "$output"
echo "$output" | awk 'NR>1 {print $1, $2}' | grep -q "*1 "
}

# Import shared functions
source functions.sh

# Create and fund validator wallets
echo -e "$COLDKEY_PASSWORD\n$COLDKEY_PASSWORD" | btcli wallet new_coldkey --wallet.name validator --wallet.password
Expand All @@ -33,40 +26,14 @@ while ! check_subnet_exists; do
done
echo "Subnet 1 has been created. Proceeding with registration."

# Function to register validator
register_validator() {
local attempt=1
local max_attempts=5

while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt to register validator..."

output=$(btcli subnet register --wallet.name validator --wallet.hotkey validator_hotkey --subtensor.chain_endpoint ws://subtensor_machine:9946 2>&1)

if echo "$output" | grep -q "Enter netuid \[0/1/3\] (0):"; then
echo "1" | btcli subnet register --wallet.name validator --wallet.hotkey validator_hotkey --subtensor.chain_endpoint ws://subtensor_machine:9946 <<EOF
1
y
$COLDKEY_PASSWORD
y
EOF
if [ $? -eq 0 ]; then
echo "Successfully registered validator."
return 0
fi
fi

echo "Registration attempt failed. Waiting 15 seconds before retrying..."
sleep 15
((attempt++))
done

echo "Failed to register validator after $max_attempts attempts."
return 1
}

# Attempt to register the validator
register_validator
# Attempt to register the validator and start it
if register_node validator; then
echo "Validator registration successful. Starting the validator..."
# Start the validator
python /app/neurons/validator.py --netuid 1 --subtensor.chain_endpoint ws://subtensor_machine:9946 --wallet.name validator --wallet.hotkey validator_hotkey --axon.port 8092
else
echo "Validator registration failed. Not starting the validator."
fi

# Keep the container running
tail -f /dev/null
77 changes: 77 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# Use environment variables for passwords
COLDKEY_PASSWORD=${COLDKEY_PASSWORD:-'default_coldkey_password'}
HOTKEY_PASSWORD=${HOTKEY_PASSWORD:-'default_hotkey_password'}

# Function to run the faucet process and wait for it to complete
run_faucet() {
WALLET_NAME=$1
expect << EOF
set timeout 360
log_user 1
spawn btcli wallet faucet --wallet.name $WALLET_NAME --subtensor.chain_endpoint ws://subtensor_machine:9945 --wallet.password
expect {
"Run Faucet ?" {
send "y\r"
exp_continue
}
"Enter password to unlock key:" {
send "$COLDKEY_PASSWORD\r"
exp_continue
}
"Balance:" {
exp_continue
}
timeout {
puts "Timeout waiting for faucet process to complete."
exit 1
}
eof {
exit
}
}
EOF
}

# Function to check if subnet 1 exists
check_subnet_exists() {
local output
output=$(btcli subnet list --subtensor.chain_endpoint ws://subtensor_machine:9945)
echo "Current subnet list:"
echo "$output"
echo "$output" | awk 'NR>1 {print $1, $2}' | grep -q "^ *1 "
}

# Function to register a miner or validator
register_node() {
local node_type=$1
local wallet_name="${node_type}"
local hotkey_name="${node_type}_hotkey"
local attempt=1
local max_attempts=5

while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt to register ${node_type}..."

output=$(btcli subnet register --wallet.name $wallet_name --wallet.hotkey $hotkey_name --subtensor.chain_endpoint ws://subtensor_machine:9946 2>&1)

if echo "$output" | grep -q "Enter netuid \[0/1/3\] (0):"; then
echo "1" | btcli subnet register --wallet.name $wallet_name --wallet.hotkey $hotkey_name --subtensor.chain_endpoint ws://subtensor_machine:9946 <<EOF
1
y
$COLDKEY_PASSWORD
y
EOF
if [ $? -eq 0 ]; then
echo "Successfully registered ${node_type}."
return 0
fi
fi
echo "Registration attempt failed. Waiting 15 seconds before retrying..."
sleep 15
((attempt++))
done
echo "Failed to register ${node_type} after $max_attempts attempts."
return 1
}
35 changes: 0 additions & 35 deletions scripts/run_faucet.sh

This file was deleted.

0 comments on commit 59fe8a0

Please sign in to comment.