diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index 058bc10314..bb46e4ddc9 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -814,13 +814,21 @@ async def all_subnets( method="get_all_dynamic_info", block_hash=block_hash, ), - self.get_subnet_prices(), + self.get_subnet_prices(block_hash=block_hash), + return_exceptions=True, ) decoded = query.decode() - for sn in decoded: - sn.update({"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))}) + if not isinstance(subnet_prices, SubstrateRequestException): + for sn in decoded: + sn.update( + {"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))} + ) + else: + logging.warning( + f"Unable to fetch subnet prices for block {block_number}, block hash {block_hash}: {subnet_prices}" + ) return DynamicInfo.list_from_dicts(decoded) async def blocks_since_last_step( @@ -1129,21 +1137,30 @@ async def get_all_subnets_info( Notes: See also: """ - result = await self.query_runtime_api( - runtime_api="SubnetInfoRuntimeApi", - method="get_subnets_info_v2", - params=[], - block=block, - block_hash=block_hash, - reuse_block=reuse_block, + result, prices = await asyncio.gather( + self.query_runtime_api( + runtime_api="SubnetInfoRuntimeApi", + method="get_subnets_info_v2", + params=[], + block=block, + block_hash=block_hash, + reuse_block=reuse_block, + ), + self.get_subnet_prices( + block=block, block_hash=block_hash, reuse_block=reuse_block + ), + return_exceptions=True, ) if not result: return [] - subnets_prices = await self.get_subnet_prices() - - for subnet in result: - subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)}) + if not isinstance(prices, SubstrateRequestException): + for subnet in result: + subnet.update({"price": prices.get(subnet["netuid"], 0)}) + else: + logging.warning( + f"Unable to fetch subnet prices for block {block}, block hash {block_hash}: {prices}" + ) return SubnetInfo.list_from_dicts(result) @@ -2035,6 +2052,7 @@ async def get_metagraph_info( "SubnetInfoRuntimeApi", "get_metagraph", params=[netuid], + block_hash=block_hash, ) if query.value is None: diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index b64809ee15..b4b35d334a 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -455,10 +455,16 @@ def all_subnets(self, block: Optional[int] = None) -> Optional[list["DynamicInfo method="get_all_dynamic_info", block_hash=block_hash, ) - subnet_prices = self.get_subnet_prices() decoded = query.decode() - for sn in decoded: - sn.update({"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))}) + try: + subnet_prices = self.get_subnet_prices(block=block) + for sn in decoded: + sn.update( + {"price": subnet_prices.get(sn["netuid"], Balance.from_tao(0))} + ) + except SubstrateRequestException as e: + logging.warning(f"Unable to fetch subnet prices for block {block}: {e}") + return DynamicInfo.list_from_dicts(decoded) def blocks_since_last_step( @@ -644,11 +650,13 @@ def get_all_subnets_info(self, block: Optional[int] = None) -> list["SubnetInfo" ) if not result: return [] + try: + subnets_prices = self.get_subnet_prices(block=block) - subnets_prices = self.get_subnet_prices() - - for subnet in result: - subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)}) + for subnet in result: + subnet.update({"price": subnets_prices.get(subnet["netuid"], 0)}) + except SubstrateRequestException as e: + logging.warning(f"Unable to fetch subnet prices for block {block}: {e}") return SubnetInfo.list_from_dicts(result)