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

Release/9.0.1 #2686

Merged
merged 67 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0958209
test: use asynccontextmanager for FastAPI lifespan
zyzniewski-reef Jan 22, 2025
321d359
test: wait for uvicorn server to start completly
zyzniewski-reef Jan 22, 2025
e6d00ad
tests: add timeouts
zyzniewski-reef Feb 3, 2025
52558f5
Python 3.9 compatibility.
thewhaleking Feb 3, 2025
9a5b538
Compatibility if uvloop is installed.
thewhaleking Feb 3, 2025
7fe7076
Ruff
thewhaleking Feb 3, 2025
c6d26d7
Merge branch 'staging' into test/use_asynccontextmanager_for_fastapi_…
thewhaleking Feb 13, 2025
4329e5b
Merge branch 'staging' into test/use_asynccontextmanager_for_fastapi_…
zyzniewski-reef Feb 13, 2025
79c85d4
test(2472): offline unittests
zyzniewski-reef Jan 22, 2025
8eb3192
tests: missing imports
zyzniewski-reef Feb 13, 2025
73cf961
Merge branch 'staging' into fix/2472-offline_unittests
zyzniewski-reef Feb 13, 2025
1f82056
Merge branch 'staging' into test/use_asynccontextmanager_for_fastapi_…
zyzniewski-reef Feb 13, 2025
134a7b5
Merge branch 'staging' into fix/2472-offline_unittests
zyzniewski-reef Feb 13, 2025
046c52d
Ensures that alpha symbols are always rendered to the right of the va…
thewhaleking Feb 14, 2025
dba23ec
fix test
roman-opentensor Feb 14, 2025
8177df1
Merge pull request #2673 from opentensor/fix/roman/e2etest-commit-wei…
roman-opentensor Feb 14, 2025
6c46997
fix `tests.e2e_tests.test_incentive.test_incentive`
roman-opentensor Feb 14, 2025
85c64b4
Merge branch 'master' into fix/roman/e2etest-incentive
roman-opentensor Feb 14, 2025
2002fc2
remove back merge changes
roman-opentensor Feb 14, 2025
348ac99
Merge pull request #2674 from opentensor/fix/roman/e2etest-incentive
roman-opentensor Feb 15, 2025
7db5f15
feat: add readonly check before modifying FS
Arthurdw Feb 18, 2025
be914a8
fix: when readonly don't save logs
Arthurdw Feb 18, 2025
434e4e2
Merge branch 'staging' into patch/v9.0.0_readonly
thewhaleking Feb 18, 2025
ff2150a
Merge branch 'staging' into fix/thewhaleking/str-formatting-for-alpha
thewhaleking Feb 18, 2025
76a10db
Ruff
thewhaleking Feb 18, 2025
3b3ff3e
Merge branch 'staging' into test/use_asynccontextmanager_for_fastapi_…
thewhaleking Feb 18, 2025
63c92d3
Merge branch 'staging' into fix/2472-offline_unittests
thewhaleking Feb 18, 2025
aacf074
Merge pull request #2676 from Arthurdw/patch/v9.0.0_readonly
thewhaleking Feb 18, 2025
8563a33
Add methods for retrieving all neuron certificates on a given netuid.
thewhaleking Feb 18, 2025
b5a8d5c
Add netuid
thewhaleking Feb 18, 2025
bf5e391
Added test
thewhaleking Feb 18, 2025
34758a6
Merge branch 'staging' into fix/thewhaleking/str-formatting-for-alpha
roman-opentensor Feb 18, 2025
d93bc7d
Added unit test
thewhaleking Feb 18, 2025
76142a5
Merge branch 'staging' into test/use_asynccontextmanager_for_fastapi_…
roman-opentensor Feb 18, 2025
1c85c53
ut
thewhaleking Feb 18, 2025
7c144a4
Update tests/unit_tests/test_async_subtensor.py
thewhaleking Feb 18, 2025
baac41b
Merge pull request #2597 from opentensor/test/use_asynccontextmanager…
thewhaleking Feb 18, 2025
2ef8377
Merge branch 'staging' into fix/2472-offline_unittests
thewhaleking Feb 18, 2025
495601d
Merge branch 'staging' into feat/thewhaleking/add-neuron-certificates…
roman-opentensor Feb 18, 2025
3db617d
Merge pull request #2596 from opentensor/fix/2472-offline_unittests
zyzniewski-reef Feb 18, 2025
8bb9218
Merge branch 'staging' into feat/thewhaleking/add-neuron-certificates…
roman-opentensor Feb 18, 2025
fb8c0ea
fix(2188): don't allow uvicorn to reconfigure event_loop_policy
zyzniewski-reef Jan 21, 2025
574dbe4
Removes extra assignments for stake, total_stake
ibraheem-opentensor Feb 18, 2025
7678f7d
Merge branch 'staging' into fix/2188-configure_uvicorn_event_loop
roman-opentensor Feb 18, 2025
cc2844d
Merge branch 'staging' into improve/remove-extra-stake-assignments
ibraheem-opentensor Feb 18, 2025
0e5ec20
Merge branch 'staging' into fix/thewhaleking/str-formatting-for-alpha
thewhaleking Feb 18, 2025
c8a570a
Merge pull request #2680 from opentensor/improve/remove-extra-stake-a…
ibraheem-opentensor Feb 18, 2025
cfa3efd
Merge branch 'staging' into fix/thewhaleking/str-formatting-for-alpha
thewhaleking Feb 18, 2025
e6f2f14
Merge branch 'staging' into fix/2188-configure_uvicorn_event_loop
roman-opentensor Feb 18, 2025
7712fa3
Merge branch 'staging' into feat/thewhaleking/add-neuron-certificates…
roman-opentensor Feb 18, 2025
b4b82a6
Merge pull request #2672 from opentensor/fix/thewhaleking/str-formatt…
thewhaleking Feb 18, 2025
2a062aa
Merge branch 'staging' into feat/thewhaleking/add-neuron-certificates…
thewhaleking Feb 18, 2025
4c6cfd2
Merge pull request #2677 from opentensor/feat/thewhaleking/add-neuron…
thewhaleking Feb 18, 2025
66409e9
Merge branch 'staging' into fix/2188-configure_uvicorn_event_loop
thewhaleking Feb 18, 2025
7445b5a
Adds stake weight to metagraph info
ibraheem-opentensor Feb 19, 2025
b7eec15
ruff
ibraheem-opentensor Feb 19, 2025
7d511a4
Merge pull request #2682 from opentensor/fix/metagraph-info-tao-stake
ibraheem-opentensor Feb 19, 2025
6302a1f
Merge branch 'staging' into fix/2188-configure_uvicorn_event_loop
thewhaleking Feb 19, 2025
4bebb26
Merge pull request #2679 from opentensor/fix/2188-configure_uvicorn_e…
thewhaleking Feb 19, 2025
7045475
Refactored the logic of `__aenter__` for `AsyncSubtensor` so that it …
thewhaleking Feb 20, 2025
c5b0986
Fix tests.
thewhaleking Feb 20, 2025
80f9174
Fix tests.
thewhaleking Feb 20, 2025
f7a9315
called -> awaited
thewhaleking Feb 20, 2025
8aa8f4c
Merge pull request #2684 from opentensor/feat/thewhaleking/refactor-a…
thewhaleking Feb 20, 2025
b0b6145
merge master to staging
ibraheem-opentensor Feb 20, 2025
fc3d850
Merge pull request #2685 from opentensor/backmerge-main-staging-900
ibraheem-opentensor Feb 20, 2025
c228c6c
Updates version and changelog
ibraheem-opentensor Feb 20, 2025
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## What's Changed
* Release/9.0.0 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2671
* fix e2e test by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2673
* fix e2e test incentive by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2674
* Add compatibility for read-only systems by @Arthurdw in https://github.com/opentensor/bittensor/pull/2676
* test: use asynccontextmanager for FastAPI lifespan by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2597
* test(2472): offline unittests by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2596
* Removes redundant assignments in Metagraph by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2680
* Alpha str formatting by @thewhaleking in https://github.com/opentensor/bittensor/pull/2672
* Add method for fetching all Neuron Certificates on a Netuid by @thewhaleking in https://github.com/opentensor/bittensor/pull/2677
* Updates tao_stake in MetagraphInfo by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2682
* fix(2188): configure uvicorn event loop by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2679
* Refactor AsyncSubtensor aenter logic by @thewhaleking in https://github.com/opentensor/bittensor/pull/2684
* Backmerge master to staging 900 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2685

