|
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,
|
@@ -3269,6 +3322,75 @@ async def root_set_weights(
|
3269 | 3322 | wait_for_inclusion=wait_for_inclusion,
|
3270 | 3323 | )
|
3271 | 3324 |
|
| 3325 | + async def set_children( |
| 3326 | + self, |
| 3327 | + wallet: "Wallet", |
| 3328 | + hotkey: str, |
| 3329 | + netuid: int, |
| 3330 | + children: list[tuple[float, str]], |
| 3331 | + wait_for_inclusion: bool = True, |
| 3332 | + wait_for_finalization: bool = True, |
| 3333 | + raise_error: bool = False, |
| 3334 | + ) -> tuple[bool, str]: |
| 3335 | + """ |
| 3336 | + Allows a coldkey to set children keys. |
| 3337 | +
|
| 3338 | + Arguments: |
| 3339 | + wallet (bittensor_wallet.Wallet): bittensor wallet instance. |
| 3340 | + hotkey (str): The ``SS58`` address of the neuron's hotkey. |
| 3341 | + netuid (int): The netuid value. |
| 3342 | + children (list[tuple[float, str]]): A list of children with their proportions. |
| 3343 | + wait_for_inclusion (bool): Waits for the transaction to be included in a block. |
| 3344 | + wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. |
| 3345 | + raise_error: Raises relevant exception rather than returning `False` if unsuccessful. |
| 3346 | +
|
| 3347 | + Returns: |
| 3348 | + tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the |
| 3349 | + operation, and the second element is a message providing additional information. |
| 3350 | +
|
| 3351 | + Raises: |
| 3352 | + DuplicateChild: There are duplicates in the list of children. |
| 3353 | + InvalidChild: Child is the hotkey. |
| 3354 | + NonAssociatedColdKey: The coldkey does not own the hotkey or the child is the same as the hotkey. |
| 3355 | + NotEnoughStakeToSetChildkeys: Parent key doesn't have minimum own stake. |
| 3356 | + ProportionOverflow: The sum of the proportions does exceed uint64. |
| 3357 | + RegistrationNotPermittedOnRootSubnet: Attempting to register a child on the root network. |
| 3358 | + SubNetworkDoesNotExist: Attempting to register to a non-existent network. |
| 3359 | + TooManyChildren: Too many children in request. |
| 3360 | + TxRateLimitExceeded: Hotkey hit the rate limit. |
| 3361 | + bittensor_wallet.errors.KeyFileError: Failed to decode keyfile data. |
| 3362 | + bittensor_wallet.errors.PasswordError: Decryption failed or wrong password for decryption provided. |
| 3363 | + """ |
| 3364 | + |
| 3365 | + unlock = unlock_key(wallet, raise_error=raise_error) |
| 3366 | + |
| 3367 | + if not unlock.success: |
| 3368 | + return False, unlock.message |
| 3369 | + |
| 3370 | + call = await self.substrate.compose_call( |
| 3371 | + call_module="SubtensorModule", |
| 3372 | + call_function="set_children", |
| 3373 | + call_params={ |
| 3374 | + "children": [ |
| 3375 | + ( |
| 3376 | + float_to_u64(proportion), |
| 3377 | + child_hotkey, |
| 3378 | + ) |
| 3379 | + for proportion, child_hotkey in children |
| 3380 | + ], |
| 3381 | + "hotkey": hotkey, |
| 3382 | + "netuid": netuid, |
| 3383 | + }, |
| 3384 | + ) |
| 3385 | + |
| 3386 | + return await self.sign_and_send_extrinsic( |
| 3387 | + call, |
| 3388 | + wallet, |
| 3389 | + wait_for_inclusion, |
| 3390 | + wait_for_finalization, |
| 3391 | + raise_error=raise_error, |
| 3392 | + ) |
| 3393 | + |
3272 | 3394 | async def set_delegate_take(
|
3273 | 3395 | self,
|
3274 | 3396 | wallet: "Wallet",
|
|
0 commit comments