|
5 | 5 | from functools import partial |
6 | 6 | from typing import Optional, Any, Union, Iterable, TYPE_CHECKING |
7 | 7 |
|
8 | | -import aiohttp |
9 | 8 | import asyncstdlib as a |
10 | 9 | import numpy as np |
11 | 10 | import scalecodec |
|
28 | 27 | decode_account_id, |
29 | 28 | DynamicInfo, |
30 | 29 | ) |
| 30 | +from bittensor.core.chain_data.chain_identity import ChainIdentity |
31 | 31 | from bittensor.core.chain_data.delegate_info import DelegatedInfo |
32 | 32 | from bittensor.core.chain_data.utils import decode_metadata |
33 | 33 | from bittensor.core.config import Config |
|
68 | 68 | reveal_weights_extrinsic, |
69 | 69 | ) |
70 | 70 | from bittensor.core.metagraph import AsyncMetagraph |
71 | | -from bittensor.core.settings import version_as_int, TYPE_REGISTRY, DELEGATES_DETAILS_URL |
| 71 | +from bittensor.core.settings import version_as_int, TYPE_REGISTRY |
72 | 72 | from bittensor.core.types import ParamWithTypes, SubtensorMixin |
73 | 73 | from bittensor.utils import ( |
| 74 | + Certificate, |
74 | 75 | decode_hex_identity_dict, |
75 | 76 | format_error_message, |
76 | 77 | torch, |
77 | 78 | u16_normalized_float, |
78 | | - _decode_hex_identity_dict, |
79 | | - Certificate, |
80 | 79 | u64_normalized_float, |
81 | 80 | ) |
82 | 81 | from bittensor.utils.balance import ( |
|
85 | 84 | check_and_convert_to_balance, |
86 | 85 | ) |
87 | 86 | from bittensor.utils.btlogging import logging |
88 | | -from bittensor.utils.delegates_details import DelegatesDetails |
89 | 87 | from bittensor.utils.weight_utils import generate_weight_hash |
90 | 88 |
|
91 | 89 | if TYPE_CHECKING: |
@@ -1079,75 +1077,33 @@ async def get_delegate_identities( |
1079 | 1077 | block: Optional[int] = None, |
1080 | 1078 | block_hash: Optional[str] = None, |
1081 | 1079 | reuse_block: bool = False, |
1082 | | - ) -> dict[str, "DelegatesDetails"]: |
| 1080 | + ) -> dict[str, ChainIdentity]: |
1083 | 1081 | """ |
1084 | | - Fetches delegates identities from the chain and GitHub. Preference is given to chain data, and missing info is |
1085 | | - filled-in by the info from GitHub. At some point, we want to totally move away from fetching this info from |
1086 | | - GitHub, but chain data is still limited in that regard. |
| 1082 | + Fetches delegates identities from the chain. |
1087 | 1083 |
|
1088 | 1084 | Arguments: |
1089 | 1085 | block (Optional[int]): The blockchain block number for the query. |
1090 | 1086 | block_hash (str): the hash of the blockchain block for the query |
1091 | 1087 | reuse_block (bool): Whether to reuse the last-used blockchain block hash. |
1092 | 1088 |
|
1093 | 1089 | Returns: |
1094 | | - Dict {ss58: DelegatesDetails, ...} |
| 1090 | + Dict {ss58: ChainIdentity, ...} |
1095 | 1091 |
|
1096 | 1092 | """ |
1097 | 1093 | block_hash = await self.determine_block_hash(block, block_hash, reuse_block) |
1098 | | - timeout = aiohttp.ClientTimeout(10.0) |
1099 | | - async with aiohttp.ClientSession(timeout=timeout) as session: |
1100 | | - identities_info, response = await asyncio.gather( |
1101 | | - self.substrate.query_map( |
1102 | | - module="Registry", |
1103 | | - storage_function="IdentityOf", |
1104 | | - block_hash=block_hash, |
1105 | | - reuse_block_hash=reuse_block, |
1106 | | - ), |
1107 | | - session.get(DELEGATES_DETAILS_URL), |
1108 | | - ) |
1109 | | - |
1110 | | - all_delegates_details = {} |
1111 | | - async for ss58_address, identity in identities_info: |
1112 | | - all_delegates_details.update( |
1113 | | - { |
1114 | | - decode_account_id( |
1115 | | - ss58_address[0] |
1116 | | - ): DelegatesDetails.from_chain_data( |
1117 | | - decode_hex_identity_dict(identity.value["info"]) |
1118 | | - ) |
1119 | | - } |
1120 | | - ) |
1121 | | - |
1122 | | - if response.ok: |
1123 | | - all_delegates: dict[str, Any] = await response.json(content_type=None) |
1124 | | - |
1125 | | - for delegate_hotkey, delegate_details in all_delegates.items(): |
1126 | | - delegate_info = all_delegates_details.setdefault( |
1127 | | - delegate_hotkey, |
1128 | | - DelegatesDetails( |
1129 | | - display=delegate_details.get("name", ""), |
1130 | | - web=delegate_details.get("url", ""), |
1131 | | - additional=delegate_details.get("description", ""), |
1132 | | - pgp_fingerprint=delegate_details.get("fingerprint", ""), |
1133 | | - ), |
1134 | | - ) |
1135 | | - delegate_info.display = ( |
1136 | | - delegate_info.display or delegate_details.get("name", "") |
1137 | | - ) |
1138 | | - delegate_info.web = delegate_info.web or delegate_details.get( |
1139 | | - "url", "" |
1140 | | - ) |
1141 | | - delegate_info.additional = ( |
1142 | | - delegate_info.additional |
1143 | | - or delegate_details.get("description", "") |
1144 | | - ) |
1145 | | - delegate_info.pgp_fingerprint = ( |
1146 | | - delegate_info.pgp_fingerprint |
1147 | | - or delegate_details.get("fingerprint", "") |
1148 | | - ) |
| 1094 | + identities = await self.substrate.query_map( |
| 1095 | + module="SubtensorModule", |
| 1096 | + storage_function="IdentitiesV2", |
| 1097 | + block_hash=block_hash, |
| 1098 | + reuse_block_hash=reuse_block, |
| 1099 | + ) |
1149 | 1100 |
|
1150 | | - return all_delegates_details |
| 1101 | + return { |
| 1102 | + decode_account_id(ss58_address[0]): ChainIdentity.from_dict( |
| 1103 | + decode_hex_identity_dict(identity.value), |
| 1104 | + ) |
| 1105 | + async for ss58_address, identity in identities |
| 1106 | + } |
1151 | 1107 |
|
1152 | 1108 | async def get_delegate_take( |
1153 | 1109 | self, |
@@ -2424,7 +2380,7 @@ async def query_identity( |
2424 | 2380 | block: Optional[int] = None, |
2425 | 2381 | block_hash: Optional[str] = None, |
2426 | 2382 | reuse_block: bool = False, |
2427 | | - ) -> dict: |
| 2383 | + ) -> Optional[ChainIdentity]: |
2428 | 2384 | """ |
2429 | 2385 | Queries the identity of a neuron on the Bittensor blockchain using the given key. This function retrieves |
2430 | 2386 | detailed identity information about a specific neuron, which is a crucial aspect of the network's |
@@ -2455,12 +2411,16 @@ async def query_identity( |
2455 | 2411 | block_hash=block_hash, |
2456 | 2412 | reuse_block_hash=reuse_block, |
2457 | 2413 | ) |
| 2414 | + |
2458 | 2415 | if not identity_info: |
2459 | | - return {} |
| 2416 | + return None |
| 2417 | + |
2460 | 2418 | try: |
2461 | | - return _decode_hex_identity_dict(identity_info) |
| 2419 | + return ChainIdentity.from_dict( |
| 2420 | + decode_hex_identity_dict(identity_info), |
| 2421 | + ) |
2462 | 2422 | except TypeError: |
2463 | | - return {} |
| 2423 | + return None |
2464 | 2424 |
|
2465 | 2425 | async def recycle( |
2466 | 2426 | self, |
|
0 commit comments