|
77 | 77 | from bittensor.utils import (
|
78 | 78 | Certificate,
|
79 | 79 | decode_hex_identity_dict,
|
| 80 | + float_to_u64, |
80 | 81 | format_error_message,
|
81 | 82 | torch,
|
82 | 83 | u16_normalized_float,
|
83 | 84 | u64_normalized_float,
|
| 85 | + unlock_key, |
84 | 86 | )
|
85 | 87 | from bittensor.utils.balance import (
|
86 | 88 | Balance,
|
@@ -934,6 +936,57 @@ async def get_children(
|
934 | 936 | except SubstrateRequestException as e:
|
935 | 937 | return False, [], format_error_message(e)
|
936 | 938 |
|
| 939 | + async def get_children_pending( |
| 940 | + self, |
| 941 | + hotkey: str, |
| 942 | + netuid: int, |
| 943 | + block: Optional[int] = None, |
| 944 | + block_hash: Optional[str] = None, |
| 945 | + reuse_block: bool = False, |
| 946 | + ) -> tuple[ |
| 947 | + list[tuple[float, str]], |
| 948 | + int, |
| 949 | + ]: |
| 950 | + """ |
| 951 | + This method retrieves the pending children of a given hotkey and netuid. |
| 952 | + It queries the SubtensorModule's PendingChildKeys storage function. |
| 953 | +
|
| 954 | + Arguments: |
| 955 | + hotkey (str): The hotkey value. |
| 956 | + netuid (int): The netuid value. |
| 957 | + block (Optional[int]): The block number for which the children are to be retrieved. |
| 958 | + block_hash (Optional[str]): The hash of the block to retrieve the subnet unique identifiers from. |
| 959 | + reuse_block (bool): Whether to reuse the last-used block hash. |
| 960 | +
|
| 961 | + Returns: |
| 962 | + list[tuple[float, str]]: A list of children with their proportions. |
| 963 | + int: The cool-down block number. |
| 964 | + """ |
| 965 | + |
| 966 | + response = await self.substrate.query( |
| 967 | + module="SubtensorModule", |
| 968 | + storage_function="PendingChildKeys", |
| 969 | + params=[netuid, hotkey], |
| 970 | + block_hash=await self.determine_block_hash( |
| 971 | + block, |
| 972 | + block_hash, |
| 973 | + reuse_block, |
| 974 | + ), |
| 975 | + reuse_block_hash=reuse_block, |
| 976 | + ) |
| 977 | + children, cooldown = response.value |
| 978 | + |
| 979 | + return ( |
| 980 | + [ |
| 981 | + ( |
| 982 | + u64_normalized_float(proportion), |
| 983 | + decode_account_id(child[0]), |
| 984 | + ) |
| 985 | + for proportion, child in children |
| 986 | + ], |
| 987 | + cooldown, |
| 988 | + ) |
| 989 | + |
937 | 990 | async def get_commitment(
|
938 | 991 | self,
|
939 | 992 | netuid: int,
|
@@ -3381,6 +3434,75 @@ async def root_set_weights(
|
3381 | 3434 | wait_for_inclusion=wait_for_inclusion,
|
3382 | 3435 | )
|
3383 | 3436 |
|
| 3437 | + async def set_children( |
| 3438 | + self, |
| 3439 | + wallet: "Wallet", |
| 3440 | + hotkey: str, |
| 3441 | + netuid: int, |
| 3442 | + children: list[tuple[float, str]], |
| 3443 | + wait_for_inclusion: bool = True, |
| 3444 | + wait_for_finalization: bool = True, |
| 3445 | + raise_error: bool = False, |
| 3446 | + ) -> tuple[bool, str]: |
| 3447 | + """ |
| 3448 | + Allows a coldkey to set children keys. |
| 3449 | +
|
| 3450 | + Arguments: |
| 3451 | + wallet (bittensor_wallet.Wallet): bittensor wallet instance. |
| 3452 | + hotkey (str): The ``SS58`` address of the neuron's hotkey. |
| 3453 | + netuid (int): The netuid value. |
| 3454 | + children (list[tuple[float, str]]): A list of children with their proportions. |
| 3455 | + wait_for_inclusion (bool): Waits for the transaction to be included in a block. |
| 3456 | + wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. |
| 3457 | + raise_error: Raises relevant exception rather than returning `False` if unsuccessful. |
| 3458 | +
|
| 3459 | + Returns: |
| 3460 | + tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the |
| 3461 | + operation, and the second element is a message providing additional information. |
| 3462 | +
|
| 3463 | + Raises: |
| 3464 | + DuplicateChild: There are duplicates in the list of children. |
| 3465 | + InvalidChild: Child is the hotkey. |
| 3466 | + NonAssociatedColdKey: The coldkey does not own the hotkey or the child is the same as the hotkey. |
| 3467 | + NotEnoughStakeToSetChildkeys: Parent key doesn't have minimum own stake. |
| 3468 | + ProportionOverflow: The sum of the proportions does exceed uint64. |
| 3469 | + RegistrationNotPermittedOnRootSubnet: Attempting to register a child on the root network. |
| 3470 | + SubNetworkDoesNotExist: Attempting to register to a non-existent network. |
| 3471 | + TooManyChildren: Too many children in request. |
| 3472 | + TxRateLimitExceeded: Hotkey hit the rate limit. |
| 3473 | + bittensor_wallet.errors.KeyFileError: Failed to decode keyfile data. |
| 3474 | + bittensor_wallet.errors.PasswordError: Decryption failed or wrong password for decryption provided. |
| 3475 | + """ |
| 3476 | + |
| 3477 | + unlock = unlock_key(wallet, raise_error=raise_error) |
| 3478 | + |
| 3479 | + if not unlock.success: |
| 3480 | + return False, unlock.message |
| 3481 | + |
| 3482 | + call = await self.substrate.compose_call( |
| 3483 | + call_module="SubtensorModule", |
| 3484 | + call_function="set_children", |
| 3485 | + call_params={ |
| 3486 | + "children": [ |
| 3487 | + ( |
| 3488 | + float_to_u64(proportion), |
| 3489 | + child_hotkey, |
| 3490 | + ) |
| 3491 | + for proportion, child_hotkey in children |
| 3492 | + ], |
| 3493 | + "hotkey": hotkey, |
| 3494 | + "netuid": netuid, |
| 3495 | + }, |
| 3496 | + ) |
| 3497 | + |
| 3498 | + return await self.sign_and_send_extrinsic( |
| 3499 | + call, |
| 3500 | + wallet, |
| 3501 | + wait_for_inclusion, |
| 3502 | + wait_for_finalization, |
| 3503 | + raise_error=raise_error, |
| 3504 | + ) |
| 3505 | + |
3384 | 3506 | async def set_delegate_take(
|
3385 | 3507 | self,
|
3386 | 3508 | wallet: "Wallet",
|
|
0 commit comments