Skip to content

Commit b62cb6d

Browse files
author
Roman
committed
update get_metagraph_info
1 parent 3835390 commit b62cb6d

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

bittensor/core/async_subtensor.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,22 @@ async def get_metagraph_info(
15731573
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
15741574
)
15751575
"""
1576+
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
1577+
if not block_hash and reuse_block:
1578+
block_hash = self.substrate.last_block_hash
1579+
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+
15761592
indexes = SelectiveMetagraphIndex.all_indices()
15771593

15781594
if field_indices:
@@ -1588,10 +1604,6 @@ async def get_metagraph_info(
15881604
"`field_indices` must be a list of SelectiveMetagraphIndex items."
15891605
)
15901606

1591-
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
1592-
if not block_hash and reuse_block:
1593-
block_hash = self.substrate.last_block_hash
1594-
15951607
query = await self.substrate.runtime_call(
15961608
"SubnetInfoRuntimeApi",
15971609
"get_selective_metagraph",
@@ -1601,7 +1613,13 @@ async def get_metagraph_info(
16011613
if query.value is None:
16021614
logging.error(f"Subnet {netuid} does not exist.")
16031615
return None
1604-
return MetagraphInfo.from_dict(query.value)
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
16051623

16061624
async def get_all_metagraphs_info(
16071625
self,

bittensor/core/subtensor.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,20 @@ def get_metagraph_info(
12171217
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
12181218
)
12191219
"""
1220+
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+
12201234
indexes = SelectiveMetagraphIndex.all_indices()
12211235

12221236
if field_indices:
@@ -1229,10 +1243,9 @@ def get_metagraph_info(
12291243
]
12301244
else:
12311245
raise ValueError(
1232-
"`field_indices` must be a list of SelectiveMetagraphIndex items."
1246+
"`field_indices` must be a list of SelectiveMetagraphIndex items or integers."
12331247
)
12341248

1235-
block_hash = self.determine_block_hash(block)
12361249
query = self.substrate.runtime_call(
12371250
"SubnetInfoRuntimeApi",
12381251
"get_selective_metagraph",
@@ -1242,7 +1255,13 @@ def get_metagraph_info(
12421255
if query.value is None:
12431256
logging.error(f"Subnet {netuid} does not exist.")
12441257
return None
1245-
return MetagraphInfo.from_dict(query.value)
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
12461265

12471266
def get_all_metagraphs_info(
12481267
self, block: Optional[int] = None

0 commit comments

Comments
 (0)