Skip to content

Commit 839e20b

Browse files
author
Roman
committed
add is_subnet_active in subtensors
1 parent a8ba38c commit 839e20b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

bittensor/core/async_subtensor.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,35 @@ async def is_hotkey_registered_on_subnet(
25822582
is not None
25832583
)
25842584

2585+
async def is_subnet_active(
2586+
self,
2587+
netuid: int,
2588+
block: Optional[int] = None,
2589+
block_hash: Optional[str] = None,
2590+
reuse_block: bool = False,
2591+
) -> bool:
2592+
"""Verify if subnet with provided netuid is active.
2593+
2594+
Args:
2595+
netuid (int): The unique identifier of the subnet.
2596+
block (Optional[int]): The blockchain block number for the query.
2597+
block_hash (Optional[str]): The blockchain block_hash representation of block id.
2598+
reuse_block (bool): Whether to reuse the last-used block hash.
2599+
2600+
Returns:
2601+
True if subnet is active, False otherwise.
2602+
2603+
This means whether the `start_call` was initiated or not.
2604+
"""
2605+
query = await self.query_subtensor(
2606+
name="FirstEmissionBlockNumber",
2607+
block=block,
2608+
block_hash=block_hash,
2609+
reuse_block=reuse_block,
2610+
params=[netuid],
2611+
)
2612+
return True if query and query.value > 0 else False
2613+
25852614
async def last_drand_round(self) -> Optional[int]:
25862615
"""
25872616
Retrieves the last drand round emitted in bittensor. This corresponds when committed weights will be revealed.

bittensor/core/subtensor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,25 @@ def is_hotkey_registered_on_subnet(
20232023
is not None
20242024
)
20252025

2026+
def is_subnet_active(self, netuid: int, block: Optional[int] = None) -> bool:
2027+
"""Verify if subnet with provided netuid is active.
2028+
2029+
Args:
2030+
netuid (int): The unique identifier of the subnet.
2031+
block (Optional[int]): The blockchain block number for the query.
2032+
2033+
Returns:
2034+
True if subnet is active, False otherwise.
2035+
2036+
This means whether the `start_call` was initiated or not.
2037+
"""
2038+
query = self.query_subtensor(
2039+
name="FirstEmissionBlockNumber",
2040+
block=block,
2041+
params=[netuid],
2042+
)
2043+
return True if query and query.value > 0 else False
2044+
20262045
def last_drand_round(self) -> Optional[int]:
20272046
"""
20282047
Retrieves the last drand round emitted in bittensor. This corresponds when committed weights will be revealed.

0 commit comments

Comments
 (0)