Running locally - Subtensor


Subtensor is our network blockchain and keeps a record of every transaction that occurs. A new block is created and recorded every 12 seconds - or "blockstep" - at which time a new round of Tao is distributed.

By connecting to Nakamoto, you automatically gain access to Subtensor. Running a Subtensor instance locally, however, will ensure a faster and more consistent experience in the case that the network is compromised or slowed by high traffic. It is therefore highly recommended to run Subtensor locally for serious miners.

Running Subtensor

Should any of the below commands fail, try running with sudo.

  1. Prepare your system by updating outdated packages in your system, and installing the newest available ones. You can do this in two commands.
apt-get update
apt-get upgrade
  1. Download Docker.
curl -fsSL https://get.docker.com -o get-docker.sh
  1. Make the Docker install script executable.
chmod +x ./get-docker.sh
  1. Install Docker. For more information, follow this link.
./get-docker.sh
  1. Clone the Subtensor repository.
git clone https://github.com/opentensor/subtensor.git ~/.bittensor/subtensor
  1. Open the Subtensor directory.
cd ~/.bittensor/subtensor
  1. Pull the latest Subtensor image.
docker pull opentensorfdn/subtensor
  1. Run Subtensor inside of Docker.
docker compose up -d
  1. Check that Subtensor is fully synced.
docker logs --since=1h node-subtensor 2>&1  | grep "best"

Here is an example of a synced copy of Subtensor:

/node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50564.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50568.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50572.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50576.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50580.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50584.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50588.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50592.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50596.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50600.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50604.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50608.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50612.    
node-subtensor    | 2022-04-27 01:32:22 Accepted a new tcp connection from 172.22.0.1:50616. 

In case your Subtensor goes down, here is the command to restart it:

# quick restart
cd ~/.bittensor/subtensor && \
/usr/local/bin/docker-compose down && \
/usr/local/bin/docker-compose up -d

# full restart
cd ~/.bittensor/subtensor && \
/usr/local/bin/docker-compose down && \
docker system prune -a -f && \
git -C ~/.bittensor/subtensor pull origin master && \
docker pull opentensorfdn/subtensor && \
/usr/local/bin/docker-compose up -d

Lastly, here are the steps to ensure both Bittensor and Subtensor are up to date.

Update Bittensor:

git -C ~/.bittensor/bittensor pull origin master
python3 -m pip install -e ~/.bittensor/bittensor

Update Subtensor:

#Bring Subtensor down
docker compose down
#Connect to directory
cd ~/.bittensor/subtensor
#update Subtensor
git pull
#Bring Subtensor back up 
docker compose up -d