Skip to content

Latest commit

 

History

History
353 lines (235 loc) · 10.7 KB

File metadata and controls

353 lines (235 loc) · 10.7 KB

Running Subnet Locally

This tutorial will guide you through:

  • Setting up a local blockchain that is not connected to either Bittensor testchain or mainchain
  • Creating a subnet
  • Run your incentive mechanism on the subnet.

Local blockchain vs local subtensor node

Running a local blockchain is sometimes synonymously referred as running on staging. This is different from running a local subtensor node that connects to the Bittensor mainchain.

A local subtensor node will connect to the mainchain and sync with the mainchain, giving you your own access point to the mainchain.

Running a local blockchain spins up two authority nodes locally, not connected to any other nodes or testchain or mainchain. This tutorial is for running a local blockchain.

Prerequisites

Before proceeding further, make sure that you have installed Bittensor. See the below instructions:

After installing bittensor, proceed as below:

1. Install Substrate dependencies

Begin by installing the required dependencies for running a Substrate node.

Update your system packages:

sudo apt update 

Install additional required libraries and tools

sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler

2. Install Rust and Cargo

Rust is the programming language used in Substrate development. Cargo is Rust package manager.

Install rust and cargo:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Update your shell's source to include Cargo's path:

source "$HOME/.cargo/env"

3. Clone the subtensor repository

This step fetches the subtensor codebase to your local machine.

git clone https://github.com/opentensor/subtensor.git

4. Setup Rust

This step ensures that you have the nightly toolchain and the WebAssembly (wasm) compilation target. Note that this step will run the subtensor chain on your terminal directly, hence we advise that you run this as a background process using PM2 or other software.

Update to the nightly version of Rust:

./subtensor/scripts/init.sh

5. Initialize

These steps initialize your local subtensor chain in development mode. These commands will set up and run a local subtensor.

./subtensor/scripts/localnet.sh False

NOTE: Watch for any build or initialization outputs in this step. If you are building the project for the first time, this step will take a while to finish building, depending on your hardware.

6. Install BitQuant-Subnet

cd to your project directory and clone the BitQuant-Subnet repository:

Validator Setup

# Install Python3.13 and Python3.13 tools on your OS
sudo apt update
sudo apt install python3.13 python3.13-venv python3.13-dev pkg-config

# Clone BitQuant-Subnet Repository and checkout Validator Branch
git clone https://github.com/OpenGradient/BitQuant-Subnet
cd BitQuant-Subnet
git checkout Validator

# Optional: Create Python Virtual Environment (Best Practice)
python3.13 -m venv venv
source venv/bin/activate

# Install Requirements
pip install -r requirements.txt
pip install -e .

# Set up customized environment variables in .env, or fall back to defaults
cp .env.example .env

Miner Setup

# Install Python3.13 and Python3.13 tools on your OS
sudo apt update
sudo apt install python3.13 python3.13-venv python3.13-dev pkg-config

# Clone BitQuant-Subnet Repository and BitQuant submodule
git clone --branch Miner --recursive https://github.com/OpenGradient/BitQuant-Subnet
cd BitQuant-Subnet

# Optional: Create Python Virtual Environment (Best Practice)
python3.13 -m venv venv
source venv/bin/activate

# Install Requirements
pip install -r requirements.txt
pip install -e .

# Setup all the environment variables in .env
cp .env.example .env

Note: Running a miner node requires substantially higher compute requirements due to the local running of the BitQuant agent. Setup instructions can be found https://github.com/OpenGradient/BitQuant

7. Set up wallets

You will need wallets for the different roles, i.e., subnet owner, subnet validator and subnet miner, in the subnet.

  • The owner wallet creates and controls the subnet.
  • The validator and miner will be registered to the subnet created by the owner. This ensures that the validator and miner can run the respective validator and miner scripts.

Create a coldkey for the owner role:

btcli wallet new_coldkey --wallet.name owner
btcli wallet new_hotkey --wallet.name owner --wallet.hotkey default

Set up the miner's wallets:

btcli wallet new_coldkey --wallet.name miner
btcli wallet new_hotkey --wallet.name miner --wallet.hotkey default

Set up the validator's wallets:

btcli wallet new_coldkey --wallet.name validator
btcli wallet new_hotkey --wallet.name validator --wallet.hotkey default

8. Mint tokens from faucet

You will need tokens to initialize the intentive mechanism on the chain as well as for registering the subnet.

Run the following commands to mint faucet tokens for the owner and for the validator.

Mint faucet tokens for the owner:

btcli wallet faucet --wallet.name owner --subtensor.chain_endpoint ws://127.0.0.1:9944 

You will see:

>> Balance: τ0.000000000 ➡ τ100.000000000