## New Contributors
* @Arthurdw made their first contribution in https://github.com/opentensor/bittensor/pull/2676

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v9.0.0...v9.0.1

## 9.0.0 /2025-02-13

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.0
9.0.1
39 changes: 37 additions & 2 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ async def __aenter__(self):
f"[magenta]Connecting to Substrate:[/magenta] [blue]{self}[/blue][magenta]...[/magenta]"
)
try:
async with self.substrate:
return self
await self.substrate.initialize()
return self
except TimeoutError:
logging.error(
f"[red]Error[/red]: Timeout occurred connecting to substrate."
Expand Down Expand Up @@ -1479,6 +1479,41 @@ async def get_neuron_certificate(
return None
return None

async def get_all_neuron_certificates(
self,
netuid: int,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> dict[str, Certificate]:
"""
Retrieves the TLS certificates for neurons within a specified subnet (netuid) of the Bittensor network.

Arguments:
netuid: The unique identifier of the subnet.
block: The blockchain block number for the query.
block_hash: The hash of the block to retrieve the parameter from. Do not specify if using block or
reuse_block.
reuse_block: Whether to use the last-used block. Do not set if using block_hash or block.

Returns:
{ss58: Certificate} for the key/Certificate pairs on the subnet

This function is used for certificate discovery for setting up mutual tls communication between neurons.
"""
query_certificates = await self.query_map(
module="SubtensorModule",
name="NeuronCertificates",
params=[netuid],
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)
output = {}
async for key, item in query_certificates:
output[decode_account_id(key)] = Certificate(item.value)
return output

async def get_neuron_for_pubkey_and_subnet(
self,
hotkey_ss58: str,
Expand Down
6 changes: 5 additions & 1 deletion bittensor/core/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ def __init__(
self.app = FastAPI()
log_level = "trace" if logging.__trace_on__ else "critical"
self.fast_config = uvicorn.Config(
self.app, host="0.0.0.0", port=self._config.axon.port, log_level=log_level
self.app,
host="0.0.0.0",
log_level=log_level,
loop="none",
port=self._config.axon.port,
)
self.fast_server = FastAPIThreadedServer(config=self.fast_config)
self.router = APIRouter()
Expand Down
6 changes: 5 additions & 1 deletion bittensor/core/chain_data/metagraph_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from typing import Optional, Union

from bittensor.core import settings
from bittensor.core.chain_data.axon_info import AxonInfo
from bittensor.core.chain_data.chain_identity import ChainIdentity
from bittensor.core.chain_data.info_base import InfoBase
Expand Down Expand Up @@ -234,7 +235,10 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
rank=[u16tf(rk) for rk in decoded.get("rank", [])],
block_at_registration=decoded["block_at_registration"],
alpha_stake=[_tbwu(ast, _netuid) for ast in decoded["alpha_stake"]],
tao_stake=[_tbwu(ts) for ts in decoded["tao_stake"]],
tao_stake=[
_tbwu(ts) * settings.ROOT_TAO_STAKE_WEIGHT
for ts in decoded["tao_stake"]
],
total_stake=[_tbwu(ts, _netuid) for ts in decoded["total_stake"]],
# Dividend break down
tao_dividends_per_hotkey=[
Expand Down
21 changes: 9 additions & 12 deletions bittensor/core/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@


Tensor = Union["torch.nn.Parameter", NDArray]
ROOT_TAO_STAKES_WEIGHT = 0.18


METAGRAPH_STATE_DICT_NDARRAY_KEYS = [
Expand Down Expand Up @@ -773,14 +772,6 @@ def _set_metagraph_attributes(self, block: int):
[neuron.validator_trust for neuron in self.neurons],
dtype=self._dtype_registry["float32"],
)
self.total_stake = self._create_tensor(
[neuron.total_stake.tao for neuron in self.neurons],
dtype=self._dtype_registry["float32"],
)
self.stake = self._create_tensor(
[neuron.stake.tao for neuron in self.neurons],
dtype=self._dtype_registry["float32"],
)
self.axons = [n.axon_info for n in self.neurons]

def save(self, root_dir: Optional[list[str]] = None) -> "MetagraphMixin":
Expand Down Expand Up @@ -1606,7 +1597,10 @@ async def _get_all_stakes_from_chain(self):
dtype=self._dtype_registry["float32"],
)
self.tao_stake = self._create_tensor(
[b.tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state.tao_stake],
[
b.tao * settings.ROOT_TAO_STAKE_WEIGHT
for b in subnet_state.tao_stake
],
dtype=self._dtype_registry["float32"],
)
self.total_stake = self.stake = self._create_tensor(
Expand Down Expand Up @@ -1634,7 +1628,7 @@ def __init__(
subtensor: Optional["Subtensor"] = None,
):
super().__init__(netuid, network, lite, sync, subtensor)
if sync:
if self.should_sync:
self.sync()

def sync(
Expand Down Expand Up @@ -1910,7 +1904,10 @@ def _get_all_stakes_from_chain(self):
dtype=self._dtype_registry["float32"],
)
self.tao_stake = self._create_tensor(
[b.tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state.tao_stake],
[
b.tao * settings.ROOT_TAO_STAKE_WEIGHT
for b in subnet_state.tao_stake
],
dtype=self._dtype_registry["float32"],
)
self.total_stake = self.stake = self._create_tensor(
Expand Down
12 changes: 8 additions & 4 deletions bittensor/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
__version__ = "9.0.0"
__version__ = "9.0.1"

import os
import re
from pathlib import Path

from munch import munchify

ROOT_TAO_STAKE_WEIGHT = 0.18

READ_ONLY = os.getenv("READ_ONLY") == "1"

HOME_DIR = Path.home()
USER_BITTENSOR_DIR = HOME_DIR / ".bittensor"
WALLETS_DIR = USER_BITTENSOR_DIR / "wallets"
MINERS_DIR = USER_BITTENSOR_DIR / "miners"


# Create dirs if they don't exist
WALLETS_DIR.mkdir(parents=True, exist_ok=True)
MINERS_DIR.mkdir(parents=True, exist_ok=True)
if not READ_ONLY:
# Create dirs if they don't exist
WALLETS_DIR.mkdir(parents=True, exist_ok=True)
MINERS_DIR.mkdir(parents=True, exist_ok=True)

# Bittensor networks name
NETWORKS = ["finney", "test", "archive", "local", "subvortex", "rao", "latent-lite"]
Expand Down
26 changes: 26 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,32 @@ def get_neuron_certificate(
return None
return None

def get_all_neuron_certificates(
self, netuid: int, block: Optional[int] = None
) -> dict[str, Certificate]:
"""
Retrieves the TLS certificates for neurons within a specified subnet (netuid) of the Bittensor network.

Arguments:
netuid: The unique identifier of the subnet.
block: The blockchain block number for the query.

Returns:
{ss58: Certificate} for the key/Certificate pairs on the subnet

This function is used for certificate discovery for setting up mutual tls communication between neurons.
"""
query_certificates = self.query_map(
module="SubtensorModule",
name="NeuronCertificates",
params=[netuid],
block=block,
)
output = {}
for key, item in query_certificates:
output[decode_account_id(key)] = Certificate(item.value)
return output

def get_neuron_for_pubkey_and_subnet(
self, hotkey_ss58: str, netuid: int, block: Optional[int] = None
) -> Optional["NeuronInfo"]:
Expand Down
9 changes: 7 additions & 2 deletions bittensor/utils/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ def __float__(self):
return self.tao

def __str__(self):
"""Returns the Balance object as a string in the format "symbolvalue", where the value is in tao."""
return f"{self.unit}{float(self.tao):,.9f}"
"""
Returns the Balance object as a string in the format "symbolvalue", where the value is in tao.
"""
if self.unit == units[0]:
return f"{self.unit}{float(self.tao):,.9f}"
else:
return f"\u200e{float(self.tao):,.9f}{self.unit}\u200e"

def __rich__(self):
int_tao, fract_tao = format(float(self.tao), "f").split(".")
Expand Down
10 changes: 7 additions & 3 deletions bittensor/utils/btlogging/loggingmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from statemachine import State, StateMachine

from bittensor.core.settings import READ_ONLY
from bittensor.core.config import Config
from bittensor.utils.btlogging.console import BittensorConsole
from .defines import (
Expand Down Expand Up @@ -584,9 +585,12 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
default_logging_info = os.getenv("BT_LOGGING_INFO") or False
default_logging_trace = os.getenv("BT_LOGGING_TRACE") or False
default_logging_record_log = os.getenv("BT_LOGGING_RECORD_LOG") or False
default_logging_logging_dir = os.getenv(
"BT_LOGGING_LOGGING_DIR"
) or os.path.join("~", ".bittensor", "miners")
default_logging_logging_dir = (
None
if READ_ONLY
else os.getenv("BT_LOGGING_LOGGING_DIR")
or os.path.join("~", ".bittensor", "miners")
)
parser.add_argument(
"--" + prefix_str + "logging.debug",
action="store_true",
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
Raises:
AssertionError: If any of the checks or verifications fail
"""
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos
subtensor.wait_for_block(20)

netuid = 2
print("Testing test_commit_and_reveal_weights")
# Register root as Alice
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e_tests/test_incentive.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
AssertionError: If any of the checks or verifications fail
"""

# Wait for 2 tempos to spin up chain properly
subtensor.wait_for_block(20)

print("Testing test_incentive")
netuid = 2

Expand Down
3 changes: 3 additions & 0 deletions tests/e2e_tests/test_neuron_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ async def test_neuron_certificate(subtensor, alice_wallet):
)
== encoded_certificate
)
all_certs_query = subtensor.get_all_neuron_certificates(netuid=netuid)
assert alice_wallet.hotkey.ss58_address in all_certs_query.keys()
assert all_certs_query[alice_wallet.hotkey.ss58_address] == encoded_certificate

logging.info("✅ Passed test_neuron_certificate")
30 changes: 30 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
from aioresponses import aioresponses
from async_substrate_interface.sync_substrate import SubstrateInterface

import bittensor.core.subtensor


@pytest.fixture
Expand All @@ -11,3 +14,30 @@ def force_legacy_torch_compatible_api(monkeypatch):
def mock_aio_response():
with aioresponses() as m:
yield m


@pytest.fixture
def mock_substrate_interface(mocker):
mocked = mocker.MagicMock(
autospec=SubstrateInterface,
)

mocker.patch("bittensor.core.subtensor.SubstrateInterface", return_value=mocked)

return mocked


@pytest.fixture
def subtensor(mock_substrate_interface):
return bittensor.core.subtensor.Subtensor()


@pytest.fixture
def mock_get_external_ip(mocker):
mocked = mocker.Mock(
return_value="192.168.1.1",
)

mocker.patch("bittensor.utils.networking.get_external_ip", mocked)

return mocked
2 changes: 1 addition & 1 deletion tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@pytest.fixture
def subtensor(mocker):
fake_substrate = mocker.AsyncMock()
fake_substrate.websocket.sock.getsockopt.return_value = 0
fake_substrate.websocket.socket.getsockopt.return_value = 0
mocker.patch.object(
subtensor_module, "AsyncSubstrateInterface", return_value=fake_substrate
)
Expand Down
11 changes: 0 additions & 11 deletions tests/unit_tests/extrinsics/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
from bittensor.core import subtensor as subtensor_module
from bittensor.core.chain_data import SubnetHyperparameters
from bittensor.core.extrinsics import commit_reveal
from bittensor.core.subtensor import Subtensor


@pytest.fixture
def subtensor(mocker):
fake_substrate = mocker.MagicMock()
fake_substrate.websocket.sock.getsockopt.return_value = 0
mocker.patch.object(
subtensor_module, "SubstrateInterface", return_value=fake_substrate
)
yield Subtensor()


@pytest.fixture
Expand Down
15 changes: 1 addition & 14 deletions tests/unit_tests/extrinsics/test_commit_weights.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import pytest
from bittensor_wallet import Wallet

from bittensor.core import subtensor as subtensor_module
from bittensor.core.settings import version_as_int
from bittensor.core.subtensor import Subtensor
from bittensor.core.extrinsics.commit_weights import (
_do_commit_weights,
_do_reveal_weights,
)


@pytest.fixture
def subtensor(mocker):
fake_substrate = mocker.MagicMock()
fake_substrate.websocket.sock.getsockopt.return_value = 0
mocker.patch.object(
subtensor_module, "SubstrateInterface", return_value=fake_substrate
)
return Subtensor()
from bittensor.core.settings import version_as_int


def test_do_commit_weights(subtensor, mocker):
Expand Down
Loading
Loading