Skip to content

Commit d244791

Browse files
authored
Merge pull request #2662 from opentensor/feat/roman/add-subnet-identity-with-subnet-creation
feat/roman/add-subnet-identity-with-subnet-creation
2 parents 820b1e2 + 1fab7b0 commit d244791

File tree

10 files changed

+681
-9
lines changed

10 files changed

+681
-9
lines changed

bittensor/core/async_subtensor.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
NeuronInfo,
2222
ProposalVoteData,
2323
SubnetHyperparameters,
24+
SubnetIdentity,
2425
SubnetInfo,
2526
WeightCommitInfo,
2627
decode_account_id,
@@ -34,6 +35,7 @@
3435
burned_register_extrinsic,
3536
register_extrinsic,
3637
register_subnet_extrinsic,
38+
set_subnet_identity_extrinsic,
3739
)
3840
from bittensor.core.extrinsics.asyncex.move_stake import (
3941
transfer_stake_extrinsic,
@@ -2581,8 +2583,8 @@ async def wait_for_block(self, block: Optional[int] = None):
25812583
bool: True if the target block was reached, False if timeout occurred.
25822584
25832585
Example:
2584-
>>> await subtensor.wait_for_block() # Waits for next block
2585-
>>> await subtensor.wait_for_block(block=1234) # Waits for specific block
2586+
await subtensor.wait_for_block() # Waits for next block
2587+
await subtensor.wait_for_block(block=1234) # Waits for specific block
25862588
"""
25872589

25882590
async def handler(block_data: dict):
@@ -3188,6 +3190,44 @@ async def root_set_weights(
31883190
wait_for_inclusion=wait_for_inclusion,
31893191
)
31903192

3193+
async def set_subnet_identity(
3194+
self,
3195+
wallet: "Wallet",
3196+
netuid: int,
3197+
subnet_identity: SubnetIdentity,
3198+
wait_for_inclusion: bool = False,
3199+
wait_for_finalization: bool = True,
3200+
) -> tuple[bool, str]:
3201+
"""
3202+
Sets the identity of a subnet for a specific wallet and network.
3203+
3204+
Arguments:
3205+
wallet (Wallet): The wallet instance that will authorize the transaction.
3206+
netuid (int): The unique ID of the network on which the operation takes place.
3207+
subnet_identity (SubnetIdentity): The identity data of the subnet including attributes like name, GitHub
3208+
repository, contact, URL, discord, description, and any additional metadata.
3209+
wait_for_inclusion (bool): Indicates if the function should wait for the transaction to be included in the block.
3210+
wait_for_finalization (bool): Indicates if the function should wait for the transaction to reach finalization.
3211+
3212+
Returns:
3213+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the
3214+
operation, and the second element is a message providing additional information.
3215+
"""
3216+
return await set_subnet_identity_extrinsic(
3217+
subtensor=self,
3218+
wallet=wallet,
3219+
netuid=netuid,
3220+
subnet_name=subnet_identity.subnet_name,
3221+
github_repo=subnet_identity.github_repo,
3222+
subnet_contact=subnet_identity.subnet_contact,
3223+
subnet_url=subnet_identity.subnet_url,
3224+
discord=subnet_identity.discord,
3225+
description=subnet_identity.description,
3226+
additional=subnet_identity.additional,
3227+
wait_for_inclusion=wait_for_inclusion,
3228+
wait_for_finalization=wait_for_finalization,
3229+
)
3230+
31913231
async def set_weights(
31923232
self,
31933233
wallet: "Wallet",

bittensor/core/extrinsics/asyncex/registration.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,92 @@ async def register_subnet_extrinsic(
430430
if not wait_for_finalization and not wait_for_inclusion:
431431
return True
432432

433-
await response.process_events()
434433
if not await response.is_success:
435434
logging.error(
436-
f"Failed to register subnet: {format_error_message(await response.error_message, subtensor.substrate)}"
435+
f"Failed to register subnet: {format_error_message(await response.error_message)}"
437436
)
438437
return False
439438

440439
logging.success(
441440
":white_heavy_check_mark: [green]Successfully registered subnet[/green]"
442441
)
443442
return True
443+
444+
445+
async def set_subnet_identity_extrinsic(
446+
subtensor: "AsyncSubtensor",
447+
wallet: "Wallet",
448+
netuid: int,
449+
subnet_name: str,
450+
github_repo: str,
451+
subnet_contact: str,
452+
subnet_url: str,
453+
discord: str,
454+
description: str,
455+
additional: str,
456+
wait_for_inclusion: bool = False,
457+
wait_for_finalization: bool = True,
458+
) -> tuple[bool, str]:
459+
"""
460+
Set the identity information for a given subnet.
461+
462+
Arguments:
463+
subtensor (AsyncSubtensor): An instance of the Subtensor class to interact with the blockchain.
464+
wallet (Wallet): A wallet instance used to sign and submit the extrinsic.
465+
netuid (int): The unique ID for the subnet.
466+
subnet_name (str): The name of the subnet to assign the identity information.
467+
github_repo (str): URL of the GitHub repository related to the subnet.
468+
subnet_contact (str): Subnet's contact information, e.g., email or contact link.
469+
subnet_url (str): The URL of the subnet's primary web portal.
470+
discord (str): Discord server or contact for the subnet.
471+
description (str): A textual description of the subnet.
472+
additional (str): Any additional metadata or information related to the subnet.
473+
wait_for_inclusion (bool): Whether to wait for the extrinsic inclusion in a block (default: False).
474+
wait_for_finalization (bool): Whether to wait for the extrinsic finalization in a block (default: True).
475+
476+
Returns:
477+
tuple[bool, str]: A tuple where the first element indicates success or failure (True/False), and the second
478+
element contains a descriptive message.
479+
"""
480+
481+
if not (unlock := unlock_key(wallet)).success:
482+
logging.error(unlock.message)
483+
return False, unlock.message
484+
485+
call = await subtensor.substrate.compose_call(
486+
call_module="SubtensorModule",
487+
call_function="set_subnet_identity",
488+
call_params={
489+
"hotkey": wallet.hotkey.ss58_address,
490+
"netuid": netuid,
491+
"subnet_name": subnet_name,
492+
"github_repo": github_repo,
493+
"subnet_contact": subnet_contact,
494+
"subnet_url": subnet_url,
495+
"discord": discord,
496+
"description": description,
497+
"additional": additional,
498+
},
499+
)
500+
501+
response = await subtensor.substrate.submit_extrinsic(
502+
call=call,
503+
wallet=wallet,
504+
wait_for_inclusion=wait_for_inclusion,
505+
wait_for_finalization=wait_for_finalization,
506+
)
507+
508+
if not wait_for_finalization and not wait_for_inclusion:
509+
return True, f"Identities for subnet {netuid} are sent to the chain."
510+
511+
if await response.is_success:
512+
logging.success(
513+
f":white_heavy_check_mark: [green]Identities for subnet[/green] [blue]{netuid}[/blue] [green]are set.[/green]"
514+
)
515+
return True, f"Identities for subnet {netuid} are set."
516+
else:
517+
error_message = await response.error_message
518+
logging.error(
519+
f":cross_mark: Failed to set identity for subnet [blue]{netuid}[/blue]: {error_message}"
520+
)
521+
return False, f"Failed to set identity for subnet {netuid}: {error_message}"

bittensor/core/extrinsics/registration.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,81 @@ def register_extrinsic(
424424
# Failed to register after max attempts.
425425
logging.error("[red]No more attempts.[/red]")
426426
return False
427+
428+
429+
def set_subnet_identity_extrinsic(
430+
subtensor: "Subtensor",
431+
wallet: "Wallet",
432+
netuid: int,
433+
subnet_name: str,
434+
github_repo: str,
435+
subnet_contact: str,
436+
subnet_url: str,
437+
discord: str,
438+
description: str,
439+
additional: str,
440+
wait_for_inclusion: bool = False,
441+
wait_for_finalization: bool = True,
442+
) -> tuple[bool, str]:
443+
"""
444+
Set the identity information for a given subnet.
445+
446+
Arguments:
447+
subtensor (Subtensor): An instance of the Subtensor class to interact with the blockchain.
448+
wallet (Wallet): A wallet instance used to sign and submit the extrinsic.
449+
netuid (int): The unique ID for the subnet.
450+
subnet_name (str): The name of the subnet to assign the identity information.
451+
github_repo (str): URL of the GitHub repository related to the subnet.
452+
subnet_contact (str): Subnet's contact information, e.g., email or contact link.
453+
subnet_url (str): The URL of the subnet's primary web portal.
454+
discord (str): Discord server or contact for the subnet.
455+
description (str): A textual description of the subnet.
456+
additional (str): Any additional metadata or information related to the subnet.
457+
wait_for_inclusion (bool): Whether to wait for the extrinsic inclusion in a block (default: False).
458+
wait_for_finalization (bool): Whether to wait for the extrinsic finalization in a block (default: True).
459+
460+
Returns:
461+
tuple[bool, str]: A tuple where the first element indicates success or failure (True/False), and the second
462+
element contains a descriptive message.
463+
"""
464+
465+
if not (unlock := unlock_key(wallet)).success:
466+
logging.error(unlock.message)
467+
return False, unlock.message
468+
469+
call = subtensor.substrate.compose_call(
470+
call_module="SubtensorModule",
471+
call_function="set_subnet_identity",
472+
call_params={
473+
"hotkey": wallet.hotkey.ss58_address,
474+
"netuid": netuid,
475+
"subnet_name": subnet_name,
476+
"github_repo": github_repo,
477+
"subnet_contact": subnet_contact,
478+
"subnet_url": subnet_url,
479+
"discord": discord,
480+
"description": description,
481+
"additional": additional,
482+
},
483+
)
484+
485+
success, message = subtensor.sign_and_send_extrinsic(
486+
call=call,
487+
wallet=wallet,
488+
wait_for_inclusion=wait_for_inclusion,
489+
wait_for_finalization=wait_for_finalization,
490+
)
491+
492+
if not wait_for_finalization and not wait_for_inclusion:
493+
return True, f"Identities for subnet {netuid} are sent to the chain."
494+
495+
if success:
496+
logging.success(
497+
f":white_heavy_check_mark: [green]Identities for subnet[/green] [blue]{netuid}[/blue] [green]are set.[/green]"
498+
)
499+
return True, f"Identities for subnet {netuid} are set."
500+
else:
501+
logging.error(
502+
f":cross_mark: Failed to set identity for subnet [blue]{netuid}[/blue]: {message}"
503+
)
504+
return False, f"Failed to set identity for subnet {netuid}: {message}"

bittensor/core/subtensor.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
StakeInfo,
2222
SubnetHyperparameters,
2323
WeightCommitInfo,
24+
SubnetIdentity,
2425
SubnetInfo,
2526
decode_account_id,
2627
)
@@ -40,6 +41,7 @@
4041
burned_register_extrinsic,
4142
register_extrinsic,
4243
register_subnet_extrinsic,
44+
set_subnet_identity_extrinsic,
4345
)
4446
from bittensor.core.extrinsics.root import (
4547
root_register_extrinsic,
@@ -2526,6 +2528,44 @@ def root_set_weights(
25262528
wait_for_inclusion=wait_for_inclusion,
25272529
)
25282530

2531+
def set_subnet_identity(
2532+
self,
2533+
wallet: "Wallet",
2534+
netuid: int,
2535+
subnet_identity: SubnetIdentity,
2536+
wait_for_inclusion: bool = False,
2537+
wait_for_finalization: bool = True,
2538+
) -> tuple[bool, str]:
2539+
"""
2540+
Sets the identity of a subnet for a specific wallet and network.
2541+
2542+
Arguments:
2543+
wallet (Wallet): The wallet instance that will authorize the transaction.
2544+
netuid (int): The unique ID of the network on which the operation takes place.
2545+
subnet_identity (SubnetIdentity): The identity data of the subnet including attributes like name, GitHub
2546+
repository, contact, URL, discord, description, and any additional metadata.
2547+
wait_for_inclusion (bool): Indicates if the function should wait for the transaction to be included in the block.
2548+
wait_for_finalization (bool): Indicates if the function should wait for the transaction to reach finalization.
2549+
2550+
Returns:
2551+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the
2552+
operation, and the second element is a message providing additional information.
2553+
"""
2554+
return set_subnet_identity_extrinsic(
2555+
subtensor=self,
2556+
wallet=wallet,
2557+
netuid=netuid,
2558+
subnet_name=subnet_identity.subnet_name,
2559+
github_repo=subnet_identity.github_repo,
2560+
subnet_contact=subnet_identity.subnet_contact,
2561+
subnet_url=subnet_identity.subnet_url,
2562+
discord=subnet_identity.discord,
2563+
description=subnet_identity.description,
2564+
additional=subnet_identity.additional,
2565+
wait_for_inclusion=wait_for_inclusion,
2566+
wait_for_finalization=wait_for_finalization,
2567+
)
2568+
25292569
def set_weights(
25302570
self,
25312571
wallet: "Wallet",

bittensor/utils/easy_imports.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,27 @@
3232
from bittensor.core.axon import Axon
3333
from bittensor.core.chain_data import ( # noqa: F401
3434
AxonInfo,
35+
ChainIdentity,
36+
DelegateInfo,
37+
DelegateInfoLite,
38+
DynamicInfo,
39+
IPInfo,
40+
MetagraphInfo,
41+
MetagraphInfoEmissions,
42+
MetagraphInfoParams,
43+
MetagraphInfoPool,
3544
NeuronInfo,
3645
NeuronInfoLite,
3746
PrometheusInfo,
38-
DelegateInfo,
39-
StakeInfo,
40-
SubnetInfo,
41-
SubnetHyperparameters,
42-
IPInfo,
4347
ProposalCallData,
4448
ProposalVoteData,
49+
ScheduledColdkeySwapInfo,
50+
StakeInfo,
51+
SubnetHyperparameters,
52+
SubnetIdentity,
53+
SubnetInfo,
54+
SubnetState,
55+
WeightCommitInfo,
4556
)
4657
from bittensor.core.config import ( # noqa: F401
4758
InvalidConfigFile,

0 commit comments

Comments
 (0)