See min_compute.yml
git clone https://github.com/Sturdy-Subnet/sturdy-subnet/
cd sturdy-subnetMake sure you have installed the correct python version, and then follow these steps:
### Install the local python environment
pip install --upgrade pip
pip install -e .You will need pm2 if you would like to utilize the auto update scripts that comes with this repository
- Install node and npm
- Install pm2
Used to store api keys, scoring logs, and "active" miner allocations for scoring
First, install dbmate. then run the command below
dbmate --url "sqlite:validator_database.db" upBefore running a validator it is highly recommended that you run a local subtensor vs. just connecting to the finney endpoint. Instructions for setting up a local subtensor can be found here.
Now - let's get to the good stuff.
Before we get to the differences between them, and how to set each of them up, we must first ensure we have a connection to the Ethereum network.
All validators are required to have a connection to an Ethereum RPC to handle requests. It is required to interact with relevant smart contracts in order to perform certain operations i.e. calculate miner allocation yields.
The next step involves interacting with an API. We've provided an .env.example file which should be copied as a .env file in the root of this repository before proceeding.
We recommend using a third party service to connect to an RPC to perform on-chain calls to evm-based chains (e.g. Ethereum) such as Infura and Alchemy (click on hyperlinks links for documentation) by obtaining there API key and adding their URL to the .env file under the ETHEREUM_MAINNET_PROVIDER_URL alias.
We also support bittensor alpha token pools, and as a validator you will need access to an archive subtensor node for historical data. The environment variable for this is BITTENSOR_MAINNET_PROVIDER_URL. Thankfully, there is already a public one that can be used (see .env.example).
Before you start the validator, run the command
lsof -i -P -n | grep LISTENThis shows you all the ports currently in use. When you come to choose a port for running the api server, make sure the ports you choose aren't already in use.
Example output:
This shows that ports 9091, 3001, .., 34579, 41133 etc, are currently in use, so pick address that don't include these.
python neurons/validator.py --netuid NETUID --subtensor.network local --wallet.name NAME --wallet.hotkey HOTKEY --logging.trace --axon.port PORT --api_port API_PORTpm2 start --name PROC_NAME --interpreter=python3 neurons/validator.py -- --netuid NETUID --subtensor.network local --wallet.name NAME --wallet.hotkey HOTKEY --logging.trace --axon.port PORT --api_port API_PORT
Replace, PROC_NAME, NAME, NETWORK, HOTKEY, PORT, API_PORT with your desired values. As mentioned in our README we highly recommend that validators run a local subtensor and use local in place of the NETWORK parameter.
Note: If you would like to participate in the testnet replace NETUID with 104
List pm2 processes:
pm2 ls
You should see a list of processes as show below:
Take note of either the id or name of the process - you'll need it going forward. For our case (as seen in the picture above) our validator's id is 6 and it's name is vali0
Run the following command to run the auto updater script. This will periodically scan the upstream branch, pull when there are changes, reinstall the repo, and finall restart the validator automatically:
pm2 start --name run_validator_auto_update --interpreter=python3 run_validator_auto_update.py -- --proc ID_OR_PROCESS_NAME
Where ID_OR_PROCESS_NAME is the name OR id of the process as noted per the previous step.
To manage access to the your api server and sell access to anyone you like, using the sturdy-cli is the easiest way.
sturdy --helpShows all the commands and should give self explanatory instructions.
You can also do
sturdy some-command --helpTo get more info about that command!
For example:
sturdy create-key --balance 10 --rate-limit-per-minute 60 --name testCreates a test key with a balance of 10 (which corresponds to 10 requests), a rate limit of 60 requests per minute = 1/s, and a name 'test'.
Now you can do:
sturdy list-keysTo see the API key. Give / sell this access to whoever you want to have access to your API server to query the network organically - these will be scored too!
For them to use your server, you will need to communicate:
- Your server address (IP_ADDRESS:PORT)
- Use /redoc or /docs for automatic documentation on how to use it!
- The API key you generated for them
Please see docs/api_usage.md for more information on how to use the API.
We provide a Docker image for easy deployment of validators. Here's how to run a validator using Docker:
- Run using
docker composeon mainnet with environment variables:
NETUID=10 \
NETWORK=wss://entrypoint-finney.opentensor.ai:443 \
WALLET_NAME=WALLET_NAME \
WALLET_HOTKEY=WALLET_HOTKEY \
AXON_PORT=AXON_PORT \
API_PORT=API_PORT \
WANDB_OFF=false \
docker compose up -dThis will:
- Initialize the SQLite database
- Start the validator process with PM2
- Enable auto-updates using watchtower
- Mount your local wallets directory
- Expose the API and Axon ports
- View logs:
# View all logs
docker compose logs -f
# View only validator logs
docker compose logs -f sturdy-validator- Stop the validator:
docker compose down| Variable | Description | Default |
|---|---|---|
NETUID |
Subnet ID | 10 |
NETWORK |
Subtensor network endpoint | wss://entrypoint-finney.opentensor.ai:443 |
WALLET_NAME |
Wallet name | default |
WALLET_HOTKEY |
Wallet hotkey | default |
AXON_PORT |
Port for Axon server | 8001 |
API_PORT |
Port for API server | 8000 |
WANDB_OFF |
Disable wandb logging | false |
The docker compose configuration mounts these volumes:
${DB_DIR:-./validator_database.db}:/app/validator_database.db- Mounts your local database file for persistence~/.bittensor/wallets/:/root/.bittensor/wallets- Mounts wallet directory~/.bittensor/miners/:/root/.bittensor/miners/- Mounts miners directory which stores saved weights.env/:/app/.env- Mounts your environment configuration file
The included watchtower service will automatically check for new Docker image versions every 30 seconds and update your validator container if a new version is available.
To disable auto-updates, remove the watchtower service from your docker compose.yml file.
Run with custom wallet and ports:
WALLET_NAME=myvalidator \
WALLET_HOTKEY=mykey \
API_PORT=3000 \
docker compose up -dRun with wandb disabled:
WANDB_OFF=true docker compose up -d