Skip to content

Latest commit

 

History

History
208 lines (130 loc) · 5.58 KB

File metadata and controls

208 lines (130 loc) · 5.58 KB

Hetu Subnet Template

This repository provides a minimal template for setting up a simple Hetu 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 Hetu network.

Overview

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 Hetu blockchain based on miner performance.

By following this guide, you'll have a functional miner and validator interacting on a Hetu subnet.

Project Structure

hetu_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.

Prerequisites

Before you begin, ensure you have the following installed:

Setup Instructions

1. Clone the Repository

Clone this repository to your local machine:

git clone https://github.com/yourusername/hetu_subnet.git
cd hetu_subnet

2. Install Dependencies

Install the required Python packages:

pip install hetu-pysdk

Note: It's recommended to use a virtual environment to manage dependencies.

3. Create Wallets

You'll need to create wallets for both the miner and validator.

Using hetucli

The hetucli tool is used to manage wallets and keys.

pip install -U hetu-pycli
hetucli --help
  1. Create keys:

    • Miner Hotkey:

      hetucli wallet create --name miner
    • Validator Hotkey:

      hetucli wallet create --name validator

4. Register Wallets

Register both the miner and validator on the Hetu network.

First, set the neuron contract address to configure the network:

hetucli c set neuron_address <address>
hetucli c set json_rpc <mainnet_rpc_url>
  • Register the Miner:

    hetucli neuron regist --sender miner --netuid 1 --is-validator-role  --axon-endpoint "http://my-node.com" --axon-port 8080 --prometheus-endpoint "http://my-metrics.com" --prometheus-port 9090
  • Register the Validator:

    hetucli neuron regist --sender validator --netuid 1 --is-validator-role  --axon-endpoint "http://my-node.com" --axon-port 8080 --prometheus-endpoint "http://my-metrics.com" --prometheus-port 9090

Running the Miner and Validator

Running the Miner

In one terminal window, navigate to the project directory and run:

python miner.py --wallet.name miner --hetu.network finney --axon.port 8901

Arguments:

  • --wallet.name: The hotkey name for the miner.
  • --hetu.network: The Hetu network to connect to.

Running the Validator

In another terminal window, navigate to the project directory and run:

python validator.py --wallet.name validator --hetu.network finney

Arguments:

  • --wallet.name: The hotkey name for the validator.
  • --hetu.network: The Hetu network to connect to.

Monitoring and Logging

Both the miner and validator will output logs to the console and save logs to files in the following directory structure:

~/.hetu/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.


Customization

Modifying the Protocol

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.

Adjusting Scoring Logic

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

Changing Network Parameters

You can adjust network parameters like netuid, timeouts, and other settings via command-line arguments or by modifying the code.


Notes and Considerations

  • 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 and hetu.network values match the subnet you intend to connect to.
  • Hetu Updates: Hetu is an evolving project. Keep your SDK updated and adjust the code as necessary to accommodate changes.

License

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 Hetu network!