Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.
Closed
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
18 changes: 12 additions & 6 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ def blocks_since_last_update(
call: Optional[list[int]] = self.get_hyperparameter(
param_name="LastUpdate", netuid=netuid, block=block
)
assert call is not None
if call is None:
return None
return None if len(call) == 0 else (block - int(call[uid]))

def blocks_until_next_epoch(
Expand Down Expand Up @@ -973,15 +974,18 @@ def bonds(

return bond_map

def commit_reveal_enabled(self, netuid: int, block: Optional[int] = None) -> bool:
def commit_reveal_enabled(
self, netuid: int, block: Optional[int] = None
) -> Optional[bool]:
"""Check if commit-reveal mechanism is enabled for a given subnet at a specific block.

Parameters:
netuid: The unique identifier of the subnet for which to check the commit-reveal mechanism.
block: The block number to query. If `None`, queries the current chain head.

Returns:
True if commit-reveal mechanism is enabled, False otherwise.
True if commit-reveal mechanism is enabled, False otherwise, or `None` if the subnet
does not exist.

Notes:
- <https://docs.learnbittensor.org/glossary#commit-reveal>
Expand All @@ -990,10 +994,11 @@ def commit_reveal_enabled(self, netuid: int, block: Optional[int] = None) -> boo
call: Optional[bool] = self.get_hyperparameter(
param_name="CommitRevealWeightsEnabled", block=block, netuid=netuid
)
assert call is not None
if call is None:
return None
return call

def difficulty(self, netuid: int, block: Optional[int] = None) -> int:
def difficulty(self, netuid: int, block: Optional[int] = None) -> Optional[int]:
"""Retrieves the 'Difficulty' hyperparameter for a specified subnet in the Bittensor network.

This parameter determines the computational challenge required for neurons to participate in consensus and
Expand All @@ -1016,7 +1021,8 @@ def difficulty(self, netuid: int, block: Optional[int] = None) -> int:
call: Optional[int] = self.get_hyperparameter(
param_name="Difficulty", netuid=netuid, block=block
)
assert call is not None
if call is None:
return None
return int(call)

def does_hotkey_exist(self, hotkey_ss58: str, block: Optional[int] = None) -> bool:
Expand Down
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[mypy]
ignore_missing_imports = True
ignore_errors = True
follow_imports_for_stubs = True

[mypy-numpy.*]
follow_imports = skip

[mypy-numpy]
follow_imports = skip

[mypy-*.axon.*]
ignore_errors = False
Expand Down
21 changes: 21 additions & 0 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,27 @@ def test_difficulty_success(subtensor, mocker):
assert result == int(mocked_get_hyperparameter.return_value)


@pytest.mark.parametrize(
"getter,param_name,extra_kwargs",
[
("difficulty", "Difficulty", {}),
("commit_reveal_enabled", "CommitRevealWeightsEnabled", {}),
("blocks_since_last_update", "LastUpdate", {"uid": 0}),
],
)
def test_subnet_getter_returns_none_when_subnet_missing(
subtensor, mocker, getter, param_name, extra_kwargs
):
"""When the subnet/uid is absent, get_hyperparameter returns None; the getter must
return None (honouring its docstring) instead of raising AssertionError."""
mocker.patch.object(subtensor, "get_hyperparameter", return_value=None)
mocker.patch.object(subtensor, "get_current_block", return_value=1)

result = getattr(subtensor, getter)(netuid=999, block=1, **extra_kwargs)

assert result is None


def test_recycle_success(subtensor, mocker):
"""Tests recycle method with successfully result."""
# Preps
Expand Down