/subnet-template

Primary LanguagePythonMIT LicenseMIT

Subnet Template


The Incentivized Internet


This template contains all the necessary files and functions to define subnet incentive mechanisms. You can run this template in three ways, on main-network (real TOKEN, to be released), Test-network (fake TOKEN), or with your own staging-network. This repo includes instructions for doing all three.

Introduction

The blockchain hosts multiple self-contained incentive mechanisms 'subnets'. Subnets are playing fields through which miners (those producing value) and validators (those producing consensus) determine together the proper distribution of TOKEN for the purpose of incentivizing the creation of value, i.e. generating digital commodities, such as intelligence, or data. Each consists of a wire protocol through which miners and validators interact and their method of interacting with chain consensus engine Yuma Consensus which is designed to drive these actors into agreement about who is creating value.

This repository is a template for writing such mechanisms, preloaded with all needed files to run a very simple mechanism. The template is designed to be simple (rewards miners for responding with the multiple of the value sent by vaidators) and can act as a starting point for those who want to write their own mechanism. It is split into 3 primary files which you should rewrite. These files are:

  • template/protocol.py: The file where the wire-protocol used by miners and validators is defined.
  • neurons/miner.py: This script which defines the miner's behavior, i.e., how the miner responds to requests from validators.
  • neurons/validator.py: This script which defines the validator's behavior, i.e., how the validator requests information from miners and determines scores.

Running the template

Before running the template you will need to attain a subnetwork on either main network, test network, or your own staging network. To create subnetworks on each of these subnets follow the instructions in files below:

  • docs/running_on_staging.md
  • docs/running_on_testnet.md
  • docs/running_on_mainnet.md

Installation

This repository requires python3.8 or higher. To install, simply clone this repository and install the requirements.

cd subnet-template
python -m pip install -r requirements.txt
python -m pip install -e .

Once you have installed this repo and attained your subnet via the instructions in the nested docs (staging, testing, or main) you can run the miner and validator with the following commands.

# To run the miner
python -m neurons/miner.py 
    --netuid <your netuid>  # Must be attained by following the instructions in the docs/running_on_*.md files
    --subtensor.chain_endpoint <your chain url>  # Must be attained by following the instructions in the docs/running_on_*.md files
    --wallet.name <your miner wallet> # Must be created using the cli
    --wallet.hotkey <your validator hotkey> # Must be created using the cli
    --logging.debug # Run in debug mode, alternatively --logging.trace for trace mode

# To run the validator
python -m neurons/validator.py 
    --netuid <your netuid> # Must be attained by following the instructions in the docs/running_on_*.md files
    --subtensor.chain_endpoint <your chain url> # Must be attained by following the instructions in the docs/running_on_*.md files
    --wallet.name <your validator wallet>  # Must be created using the cli
    --wallet.hotkey <your validator hotkey> # Must be created using the cli
    --logging.debug # Run in debug mode, alternatively --logging.trace for trace mode

Updating the template

The code contains detailed documentation on how to update the template. Please read the documentation in each of the files to understand how to update the template. There are multiple TODOs in each of the files which you should read and update.


License

This repository is licensed under the MIT License.

# The MIT License (MIT)
# Copyright © 2023 Yuma Rao

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.