Skip to content

Commit 547dbcb

Browse files
author
Roman
committed
Temporarily return the previous implementation of get_metagraph_info without SelectiveMetagraph.
1 parent b62cb6d commit 547dbcb

File tree

2 files changed

+15
-110
lines changed

2 files changed

+15
-110
lines changed

bittensor/core/async_subtensor.py

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
NeuronInfo,
2424
ProposalVoteData,
2525
StakeInfo,
26-
SelectiveMetagraphIndex,
2726
SubnetHyperparameters,
2827
SubnetIdentity,
2928
SubnetInfo,
@@ -1543,83 +1542,38 @@ async def get_minimum_required_stake(self):
15431542
async def get_metagraph_info(
15441543
self,
15451544
netuid: int,
1546-
field_indices: Optional[list["SelectiveMetagraphIndex"]] = None,
15471545
block: Optional[int] = None,
15481546
block_hash: Optional[str] = None,
15491547
reuse_block: bool = False,
15501548
) -> Optional[MetagraphInfo]:
15511549
"""
1552-
Retrieves full or partial metagraph information for the specified subnet (netuid).
1550+
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
15531551
15541552
Arguments:
1555-
netuid: The NetUID of the subnet to query.
1556-
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
1557-
not provided, all available fields will be returned.
1553+
netuid: The NetUID of the subnet.
15581554
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
15591555
reuse_block
15601556
block_hash: The hash of blockchain block number for the query. Do not specify if using
15611557
block or reuse_block
15621558
reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
15631559
15641560
Returns:
1565-
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
1566-
with the given netuid does not exist.
1567-
1568-
Example:
1569-
meta_info = await subtensor.get_metagraph_info(netuid=2)
1570-
1571-
partial_meta_info = await subtensor.get_metagraph_info(
1572-
netuid=2,
1573-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1574-
)
1561+
MetagraphInfo dataclass
15751562
"""
15761563
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
15771564
if not block_hash and reuse_block:
15781565
block_hash = self.substrate.last_block_hash
15791566

1580-
if field_indices is None:
1581-
query = await self.substrate.runtime_call(
1582-
"SubnetInfoRuntimeApi",
1583-
"get_metagraph",
1584-
params=[netuid],
1585-
block_hash=block_hash,
1586-
)
1587-
if query.value is None:
1588-
logging.error(f"Subnet {netuid} does not exist.")
1589-
return None
1590-
return MetagraphInfo.from_dict(query.value)
1591-
1592-
indexes = SelectiveMetagraphIndex.all_indices()
1593-
1594-
if field_indices:
1595-
if isinstance(field_indices, list) and all(
1596-
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
1597-
):
1598-
indexes = [
1599-
f.value if isinstance(f, SelectiveMetagraphIndex) else f
1600-
for f in field_indices
1601-
]
1602-
else:
1603-
raise ValueError(
1604-
"`field_indices` must be a list of SelectiveMetagraphIndex items."
1605-
)
1606-
16071567
query = await self.substrate.runtime_call(
16081568
"SubnetInfoRuntimeApi",
1609-
"get_selective_metagraph",
1610-
params=[netuid, indexes if 0 in indexes else [0] + indexes],
1569+
"get_metagraph",
1570+
params=[netuid],
16111571
block_hash=block_hash,
16121572
)
16131573
if query.value is None:
16141574
logging.error(f"Subnet {netuid} does not exist.")
16151575
return None
1616-
meta: MetagraphInfo = MetagraphInfo.from_dict(query.value)
1617-
# TODO: remove this after SelectiveMetagraph is updated in mainnet.
1618-
if meta.netuid == 0 and meta.name != "root":
1619-
logging.warning(
1620-
"Do not use the 'field_indices' argument while you see this message. Mainnet update pending."
1621-
)
1622-
return meta
1576+
return MetagraphInfo.from_dict(query.value)
16231577

16241578
async def get_all_metagraphs_info(
16251579
self,

bittensor/core/subtensor.py

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
MetagraphInfo,
2222
NeuronInfo,
2323
NeuronInfoLite,
24-
SelectiveMetagraphIndex,
2524
StakeInfo,
2625
SubnetInfo,
2726
SubnetIdentity,
@@ -1190,78 +1189,30 @@ def get_minimum_required_stake(self) -> Balance:
11901189
return Balance.from_rao(getattr(result, "value", 0))
11911190

11921191
def get_metagraph_info(
1193-
self,
1194-
netuid: int,
1195-
field_indices: Optional[list[Union["SelectiveMetagraphIndex", int]]] = None,
1196-
block: Optional[int] = None,
1192+
self, netuid: int, block: Optional[int] = None
11971193
) -> Optional[MetagraphInfo]:
11981194
"""
1199-
Retrieves full or partial metagraph information for the specified subnet (netuid).
1195+
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
12001196
12011197
Arguments:
1202-
netuid: The NetUID of the subnet to query.
1203-
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
1204-
not provided, all available fields will be returned.
1205-
block: The block number at which to query the data. If not specified, the current block or one determined
1206-
via reuse_block or block_hash will be used.
1198+
netuid: The NetUID of the subnet.
1199+
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
1200+
reuse_block
12071201
12081202
Returns:
1209-
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
1210-
with the given netuid does not exist.
1211-
1212-
Example:
1213-
meta_info = subtensor.get_metagraph_info(netuid=2)
1214-
1215-
partial_meta_info = subtensor.get_metagraph_info(
1216-
netuid=2,
1217-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1218-
)
1203+
MetagraphInfo dataclass
12191204
"""
12201205
block_hash = self.determine_block_hash(block)
1221-
1222-
if field_indices is None:
1223-
query = self.substrate.runtime_call(
1224-
"SubnetInfoRuntimeApi",
1225-
"get_metagraph",
1226-
params=[netuid],
1227-
block_hash=block_hash,
1228-
)
1229-
if query.value is None:
1230-
logging.error(f"Subnet {netuid} does not exist.")
1231-
return None
1232-
return MetagraphInfo.from_dict(query.value)
1233-
1234-
indexes = SelectiveMetagraphIndex.all_indices()
1235-
1236-
if field_indices:
1237-
if isinstance(field_indices, list) and all(
1238-
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
1239-
):
1240-
indexes = [
1241-
f.value if isinstance(f, SelectiveMetagraphIndex) else f
1242-
for f in field_indices
1243-
]
1244-
else:
1245-
raise ValueError(
1246-
"`field_indices` must be a list of SelectiveMetagraphIndex items or integers."
1247-
)
1248-
12491206
query = self.substrate.runtime_call(
12501207
"SubnetInfoRuntimeApi",
1251-
"get_selective_metagraph",
1252-
params=[netuid, indexes if 0 in indexes else [0] + indexes],
1208+
"get_metagraph",
1209+
params=[netuid],
12531210
block_hash=block_hash,
12541211
)
12551212
if query.value is None:
12561213
logging.error(f"Subnet {netuid} does not exist.")
12571214
return None
1258-
meta: MetagraphInfo = MetagraphInfo.from_dict(query.value)
1259-
# TODO: remove this after SelectiveMetagraph is updated in mainnet.
1260-
if meta.netuid == 0 and meta.name != "root":
1261-
logging.warning(
1262-
"Do not use the 'field_indices' argument while you see this message. Mainnet update pending."
1263-
)
1264-
return meta
1215+
return MetagraphInfo.from_dict(query.value)
12651216

12661217
def get_all_metagraphs_info(
12671218
self, block: Optional[int] = None

0 commit comments

Comments
 (0)