Skip to content
Merged
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
13 changes: 8 additions & 5 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,9 @@ async def get_metagraph_info(
Retrieves full or partial metagraph information for the specified subnet (netuid).

Arguments:
netuid (int): The NetUID of the subnet to query.
field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values
specifying which fields to retrieve. If not provided, all available fields will be returned.
netuid: The NetUID of the subnet to query.
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
not provided, all available fields will be returned.
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
reuse_block
block_hash: The hash of blockchain block number for the query. Do not specify if using
Expand All @@ -1505,9 +1505,12 @@ async def get_metagraph_info(

if field_indices:
if isinstance(field_indices, list) and all(
isinstance(f, SelectiveMetagraphIndex) for f in field_indices
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
):
indexes = [f.value for f in field_indices]
indexes = [
f.value if isinstance(f, SelectiveMetagraphIndex) else f
for f in field_indices
]
else:
raise ValueError(
"`field_indices` must be a list of SelectiveMetagraphIndex items."
Expand Down
19 changes: 11 additions & 8 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,18 +1133,18 @@ def get_minimum_required_stake(self) -> Balance:
def get_metagraph_info(
self,
netuid: int,
field_indices: Optional[list["SelectiveMetagraphIndex"]] = None,
field_indices: Optional[list[Union["SelectiveMetagraphIndex", int]]] = None,
block: Optional[int] = None,
) -> Optional[MetagraphInfo]:
"""
Retrieves full or partial metagraph information for the specified subnet (netuid).

Arguments:
netuid (int): The NetUID of the subnet to query.
field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values
specifying which fields to retrieve. If not provided, all available fields will be returned.
block (Optional[int]):The block number at which to query the data. If not specified, the current block or
one determined via reuse_block or block_hash will be used.
netuid: The NetUID of the subnet to query.
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
not provided, all available fields will be returned.
block: The block number at which to query the data. If not specified, the current block or one determined
via reuse_block or block_hash will be used.

Returns:
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
Expand All @@ -1162,9 +1162,12 @@ def get_metagraph_info(

if field_indices:
if isinstance(field_indices, list) and all(
isinstance(f, SelectiveMetagraphIndex) for f in field_indices
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
):
indexes = [f.value for f in field_indices]
indexes = [
f.value if isinstance(f, SelectiveMetagraphIndex) else f
for f in field_indices
]
else:
raise ValueError(
"`field_indices` must be a list of SelectiveMetagraphIndex items."
Expand Down
1 change: 1 addition & 0 deletions bittensor/utils/easy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ProposalCallData,
ProposalVoteData,
ScheduledColdkeySwapInfo,
SelectiveMetagraphIndex,
StakeInfo,
SubnetHyperparameters,
SubnetIdentity,
Expand Down
14 changes: 10 additions & 4 deletions tests/unit_tests/test_async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3100,7 +3100,7 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker):
# Preps
netuid = 1
mock_value = {"mock": "data"}
fields = [SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkey]
fields = [SelectiveMetagraphIndex.Name, 5]

mock_runtime_call = mocker.patch.object(
subtensor.substrate,
Expand All @@ -3119,7 +3119,13 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker):
mock_runtime_call.assert_awaited_once_with(
"SubnetInfoRuntimeApi",
"get_selective_metagraph",
params=[netuid, [0] + [f.value for f in fields]],
params=[
netuid,
[0]
+ [
f.value if isinstance(f, SelectiveMetagraphIndex) else f for f in fields
],
],
block_hash=await subtensor.determine_block_hash(None),
)
mock_from_dict.assert_called_once_with(mock_value)
Expand All @@ -3131,8 +3137,8 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker):
[
"invalid",
],
[SelectiveMetagraphIndex.Active, 1],
[1, 2, 3],
[SelectiveMetagraphIndex.Active, 1, "f"],
[1, 2, 3, "f"],
],
)
@pytest.mark.asyncio
Expand Down
14 changes: 10 additions & 4 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3428,7 +3428,7 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker):
# Preps
netuid = 1
mock_value = {"mock": "data"}
fields = [SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkey]
fields = [SelectiveMetagraphIndex.Name, 5]

mock_runtime_call = mocker.patch.object(
subtensor.substrate,
Expand All @@ -3447,7 +3447,13 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker):
mock_runtime_call.assert_called_once_with(
"SubnetInfoRuntimeApi",
"get_selective_metagraph",
params=[netuid, [0] + [f.value for f in fields]],
params=[
netuid,
[0]
+ [
f.value if isinstance(f, SelectiveMetagraphIndex) else f for f in fields
],
],
block_hash=subtensor.determine_block_hash(None),
)
mock_from_dict.assert_called_once_with(mock_value)
Expand All @@ -3459,8 +3465,8 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker):
[
"invalid",
],
[SelectiveMetagraphIndex.Active, 1],
[1, 2, 3],
[SelectiveMetagraphIndex.Active, 1, "f"],
[1, 2, 3, "f"],
],
)
def test_get_metagraph_info_invalid_field_indices(subtensor, wrong_fields):
Expand Down