11from typing import TYPE_CHECKING , Optional
22
3+ from bittensor .core .extrinsics .asyncex .mev_shield import submit_encrypted_extrinsic
34from bittensor .core .extrinsics .pallets import SubtensorModule , Sudo
5+ from bittensor .core .settings import DEFAULT_MEV_PROTECTION
46from bittensor .core .types import ExtrinsicResponse
57from bittensor .utils import float_to_u64
68
@@ -15,10 +17,13 @@ async def set_children_extrinsic(
1517 hotkey_ss58 : str ,
1618 netuid : int ,
1719 children : list [tuple [float , str ]],
20+ * ,
21+ mev_protection : bool = DEFAULT_MEV_PROTECTION ,
1822 period : Optional [int ] = None ,
1923 raise_error : bool = False ,
2024 wait_for_inclusion : bool = True ,
2125 wait_for_finalization : bool = True ,
26+ wait_for_revealed_execution : bool = True ,
2227) -> ExtrinsicResponse :
2328 """
2429 Allows a coldkey to set children-keys.
@@ -29,6 +34,9 @@ async def set_children_extrinsic(
2934 hotkey_ss58: The ``SS58`` address of the neuron's hotkey.
3035 netuid: The netuid value.
3136 children: A list of children with their proportions.
37+ mev_protection: If True, encrypts and submits the transaction through the MEV Shield pallet to protect
38+ against front-running and MEV attacks. The transaction remains encrypted in the mempool until validators
39+ decrypt and execute it. If False, submits the transaction directly without encryption.
3240 period: The number of blocks during which the transaction will remain valid after it's submitted. If the
3341 transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
3442 think of it as an expiration date for the transaction.
@@ -67,14 +75,26 @@ async def set_children_extrinsic(
6775 ],
6876 )
6977
70- response = await subtensor .sign_and_send_extrinsic (
71- call = call ,
72- wallet = wallet ,
73- period = period ,
74- raise_error = raise_error ,
75- wait_for_inclusion = wait_for_inclusion ,
76- wait_for_finalization = wait_for_finalization ,
77- )
78+ if mev_protection :
79+ response = await submit_encrypted_extrinsic (
80+ subtensor = subtensor ,
81+ wallet = wallet ,
82+ call = call ,
83+ period = period ,
84+ raise_error = raise_error ,
85+ wait_for_inclusion = wait_for_inclusion ,
86+ wait_for_finalization = wait_for_finalization ,
87+ wait_for_revealed_execution = wait_for_revealed_execution ,
88+ )
89+ else :
90+ response = await subtensor .sign_and_send_extrinsic (
91+ call = call ,
92+ wallet = wallet ,
93+ period = period ,
94+ raise_error = raise_error ,
95+ wait_for_inclusion = wait_for_inclusion ,
96+ wait_for_finalization = wait_for_finalization ,
97+ )
7898 return response
7999
80100 except Exception as error :
@@ -85,10 +105,13 @@ async def root_set_pending_childkey_cooldown_extrinsic(
85105 subtensor : "AsyncSubtensor" ,
86106 wallet : "Wallet" ,
87107 cooldown : int ,
108+ * ,
109+ mev_protection : bool = DEFAULT_MEV_PROTECTION ,
88110 period : Optional [int ] = None ,
89111 raise_error : bool = False ,
90112 wait_for_inclusion : bool = True ,
91113 wait_for_finalization : bool = True ,
114+ wait_for_revealed_execution : bool = True ,
92115) -> ExtrinsicResponse :
93116 """
94117 Allows a root coldkey to set children-keys.
@@ -97,6 +120,9 @@ async def root_set_pending_childkey_cooldown_extrinsic(
97120 subtensor: The Subtensor client instance used for blockchain interaction.
98121 wallet: The wallet used to sign the extrinsic (must be unlocked).
99122 cooldown: The cooldown period in blocks.
123+ mev_protection: If True, encrypts and submits the transaction through the MEV Shield pallet to protect
124+ against front-running and MEV attacks. The transaction remains encrypted in the mempool until validators
125+ decrypt and execute it. If False, submits the transaction directly without encryption.
100126 period: The number of blocks during which the transaction will remain valid after it's submitted. If the
101127 transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
102128 think of it as an expiration date for the transaction.
@@ -119,14 +145,26 @@ async def root_set_pending_childkey_cooldown_extrinsic(
119145
120146 sudo_call = await Sudo (subtensor ).sudo (call = call )
121147
122- response = await subtensor .sign_and_send_extrinsic (
123- call = sudo_call ,
124- wallet = wallet ,
125- period = period ,
126- raise_error = raise_error ,
127- wait_for_inclusion = wait_for_inclusion ,
128- wait_for_finalization = wait_for_finalization ,
129- )
148+ if mev_protection :
149+ response = await submit_encrypted_extrinsic (
150+ subtensor = subtensor ,
151+ wallet = wallet ,
152+ call = sudo_call ,
153+ period = period ,
154+ raise_error = raise_error ,
155+ wait_for_inclusion = wait_for_inclusion ,
156+ wait_for_finalization = wait_for_finalization ,
157+ wait_for_revealed_execution = wait_for_revealed_execution ,
158+ )
159+ else :
160+ response = await subtensor .sign_and_send_extrinsic (
161+ call = sudo_call ,
162+ wallet = wallet ,
163+ period = period ,
164+ raise_error = raise_error ,
165+ wait_for_inclusion = wait_for_inclusion ,
166+ wait_for_finalization = wait_for_finalization ,
167+ )
130168 return response
131169
132170 except Exception as error :
0 commit comments