Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add register_cost command for registering a neuron to a subnet #2195

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .github/workflows/e2e-multiple-bittensor-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: E2E tests w/ multiple bittensor versions

on:
workflow_dispatch:
inputs:
bittensor_versions:
description: 'Bittensor versions to test (comma-separated)'
required: true
default: '7.3.1,7.2.1'
bittensor_branch:
description: 'Branch of bittensor'
required: true
default: 'staging'
subtensor_branch:
description: 'Branch of subtensor'
required: true
default: 'testnet'

env:
RUSTV: nightly-2024-03-05
RUST_BACKTRACE: full

jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set up test matrix
id: set-matrix
run: |
versions=$(echo "${{ github.event.inputs.bittensor_versions }}" | jq -R -s -c 'split(",")| map(select(. != ""))')
echo "matrix=${versions}" >> $GITHUB_OUTPUT

test:
needs: setup
runs-on: SubtensorCI
strategy:
fail-fast: false
matrix:
bittensor-version: ${{fromJson(needs.setup.outputs.matrix)}}
rust-target:
- x86_64-unknown-linux-gnu
env:
RUST_BIN_DIR: target/${{ matrix.rust-target }}
TARGET: ${{ matrix.rust-target }}
steps:
- name: Check-out repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.bittensor_branch }}

- name: Print working directory
run: |
pwd
ls -la

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Install Rust dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler

- name: Install Rust ${{ env.RUSTV }}
uses: actions-rs/[email protected]
with:
toolchain: ${{ env.RUSTV }}
components: rustfmt
profile: minimal

- name: Add wasm32-unknown-unknown target
run: |
rustup target add wasm32-unknown-unknown --toolchain stable-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain stable-x86_64-unknown-linux-gnu

- name: Clone subtensor repo
run: git clone https://github.com/opentensor/subtensor.git

- name: Setup subtensor repo
working-directory: ${{ github.workspace }}/subtensor
run: git checkout ${{ github.event.inputs.subtensor_branch }}

- name: Create tox.ini
run: |
cd ../..
cat << EOF > tox.ini
[tox]
envlist = bt-${{ matrix.bittensor-version }}

[testenv]
deps =
pytest
pytest-asyncio
anyio
nest_asyncio
bittensor==${{ matrix.bittensor-version }}
commands =
pytest ${{ github.workspace }}/tests/e2e_tests -v -s {posargs}
passenv =
LOCALNET_SH_PATH

[pytest]
asyncio_mode = auto
EOF

- name: Run tox
env:
LOCALNET_SH_PATH: ${{ github.workspace }}/subtensor/scripts/localnet.sh
run: |
cd ../..
tox -c tox.ini -e bt-${{ matrix.bittensor-version }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 7.3.1 / 2024-08-19

## What's Changed
* https://github.com/opentensor/bittensor/pull/2156 by @camfairchild

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v7.3.0...v7.3.1

## 7.3.0 / 2024-07-12

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.0
7.3.1
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


# Bittensor code and protocol version.
__version__ = "7.3.0"
__version__ = "7.3.1"

_version_split = __version__.split(".")
__version_info__ = tuple(int(part) for part in _version_split)
Expand Down
2 changes: 2 additions & 0 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
RegenColdkeypubCommand,
RegenHotkeyCommand,
RegisterCommand,
RegisterCostCommand,
RegisterSubnetworkCommand,
RootGetWeightsCommand,
RootList,
Expand Down Expand Up @@ -111,6 +112,7 @@
"create": RegisterSubnetworkCommand,
"pow_register": PowRegisterCommand,
"register": RegisterCommand,
"register_cost": RegisterCostCommand,
"hyperparameters": SubnetHyperparamsCommand,
},
},
Expand Down
1 change: 1 addition & 0 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from .register import (
PowRegisterCommand,
RegisterCommand,
RegisterCostCommand,
RunFaucetCommand,
SwapHotkeyCommand,
)
Expand Down
72 changes: 72 additions & 0 deletions bittensor/commands/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,78 @@ def check_config(config: "bittensor.config"):
config.wallet.hotkey = str(hotkey)


class RegisterCostCommand:
"""
Executes the ``register_cost`` command to return the cost of registering a neuron on the Bittensor network by recycling some TAO.

This command is used to determine the registration cost for a neuron on a specified subnet within the network.

Usage:
The command verifies the existence of the specified subnet and returns the current recycle amount required for registration. The cost is displayed in TAO, the network's native token.

The registration cost is essential for users to understand the financial commitment required to add a neuron to the network. It is a critical factor in the decision-making process for contributing to the network.

Example usage::

btcli register_cost --netuid 1

Note:
This command is useful for users who wish to understand the registration cost before proceeding with the registration process. It provides valuable information for planning and budgeting the registration of a neuron on the network.
"""

@staticmethod
def run(cli: "bittensor.cli"):
r"""View the cost to register a neuron to a subnet."""
try:
config = cli.config.copy()
subtensor: "bittensor.subtensor" = bittensor.subtensor(
config=config, log_verbose=False
)
RegisterCostCommand._run(cli, subtensor)
finally:
if "subtensor" in locals():
subtensor.close()
bittensor.logging.debug("closing subtensor connection")

@staticmethod
def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
r"""View the cost to register a neuron to a subnet."""

# Verify subnet exists
if not subtensor.subnet_exists(netuid=cli.config.netuid):
bittensor.__console__.print(
f"[red]Subnet {cli.config.netuid} does not exist[/red]"
)
sys.exit(1)

# Check current recycle amount
current_recycle = subtensor.recycle(netuid=cli.config.netuid)
bittensor.__console__.print(
f"The cost to register by recycling is [green]{current_recycle}[/green] TAO"
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
register_parser = parser.add_parser(
"register_cost",
help="""Return the cost to register a wallet to a subnet.""",
)
register_parser.add_argument(
"--netuid",
type=int,
help="netuid for subnet to serve this neuron on",
default=argparse.SUPPRESS,
)

bittensor.subtensor.add_args(register_parser)

@staticmethod
def check_config(config: "bittensor.config"):
check_netuid_set(
config, subtensor=bittensor.subtensor(config=config, log_verbose=False)
)


class PowRegisterCommand:
"""
Executes the ``pow_register`` command to register a neuron on the Bittensor network using Proof of Work (PoW).
Expand Down
5 changes: 3 additions & 2 deletions bittensor/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# 3rd Party
import aiohttp
from aiohttp import ClientTimeout

# Application
import bittensor
Expand Down Expand Up @@ -557,7 +558,7 @@ async def call(
url,
headers=synapse.to_headers(),
json=synapse.model_dump(),
timeout=timeout,
timeout=ClientTimeout(total=timeout),
) as response:
# Extract the JSON response from the server
json_response = await response.json()
Expand Down Expand Up @@ -636,7 +637,7 @@ async def call_stream(
url,
headers=synapse.to_headers(),
json=synapse.model_dump(),
timeout=timeout,
timeout=ClientTimeout(total=timeout),
) as response:
# Use synapse subclass' process_streaming_response method to yield the response chunks
async for chunk in synapse.process_streaming_response(response): # type: ignore
Expand Down