Skip to content

Commit f15b147

Browse files
authored
Merge branch 'staging' into master
2 parents 9b8c613 + da96dad commit f15b147

File tree

12 files changed

+648
-115
lines changed

12 files changed

+648
-115
lines changed

bittensor/core/async_subtensor.py

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
swap_stake_extrinsic,
4545
move_stake_extrinsic,
4646
)
47+
from bittensor.core.extrinsics.asyncex.children import (
48+
root_set_pending_childkey_cooldown_extrinsic,
49+
set_children_extrinsic,
50+
)
4751
from bittensor.core.extrinsics.asyncex.registration import (
4852
burned_register_extrinsic,
4953
register_extrinsic,
@@ -84,13 +88,11 @@
8488
from bittensor.utils import (
8589
Certificate,
8690
decode_hex_identity_dict,
87-
float_to_u64,
8891
format_error_message,
8992
is_valid_ss58_address,
9093
torch,
9194
u16_normalized_float,
9295
u64_normalized_float,
93-
unlock_key,
9496
)
9597
from bittensor.utils.balance import (
9698
Balance,
@@ -3878,6 +3880,41 @@ async def reveal_weights(
38783880

38793881
return success, message
38803882

3883+
async def root_set_pending_childkey_cooldown(
3884+
self,
3885+
wallet: "Wallet",
3886+
cooldown: int,
3887+
wait_for_inclusion: bool = True,
3888+
wait_for_finalization: bool = True,
3889+
period: Optional[int] = None,
3890+
) -> tuple[bool, str]:
3891+
"""Sets the pending childkey cooldown.
3892+
3893+
Arguments:
3894+
wallet: bittensor wallet instance.
3895+
cooldown: the number of blocks to setting pending childkey cooldown.
3896+
wait_for_inclusion (bool): Waits for the transaction to be included in a block. Default is ``False``.
3897+
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. Default is
3898+
``False``.
3899+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's
3900+
submitted. If the transaction is not included in a block within that number of blocks, it will expire
3901+
and be rejected. You can think of it as an expiration date for the transaction.
3902+
3903+
Returns:
3904+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the
3905+
operation, and the second element is a message providing additional information.
3906+
3907+
Note: This operation can only be successfully performed if your wallet has root privileges.
3908+
"""
3909+
return await root_set_pending_childkey_cooldown_extrinsic(
3910+
subtensor=self,
3911+
wallet=wallet,
3912+
cooldown=cooldown,
3913+
wait_for_inclusion=wait_for_inclusion,
3914+
wait_for_finalization=wait_for_finalization,
3915+
period=period,
3916+
)
3917+
38813918
# TODO: remove `block_hash` argument
38823919
async def root_register(
38833920
self,
@@ -3998,33 +4035,14 @@ async def set_children(
39984035
bittensor_wallet.errors.KeyFileError: Failed to decode keyfile data.
39994036
bittensor_wallet.errors.PasswordError: Decryption failed or wrong password for decryption provided.
40004037
"""
4001-
4002-
unlock = unlock_key(wallet, raise_error=raise_error)
4003-
4004-
if not unlock.success:
4005-
return False, unlock.message
4006-
4007-
call = await self.substrate.compose_call(
4008-
call_module="SubtensorModule",
4009-
call_function="set_children",
4010-
call_params={
4011-
"children": [
4012-
(
4013-
float_to_u64(proportion),
4014-
child_hotkey,
4015-
)
4016-
for proportion, child_hotkey in children
4017-
],
4018-
"hotkey": hotkey,
4019-
"netuid": netuid,
4020-
},
4021-
)
4022-
4023-
return await self.sign_and_send_extrinsic(
4024-
call,
4025-
wallet,
4026-
wait_for_inclusion,
4027-
wait_for_finalization,
4038+
return await set_children_extrinsic(
4039+
subtensor=self,
4040+
wallet=wallet,
4041+
hotkey=hotkey,
4042+
netuid=netuid,
4043+
children=children,
4044+
wait_for_inclusion=wait_for_inclusion,
4045+
wait_for_finalization=wait_for_finalization,
40284046
raise_error=raise_error,
40294047
period=period,
40304048
)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
from typing import TYPE_CHECKING, Optional
2+
from bittensor.utils import float_to_u64, unlock_key
3+
4+
if TYPE_CHECKING:
5+
from bittensor_wallet import Wallet
6+
from bittensor.core.async_subtensor import AsyncSubtensor
7+
8+
9+
async def set_children_extrinsic(
10+
subtensor: "AsyncSubtensor",
11+
wallet: "Wallet",
12+
hotkey: str,
13+
netuid: int,
14+
children: list[tuple[float, str]],
15+
wait_for_inclusion: bool = True,
16+
wait_for_finalization: bool = False,
17+
raise_error: bool = False,
18+
period: Optional[int] = None,
19+
):
20+
"""
21+
Allows a coldkey to set children-keys.
22+
23+
Arguments:
24+
subtensor: bittensor subtensor.
25+
wallet: bittensor wallet instance.
26+
hotkey: The ``SS58`` address of the neuron's hotkey.
27+
netuid: The netuid value.
28+
children: A list of children with their proportions.
29+
wait_for_inclusion: Waits for the transaction to be included in a block.
30+
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.
31+
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
32+
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
33+
transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
34+
think of it as an expiration date for the transaction.
35+
36+
Returns:
37+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the operation,
38+
and the second element is a message providing additional information.
39+
40+
Raises:
41+
DuplicateChild: There are duplicates in the list of children.
42+
InvalidChild: Child is the hotkey.
43+
NonAssociatedColdKey: The coldkey does not own the hotkey or the child is the same as the hotkey.
44+
NotEnoughStakeToSetChildkeys: Parent key doesn't have minimum own stake.
45+
ProportionOverflow: The sum of the proportions does exceed uint64.
46+
RegistrationNotPermittedOnRootSubnet: Attempting to register a child on the root network.
47+
SubNetworkDoesNotExist: Attempting to register to a non-existent network.
48+
TooManyChildren: Too many children in request.
49+
TxRateLimitExceeded: Hotkey hit the rate limit.
50+
bittensor_wallet.errors.KeyFileError: Failed to decode keyfile data.
51+
bittensor_wallet.errors.PasswordError: Decryption failed or wrong password for decryption provided.
52+
"""
53+
unlock = unlock_key(wallet, raise_error=raise_error)
54+
55+
if not unlock.success:
56+
return False, unlock.message
57+
58+
async with subtensor.substrate as substrate:
59+
call = await substrate.compose_call(
60+
call_module="SubtensorModule",
61+
call_function="set_children",
62+
call_params={
63+
"children": [
64+
(
65+
float_to_u64(proportion),
66+
child_hotkey,
67+
)
68+
for proportion, child_hotkey in children
69+
],
70+
"hotkey": hotkey,
71+
"netuid": netuid,
72+
},
73+
)
74+
75+
success, message = await subtensor.sign_and_send_extrinsic(
76+
call=call,
77+
wallet=wallet,
78+
wait_for_inclusion=wait_for_inclusion,
79+
wait_for_finalization=wait_for_finalization,
80+
raise_error=raise_error,
81+
period=period,
82+
)
83+
84+
if not wait_for_finalization and not wait_for_inclusion:
85+
return True, message
86+
87+
if success:
88+
return True, "Success with `set_children_extrinsic` response."
89+
90+
return True, message
91+
92+
93+
async def root_set_pending_childkey_cooldown_extrinsic(
94+
subtensor: "AsyncSubtensor",
95+
wallet: "Wallet",
96+
cooldown: int,
97+
wait_for_inclusion: bool = True,
98+
wait_for_finalization: bool = False,
99+
period: Optional[int] = None,
100+
) -> tuple[bool, str]:
101+
"""
102+
Allows a coldkey to set children-keys.
103+
"""
104+
unlock = unlock_key(wallet)
105+
106+
if not unlock.success:
107+
return False, unlock.message
108+
109+
async with subtensor.substrate as substrate:
110+
call = await substrate.compose_call(
111+
call_module="SubtensorModule",
112+
call_function="set_pending_childkey_cooldown",
113+
call_params={"cooldown": cooldown},
114+
)
115+
116+
sudo_call = await substrate.compose_call(
117+
call_module="Sudo",
118+
call_function="sudo",
119+
call_params={"call": call},
120+
)
121+
122+
success, message = await subtensor.sign_and_send_extrinsic(
123+
call=sudo_call,
124+
wallet=wallet,
125+
wait_for_inclusion=wait_for_inclusion,
126+
wait_for_finalization=wait_for_finalization,
127+
period=period,
128+
)
129+
130+
if not wait_for_finalization and not wait_for_inclusion:
131+
return True, message
132+
133+
if success:
134+
return (
135+
True,
136+
"Success with `root_set_pending_childkey_cooldown_extrinsic` response.",
137+
)
138+
139+
return True, message
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
from typing import TYPE_CHECKING, Optional
2+
from bittensor.utils import float_to_u64, unlock_key
3+
4+
if TYPE_CHECKING:
5+
from bittensor_wallet import Wallet
6+
from bittensor.core.subtensor import Subtensor
7+
8+
9+
def set_children_extrinsic(
10+
subtensor: "Subtensor",
11+
wallet: "Wallet",
12+
hotkey: str,
13+
netuid: int,
14+
children: list[tuple[float, str]],
15+
wait_for_inclusion: bool = True,
16+
wait_for_finalization: bool = False,
17+
raise_error: bool = False,
18+
period: Optional[int] = None,
19+
):
20+
"""
21+
Allows a coldkey to set children-keys.
22+
23+
Arguments:
24+
subtensor: bittensor subtensor.
25+
wallet: bittensor wallet instance.
26+
hotkey: The ``SS58`` address of the neuron's hotkey.
27+
netuid: The netuid value.
28+
children: A list of children with their proportions.
29+
wait_for_inclusion: Waits for the transaction to be included in a block.
30+
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.
31+
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
32+
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
33+
transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
34+
think of it as an expiration date for the transaction.
35+
36+
Returns:
37+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure of the operation,
38+
and the second element is a message providing additional information.
39+
40+
Raises:
41+
DuplicateChild: There are duplicates in the list of children.
42+
InvalidChild: Child is the hotkey.
43+
NonAssociatedColdKey: The coldkey does not own the hotkey or the child is the same as the hotkey.
44+
NotEnoughStakeToSetChildkeys: Parent key doesn't have minimum own stake.
45+
ProportionOverflow: The sum of the proportions does exceed uint64.
46+
RegistrationNotPermittedOnRootSubnet: Attempting to register a child on the root network.
47+
SubNetworkDoesNotExist: Attempting to register to a non-existent network.
48+
TooManyChildren: Too many children in request.
49+
TxRateLimitExceeded: Hotkey hit the rate limit.
50+
bittensor_wallet.errors.KeyFileError: Failed to decode keyfile data.
51+
bittensor_wallet.errors.PasswordError: Decryption failed or wrong password for decryption provided.
52+
"""
53+
unlock = unlock_key(wallet, raise_error=raise_error)
54+
55+
if not unlock.success:
56+
return False, unlock.message
57+
58+
call = subtensor.substrate.compose_call(
59+
call_module="SubtensorModule",
60+
call_function="set_children",
61+
call_params={
62+
"children": [
63+
(
64+
float_to_u64(proportion),
65+
child_hotkey,
66+
)
67+
for proportion, child_hotkey in children
68+
],
69+
"hotkey": hotkey,
70+
"netuid": netuid,
71+
},
72+
)
73+
74+
success, message = subtensor.sign_and_send_extrinsic(
75+
call=call,
76+
wallet=wallet,
77+
wait_for_inclusion=wait_for_inclusion,
78+
wait_for_finalization=wait_for_finalization,
79+
raise_error=raise_error,
80+
period=period,
81+
)
82+
83+
if not wait_for_finalization and not wait_for_inclusion:
84+
return True, message
85+
86+
if success:
87+
return True, "Success with `set_children_extrinsic` response."
88+
89+
return True, message
90+
91+
92+
def root_set_pending_childkey_cooldown_extrinsic(
93+
subtensor: "Subtensor",
94+
wallet: "Wallet",
95+
cooldown: int,
96+
wait_for_inclusion: bool = True,
97+
wait_for_finalization: bool = False,
98+
period: Optional[int] = None,
99+
) -> tuple[bool, str]:
100+
"""
101+
Allows a coldkey to set children-keys.
102+
"""
103+
unlock = unlock_key(wallet)
104+
105+
if not unlock.success:
106+
return False, unlock.message
107+
108+
call = subtensor.substrate.compose_call(
109+
call_module="SubtensorModule",
110+
call_function="set_pending_childkey_cooldown",
111+
call_params={"cooldown": cooldown},
112+
)
113+
114+
sudo_call = subtensor.substrate.compose_call(
115+
call_module="Sudo",
116+
call_function="sudo",
117+
call_params={"call": call},
118+
)
119+
120+
success, message = subtensor.sign_and_send_extrinsic(
121+
call=sudo_call,
122+
wallet=wallet,
123+
wait_for_inclusion=wait_for_inclusion,
124+
wait_for_finalization=wait_for_finalization,
125+
period=period,
126+
)
127+
128+
if not wait_for_finalization and not wait_for_inclusion:
129+
return True, message
130+
131+
if success:
132+
return (
133+
True,
134+
"Success with `root_set_pending_childkey_cooldown_extrinsic` response.",
135+
)
136+
137+
return True, message

0 commit comments

Comments
 (0)