This repository provides a minimal template for setting up a simple Bittensor subnet with a miner and a validator. The miner and validator communicate using a custom protocol defined in protocol.py
. This template serves as a starting point for developers interested in building on the Bittensor network.
- Overview
- Project Structure
- Prerequisites
- Setup Instructions
- Running the Miner and Validator
- Monitoring and Logging
- Customization
- Notes and Considerations
- License
This template demonstrates how to:
- Set up a basic miner that responds to queries from validators.
- Implement a validator that sends queries to miners and adjusts their scores based on responses.
- Use a custom protocol for communication between the miner and validator.
- Update weights on the Bittensor blockchain based on miner performance.
By following this guide, you'll have a functional miner and validator interacting on a Bittensor subnet.
bittensor_subnet/
├── miner.py # Miner node script
├── validator.py # Validator node script
└── protocol.py # Custom protocol definition
- miner.py: Implements a miner that listens for incoming requests and responds according to the protocol.
- validator.py: Implements a validator that sends requests to miners and updates their scores.
- protocol.py: Defines the custom protocol used for communication between the miner and validator.
Before you begin, ensure you have the following installed:
- Python 3.10 or higher
- Git
- Bittensor SDK
Clone this repository to your local machine:
git clone https://github.com/yourusername/bittensor_subnet.git
cd bittensor_subnet
Install the required Python packages:
pip install bittensor
Note: It's recommended to use a virtual environment to manage dependencies.
You'll need to create wallets for both the miner and validator.
The btcli
tool is used to manage wallets and keys.
-
Create a Coldkey (shared between miner and validator):
btcli w new_coldkey --wallet.name mywallet
-
Create Hotkeys:
-
Miner Hotkey:
btcli w new_hotkey --wallet.name mywallet --wallet.hotkey miner_hotkey
-
Validator Hotkey:
btcli w new_hotkey --wallet.name mywallet --wallet.hotkey validator_hotkey
-
Register both the miner and validator on the Bittensor network.
-
Register the Miner:
btcli s register --wallet.name mywallet --wallet.hotkey miner_hotkey --subtensor.network finney
-
Register the Validator:
btcli s register --wallet.name mywallet --wallet.hotkey validator_hotkey --subtensor.network finney
Note: Replace
finney
with the name of the network you are connecting to if different.
In one terminal window, navigate to the project directory and run:
python miner.py --wallet.name mywallet --wallet.hotkey miner_hotkey --subtensor.network finney --axon.port 8901
Arguments:
--wallet.name
: The name of the wallet.--wallet.hotkey
: The hotkey name for the miner.--subtensor.network
: The Bittensor network to connect to.
In another terminal window, navigate to the project directory and run:
python validator.py --wallet.name mywallet --wallet.hotkey validator_hotkey --subtensor.network finney
Arguments:
--wallet.name
: The name of the wallet.--wallet.hotkey
: The hotkey name for the validator.--subtensor.network
: The Bittensor network to connect to.
Both the miner and validator will output logs to the console and save logs to files in the following directory structure:
~/.bittensor/wallets/<wallet.name>/<wallet.hotkey>/netuid<netuid>/<miner or validator>/
- Miner Logs: Located in the
miner
directory. - Validator Logs: Located in the
validator
directory.
You can monitor these logs to observe the interactions and performance metrics.
The communication protocol is defined in protocol.py
. You can modify or extend the Dummy
class to implement more complex interactions.
Example:
class CustomProtocol(bt.Synapse):
# Define your custom protocol attributes and methods
...
Update miner.py
and validator.py
to use your custom protocol.
In validator.py
, the validator adjusts miner scores based on their responses. You can modify the scoring logic in the main loop to suit your needs.
Example:
# Custom scoring logic
if resp_i == expected_value:
score = 1
else:
score = 0
You can adjust network parameters like netuid
, timeouts, and other settings via command-line arguments or by modifying the code.
- Security: This template is for educational purposes. In a production environment, ensure robust security measures are in place.
- Error Handling: The provided code includes basic error handling. Enhance it to handle edge cases and exceptions gracefully.
- Network Compatibility: Ensure that the
netuid
andsubtensor.network
values match the subnet you intend to connect to. - Bittensor Updates: Bittensor is an evolving project. Keep your SDK updated and adjust the code as necessary to accommodate changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to contribute, raise issues, or suggest improvements to this template. Happy mining and validating on the Bittensor network!