|
71 | 71 | transfer_extrinsic,
|
72 | 72 | )
|
73 | 73 | from bittensor.core.metagraph import Metagraph
|
74 |
| -from bittensor.utils import networking, torch, ss58_to_vec_u8, u16_normalized_float |
| 74 | +from bittensor.utils import ( |
| 75 | + networking, |
| 76 | + torch, |
| 77 | + ss58_to_vec_u8, |
| 78 | + u16_normalized_float, |
| 79 | + hex_to_bytes, |
| 80 | +) |
75 | 81 | from bittensor.utils.balance import Balance
|
76 | 82 | from bittensor.utils.btlogging import logging
|
77 | 83 | from bittensor.utils.registration import legacy_torch_api_compat
|
@@ -523,13 +529,11 @@ def query_runtime_api(
|
523 | 529 | return None
|
524 | 530 |
|
525 | 531 | return_type = call_definition["type"]
|
526 |
| - |
527 | 532 | as_scale_bytes = scalecodec.ScaleBytes(json_result["result"])
|
528 | 533 |
|
529 | 534 | rpc_runtime_config = RuntimeConfiguration()
|
530 | 535 | rpc_runtime_config.update_type_registry(load_type_registry_preset("legacy"))
|
531 | 536 | rpc_runtime_config.update_type_registry(custom_rpc_type_registry)
|
532 |
| - |
533 | 537 | obj = rpc_runtime_config.create_scale_object(return_type, as_scale_bytes)
|
534 | 538 | if obj.data.to_hex() == "0x0400": # RPC returned None result
|
535 | 539 | return None
|
@@ -1227,12 +1231,7 @@ def get_subnet_hyperparameters(
|
1227 | 1231 | if hex_bytes_result is None:
|
1228 | 1232 | return []
|
1229 | 1233 |
|
1230 |
| - if hex_bytes_result.startswith("0x"): |
1231 |
| - bytes_result = bytes.fromhex(hex_bytes_result[2:]) |
1232 |
| - else: |
1233 |
| - bytes_result = bytes.fromhex(hex_bytes_result) |
1234 |
| - |
1235 |
| - return SubnetHyperparameters.from_vec_u8(bytes_result) |
| 1234 | + return SubnetHyperparameters.from_vec_u8(hex_to_bytes(hex_bytes_result)) |
1236 | 1235 |
|
1237 | 1236 | # Community uses this method
|
1238 | 1237 | # Returns network ImmunityPeriod hyper parameter.
|
@@ -1308,10 +1307,13 @@ def get_commitment(self, netuid: int, uid: int, block: Optional[int] = None) ->
|
1308 | 1307 | hotkey = metagraph.hotkeys[uid] # type: ignore
|
1309 | 1308 |
|
1310 | 1309 | metadata = get_metadata(self, netuid, hotkey, block)
|
1311 |
| - commitment = metadata["info"]["fields"][0] # type: ignore |
1312 |
| - hex_data = commitment[list(commitment.keys())[0]][2:] # type: ignore |
| 1310 | + try: |
| 1311 | + commitment = metadata["info"]["fields"][0] # type: ignore |
| 1312 | + hex_data = commitment[list(commitment.keys())[0]][2:] # type: ignore |
| 1313 | + return bytes.fromhex(hex_data).decode() |
1313 | 1314 |
|
1314 |
| - return bytes.fromhex(hex_data).decode() |
| 1315 | + except TypeError: |
| 1316 | + return "" |
1315 | 1317 |
|
1316 | 1318 | # Community uses this via `bittensor.utils.weight_utils.process_weights_for_netuid` function.
|
1317 | 1319 | def min_allowed_weights(
|
@@ -1367,7 +1369,7 @@ def get_prometheus_info(
|
1367 | 1369 | Optional[bittensor.core.chain_data.prometheus_info.PrometheusInfo]: A PrometheusInfo object containing the prometheus information, or ``None`` if the prometheus information is not found.
|
1368 | 1370 | """
|
1369 | 1371 | result = self.query_subtensor("Prometheus", block, [netuid, hotkey_ss58])
|
1370 |
| - if result is not None and hasattr(result, "value"): |
| 1372 | + if result is not None and getattr(result, "value", None) is not None: |
1371 | 1373 | return PrometheusInfo(
|
1372 | 1374 | ip=networking.int_to_ip(result.value["ip"]),
|
1373 | 1375 | ip_type=result.value["ip_type"],
|
@@ -1407,17 +1409,13 @@ def get_all_subnets_info(self, block: Optional[int] = None) -> list[SubnetInfo]:
|
1407 | 1409 |
|
1408 | 1410 | Gaining insights into the subnets' details assists in understanding the network's composition, the roles of different subnets, and their unique features.
|
1409 | 1411 | """
|
1410 |
| - block_hash = None if block is None else self.substrate.get_block_hash(block) |
1411 |
| - |
1412 |
| - json_body = self.substrate.rpc_request( |
1413 |
| - method="subnetInfo_getSubnetsInfo", # custom rpc method |
1414 |
| - params=[block_hash] if block_hash else [], |
| 1412 | + hex_bytes_result = self.query_runtime_api( |
| 1413 | + "SubnetInfoRuntimeApi", "get_subnets_info", params=[], block=block |
1415 | 1414 | )
|
1416 |
| - |
1417 |
| - if not (result := json_body.get("result", None)): |
| 1415 | + if not hex_bytes_result: |
1418 | 1416 | return []
|
1419 |
| - |
1420 |
| - return SubnetInfo.list_from_vec_u8(result) |
| 1417 | + else: |
| 1418 | + return SubnetInfo.list_from_vec_u8(hex_to_bytes(hex_bytes_result)) |
1421 | 1419 |
|
1422 | 1420 | # Metagraph uses this method
|
1423 | 1421 | def bonds(
|
@@ -1561,12 +1559,7 @@ def neurons_lite(
|
1561 | 1559 | if hex_bytes_result is None:
|
1562 | 1560 | return []
|
1563 | 1561 |
|
1564 |
| - if hex_bytes_result.startswith("0x"): |
1565 |
| - bytes_result = bytes.fromhex(hex_bytes_result[2:]) |
1566 |
| - else: |
1567 |
| - bytes_result = bytes.fromhex(hex_bytes_result) |
1568 |
| - |
1569 |
| - return NeuronInfoLite.list_from_vec_u8(bytes_result) # type: ignore |
| 1562 | + return NeuronInfoLite.list_from_vec_u8(hex_to_bytes(hex_bytes_result)) # type: ignore |
1570 | 1563 |
|
1571 | 1564 | # Used in the `neurons` method which is used in metagraph.py
|
1572 | 1565 | def weights(
|
@@ -1923,7 +1916,7 @@ def get_delegate_by_hotkey(
|
1923 | 1916 | if not (result := json_body.get("result", None)):
|
1924 | 1917 | return None
|
1925 | 1918 |
|
1926 |
| - return DelegateInfo.from_vec_u8(result) |
| 1919 | + return DelegateInfo.from_vec_u8(bytes(result)) |
1927 | 1920 |
|
1928 | 1921 | # Subnet 27 uses this method name
|
1929 | 1922 | _do_serve_axon = do_serve_axon
|
0 commit comments