Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1129,21 +1137,30 @@ async def get_all_subnets_info(
Notes:
See also: <https://docs.learnbittensor.org/glossary#subnet>
"""
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)

Expand Down Expand Up @@ -2035,6 +2052,7 @@ async def get_metagraph_info(
"SubnetInfoRuntimeApi",
"get_metagraph",
params=[netuid],
block_hash=block_hash,
)

if query.value is None:
Expand Down
22 changes: 15 additions & 7 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
Loading