Skip to content

Commit dd35bfa

Browse files
committed
Updated Subtensor and AsyncSubtensor's get_children method to return normalised float values.
1 parent 606f5aa commit dd35bfa

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

bittensor/core/async_subtensor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
u16_normalized_float,
7676
_decode_hex_identity_dict,
7777
Certificate,
78+
u64_normalized_float,
7879
)
7980
from bittensor.utils.balance import (
8081
Balance,
@@ -891,7 +892,7 @@ async def get_children(
891892
block: Optional[int] = None,
892893
block_hash: Optional[str] = None,
893894
reuse_block: bool = False,
894-
) -> tuple[bool, list, str]:
895+
) -> tuple[bool, list[tuple[float, str]], str]:
895896
"""
896897
This method retrieves the children of a given hotkey and netuid. It queries the SubtensorModule's ChildKeys
897898
storage function to get the children and formats them before returning as a tuple.
@@ -921,8 +922,8 @@ async def get_children(
921922
for proportion, child in children.value:
922923
# Convert U64 to int
923924
formatted_child = decode_account_id(child[0])
924-
int_proportion = int(proportion)
925-
formatted_children.append((int_proportion, formatted_child))
925+
normalized_proportion = u64_normalized_float(proportion)
926+
formatted_children.append((normalized_proportion, formatted_child))
926927
return True, formatted_children, ""
927928
else:
928929
return True, [], ""

bittensor/core/subtensor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
u16_normalized_float,
7979
_decode_hex_identity_dict,
8080
Certificate,
81+
u64_normalized_float,
8182
)
8283
from bittensor.utils.balance import (
8384
Balance,
@@ -678,7 +679,7 @@ def get_hyperparameter(
678679

679680
def get_children(
680681
self, hotkey: str, netuid: int, block: Optional[int] = None
681-
) -> tuple[bool, list, str]:
682+
) -> tuple[bool, list[tuple[float, str]], str]:
682683
"""
683684
This method retrieves the children of a given hotkey and netuid. It queries the SubtensorModule's ChildKeys
684685
storage function to get the children and formats them before returning as a tuple.
@@ -704,8 +705,8 @@ def get_children(
704705
for proportion, child in children.value:
705706
# Convert U64 to int
706707
formatted_child = decode_account_id(child[0])
707-
int_proportion = int(proportion)
708-
formatted_children.append((int_proportion, formatted_child))
708+
normalized_proportion = u64_normalized_float(proportion)
709+
formatted_children.append((normalized_proportion, formatted_child))
709710
return True, formatted_children, ""
710711
else:
711712
return True, [], ""

tests/unit_tests/test_async_subtensor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from bittensor_wallet import Wallet
55

6+
from bittensor import u64_normalized_float
67
from bittensor.core import async_subtensor
78
from bittensor.core.async_subtensor import AsyncSubtensor
89
from bittensor.core.chain_data.stake_info import StakeInfo
@@ -1765,8 +1766,8 @@ async def test_get_children_success(subtensor, mocker):
17651766
mocker.patch.object(async_subtensor, "decode_account_id", mocked_decode_account_id)
17661767

17671768
expected_formatted_children = [
1768-
(1000, "decoded_child_key_1"),
1769-
(2000, "decoded_child_key_2"),
1769+
(u64_normalized_float(1000), "decoded_child_key_1"),
1770+
(u64_normalized_float(2000), "decoded_child_key_2"),
17701771
]
17711772

17721773
# Call

0 commit comments

Comments
 (0)