Mint tokens for the validator:

btcli wallet faucet --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9944 

You will see:

>> Balance: τ0.000000000 ➡ τ100.000000000

9. Register keys

Register your subnet validator and subnet miner on the subnet. This gives your two keys unique slots on the subnet. The subnet has a current limit of 128 slots.

Register the subnet miner:

btcli subnet register --wallet.name miner --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944

Follow the below prompts:

>> Enter netuid [1]: 2
>> Continue Registration? [y/n]: y
>> ✅ Registered

Register the subnet validator:

btcli subnet register --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944

Follow the below prompts:

>> Enter netuid [1] (1): 1
>> Continue Registration? [y/n]: y
>> ✅ Registered

10. Add stake

This step bootstraps the incentives on your new subnet by adding stake into its incentive mechanism.

btcli stake add --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944

Follow the below prompts:

>> Stake all Tao from account: 'validator'? [y/n]: y
>> Stake:
    τ0.000000000 ➡ τ100.000000000

11. Validate key registrations

Verify that both the miner and validator keys are successfully registered:

btcli subnet list --subtensor.chain_endpoint ws://127.0.0.1:9944

You will see the 2 entry under NEURONS column for the NETUID of 1, indicating that you have registered a validator and a miner in this subnet:

NETUID  NEURONS  MAX_N   DIFFICULTY  TEMPO  CON_REQ  EMISSION  BURN(τ)  
   1        2     256.00   10.00 M    1000    None     0.00%    τ1.00000 
   2      128    

See the subnet validator's registered details:

btcli wallet overview --wallet.name validator --subtensor.chain_endpoint ws://127.0.0.1:9944

You will see:

Subnet: 1                                                                                                                                                                
COLDKEY  HOTKEY   UID  ACTIVE  STAKE(τ)     RANK    TRUST  CONSENSUS  INCENTIVE  DIVIDENDS  EMISSION(ρ)   VTRUST  VPERMIT  UPDATED  AXON  HOTKEY_SS58                    
validator    default  0      True   100.00000  0.00000  0.00000    0.00000    0.00000    0.00000            0  0.00000                14  none  5GTFrsEQfvTsh3WjiEVFeKzFTc2xcf…
1        1        2            τ100.00000  0.00000  0.00000    0.00000    0.00000    0.00000           ρ0  0.00000                                                         
                                                                          Wallet balance: τ0.0         

See the subnet miner's registered details:

btcli wallet overview --wallet.name miner --subtensor.chain_endpoint ws://127.0.0.1:9944

You will see:

Subnet: 1                                                                                                                                                                
COLDKEY  HOTKEY   UID  ACTIVE  STAKE(τ)     RANK    TRUST  CONSENSUS  INCENTIVE  DIVIDENDS  EMISSION(ρ)   VTRUST  VPERMIT  UPDATED  AXON  HOTKEY_SS58                    
miner    default  1      True   0.00000  0.00000  0.00000    0.00000    0.00000    0.00000            0  0.00000                14  none  5GTFrsEQfvTsh3WjiEVFeKzFTc2xcf…
1        1        2            τ0.00000  0.00000  0.00000    0.00000    0.00000    0.00000           ρ0  0.00000                                                         
                                                                          Wallet balance: τ0.0   

12. Run subnet miner and subnet validator

Run the subnet miner and subnet validator. Make sure to specify your subnet parameters.

Run the subnet miner:

python neurons/miner.py --netuid 2 --subtensor.network ws://127.0.0.1:9944 --wallet.name miner --wallet.hotkey default --logging.debug

Run the subnet validator:

python neurons/validator.py --netuid 2 --subtensor.network ws://127.0.0.1:9944 --wallet.name validator --wallet.hotkey default --logging.debug

Check if the SubnetAPI is working:

./api_test.py --subtensor.network ws://127.0.0.1:9944 --netuid 2 --wallet.name validator --wallet.hotkey default --timeout 15.0 --specific_uid 2

13. Set weights for your subnet

Register a validator on the root subnet and boost to set weights for your subnet. This is a necessary step to ensure that the subnet is able to receive emmissions.

Register your validator on the root subnet

btcli root register --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944

Boost your subnet on the root subnet

btcli root boost --netuid 2 --increase 1 --wallet.name validator --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9944

14. Verify your incentive mechanism

After a few blocks the subnet validator will set weights. This indicates that the incentive mechanism is active. Then after a subnet tempo elapses (360 blocks or 72 minutes) you will see your incentive mechanism beginning to distribute TAO to the subnet miner.

btcli wallet overview --wallet.name miner --subtensor.chain_endpoint ws://127.0.0.1:9944

Ending your session

To halt your nodes:

# Press CTRL + C keys in the terminal.