Skip to content

Commit 51ad4f4

Browse files
committed
More missed
1 parent a5ddfd4 commit 51ad4f4

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

bittensor/core/async_subtensor.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,20 @@ async def all_subnets(
815815
block_hash=block_hash,
816816
),
817817
self.get_subnet_prices(block_hash=block_hash),
818+
return_exceptions=True,
818819
)
819820

820821
decoded = query.decode()
821822

822-
for sn in decoded:
823-
sn.update({"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))})
823+
if not isinstance(subnet_prices, SubstrateRequestException):
824+
for sn in decoded:
825+
sn.update(
826+
{"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))}
827+
)
828+
else:
829+
logging.warning(
830+
f"Unable to fetch subnet prices for block {block_number}, block hash {block_hash}"
831+
)
824832
return DynamicInfo.list_from_dicts(decoded)
825833

826834
async def blocks_since_last_step(
@@ -1129,21 +1137,30 @@ async def get_all_subnets_info(
11291137
Notes:
11301138
See also: <https://docs.learnbittensor.org/glossary#subnet>
11311139
"""
1132-
result = await self.query_runtime_api(
1133-
runtime_api="SubnetInfoRuntimeApi",
1134-
method="get_subnets_info_v2",
1135-
params=[],
1136-
block=block,
1137-
block_hash=block_hash,
1138-
reuse_block=reuse_block,
1140+
result, prices = await asyncio.gather(
1141+
self.query_runtime_api(
1142+
runtime_api="SubnetInfoRuntimeApi",
1143+
method="get_subnets_info_v2",
1144+
params=[],
1145+
block=block,
1146+
block_hash=block_hash,
1147+
reuse_block=reuse_block,
1148+
),
1149+
self.get_subnet_prices(
1150+
block=block, block_hash=block_hash, reuse_block=reuse_block
1151+
),
1152+
return_exceptions=True,
11391153
)
11401154
if not result:
11411155
return []
11421156

1143-
subnets_prices = await self.get_subnet_prices()
1144-
1145-
for subnet in result:
1146-
subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)})
1157+
if not isinstance(prices, SubstrateRequestException):
1158+
for subnet in result:
1159+
subnet.update({"price": prices.get(subnet["netuid"], 0)})
1160+
else:
1161+
logging.warning(
1162+
f"Unable to fetch subnet prices for block {block}, block hash {block_hash}"
1163+
)
11471164

11481165
return SubnetInfo.list_from_dicts(result)
11491166

bittensor/core/subtensor.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,16 @@ def all_subnets(self, block: Optional[int] = None) -> Optional[list["DynamicInfo
455455
method="get_all_dynamic_info",
456456
block_hash=block_hash,
457457
)
458-
subnet_prices = self.get_subnet_prices(block=block)
459458
decoded = query.decode()
460-
for sn in decoded:
461-
sn.update({"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))})
459+
try:
460+
subnet_prices = self.get_subnet_prices(block=block)
461+
for sn in decoded:
462+
sn.update(
463+
{"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))}
464+
)
465+
except SubstrateRequestException:
466+
logging.warning(f"Unable to fetch subnet prices for block {block}")
467+
462468
return DynamicInfo.list_from_dicts(decoded)
463469

464470
def blocks_since_last_step(
@@ -644,11 +650,13 @@ def get_all_subnets_info(self, block: Optional[int] = None) -> list["SubnetInfo"
644650
)
645651
if not result:
646652
return []
653+
try:
654+
subnets_prices = self.get_subnet_prices(block=block)
647655

648-
subnets_prices = self.get_subnet_prices()
649-
650-
for subnet in result:
651-
subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)})
656+
for subnet in result:
657+
subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)})
658+
except SubstrateRequestException:
659+
logging.warning(f"Unable to fetch subnet prices for block {block}")
652660

653661
return SubnetInfo.list_from_dicts(result)
654662

0 commit comments

Comments
 (0)