Skip to content

Commit

Permalink
Merge branch 'staging' into feature/mvds00/axon-threads-and-exception…
Browse files Browse the repository at this point in the history
…-handling
  • Loading branch information
roman-opentensor authored Nov 22, 2024
2 parents 1bd5a0c + d460670 commit 29a0fa0
Show file tree
Hide file tree
Showing 11 changed files with 2,266 additions and 486 deletions.
70 changes: 36 additions & 34 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ async def encode_params(

return param_data.to_hex()

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.
Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.
Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
logging.error(f"subnet {netuid} does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

# Common subtensor methods =========================================================================================

async def get_current_block(self) -> int:
"""
Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.
Expand Down Expand Up @@ -663,39 +698,6 @@ async def subnet_exists(
)
return result

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.
Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.
Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
print("subnet does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

async def filter_netuids_by_registered_hotkeys(
self,
all_netuids: Iterable[int],
Expand Down Expand Up @@ -1357,7 +1359,7 @@ async def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]
call = await self.get_hyperparameter(param_name="LastUpdate", netuid=netuid)
return None if call is None else await self.get_current_block() - int(call[uid])

# extrinsics
# Extrinsics =======================================================================================================

async def transfer(
self,
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/extrinsics/async_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def register_extrinsic(
`True` if extrinsic was finalized or included in the block. If we did not wait for finalization/inclusion, the response is `True`.
"""

logging.debug("Checking subnet status")
logging.debug("[magenta]Checking subnet status... [/magenta]")
if not await subtensor.subnet_exists(netuid):
logging.error(
f":cross_mark: [red]Failed error:[/red] subnet [blue]{netuid}[/blue] does not exist."
Expand Down
Loading

0 comments on commit 29a0fa0

Please sign in to comment.