Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d0b3862
add `MevShield` pallet function call builder class
basfroman Nov 21, 2025
4fad186
update SubtensorApi
basfroman Nov 21, 2025
89245b0
update pallet functions call builder
basfroman Nov 21, 2025
91c70f1
add e2e tests
basfroman Nov 22, 2025
e42f03d
updated pallet
basfroman Nov 26, 2025
bb5ba56
workable draft
basfroman Nov 26, 2025
770a99c
apply signer_keypair logic as third keypair
basfroman Nov 26, 2025
aa0d5a3
probably tests are broken
basfroman Nov 26, 2025
51ca4e1
ruff
basfroman Nov 26, 2025
38d198e
Merge branch 'SDKv10' into feat/roman/MevShield
basfroman Dec 1, 2025
2a8709f
bump ASI version
basfroman Dec 2, 2025
f700b4a
add pallets to easy imports
basfroman Dec 2, 2025
7d221ea
add get_event_data, get_mev_commitment_and_ciphertext to utils
basfroman Dec 2, 2025
f0ac977
update SubtensorApi
basfroman Dec 2, 2025
0bda5c1
add sync `submit_encrypted_extrinsic`
basfroman Dec 2, 2025
a128f29
add sync e2e test
basfroman Dec 2, 2025
611ebbb
ruff
basfroman Dec 2, 2025
ea9ba62
update SubtensorApi
basfroman Dec 2, 2025
7561b70
add async extrinsic
basfroman Dec 2, 2025
015eb62
add async subtensor methods
basfroman Dec 2, 2025
036e044
fix subtensor_api test
basfroman Dec 2, 2025
11b0344
add async e2e test
basfroman Dec 2, 2025
7dceefb
fixes
basfroman Dec 2, 2025
7a345c4
add `with_mev_protection` flag to `add_stake`
basfroman Dec 2, 2025
85161e2
fix conftest
basfroman Dec 2, 2025
9d34fac
non fast blocks e2e tests
basfroman Dec 2, 2025
a4e1adf
ruff
basfroman Dec 2, 2025
192dfc3
unit test fix
basfroman Dec 2, 2025
f954950
unit test fix (one more)
basfroman Dec 2, 2025
f0c0eaa
update `ExtrinsicResponse`
basfroman Dec 2, 2025
849317c
improve `get_event_attributes_by_event_name`
basfroman Dec 2, 2025
14ff6fc
update extrinsics
basfroman Dec 2, 2025
8310566
improve e2e tests
basfroman Dec 2, 2025
752f500
rename `with_mev_protection` to `mev_protection`
basfroman Dec 2, 2025
9472dcb
rename `with_mev_protection` to `mev_protection` + docstrings
basfroman Dec 2, 2025
f46cfd9
fix unit tests
basfroman Dec 2, 2025
c654916
weird code
basfroman Dec 2, 2025
3647866
update `submit_encrypted_extrinsic`
basfroman Dec 3, 2025
12244c5
add `mev_protection` to all sync extrinsics
basfroman Dec 3, 2025
c14ad40
update unit tests
basfroman Dec 3, 2025
cf2d394
add `mev_protection` with default value to subtensor methods
basfroman Dec 3, 2025
4922bb6
update async `add_stake` and `mev_submit_encrypted` methods
basfroman Dec 3, 2025
27cf947
Merge branch 'SDKv10' into feat/roman/MevShield
basfroman Dec 3, 2025
7879133
add `mev_protection` to all async extrinsics
basfroman Dec 3, 2025
1bc7ce1
update all async subtensor methods
basfroman Dec 3, 2025
1b84ee3
fix unit tests
basfroman Dec 3, 2025
2488943
add new sync unit tests
basfroman Dec 3, 2025
a068113
add new async unit tests
basfroman Dec 3, 2025
5ac4d3e
improve `test_mev_shield_happy_path` logic
basfroman Dec 3, 2025
54cd478
add check in `submit_encrypted_extrinsic`
basfroman Dec 3, 2025
08cf924
non-fast-block e2e test
basfroman Dec 3, 2025
6d1a945
update ExtrinsicResponse.__str__
basfroman Dec 3, 2025
2877d2d
update ExtrinsicResponse.__str__
basfroman Dec 3, 2025
4411688
bumping `bittensor-drand` version
basfroman Dec 3, 2025
381a32b
add `post_process_mev_response`
basfroman Dec 3, 2025
9c2e344
improve `submit_encrypted_extrinsic`, DRY, etc
basfroman Dec 3, 2025
f5f300e
ruff
basfroman Dec 3, 2025
e93ffe7
add `BT_MEV_PROTECTION` local env variable
basfroman Dec 3, 2025
799343c
add `wait_for_revealed_execution` param to all extrinsics + unit tests
basfroman Dec 4, 2025
10e88a6
improvement for utils
basfroman Dec 4, 2025
09d891b
fix `find_revealed_extrinsic`
basfroman Dec 4, 2025
c6a9b2e
typo
basfroman Dec 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
741 changes: 737 additions & 4 deletions bittensor/core/async_subtensor.py

Large diffs are not rendered by default.

70 changes: 54 additions & 16 deletions bittensor/core/extrinsics/asyncex/children.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import TYPE_CHECKING, Optional

from bittensor.core.extrinsics.asyncex.mev_shield import submit_encrypted_extrinsic
from bittensor.core.extrinsics.pallets import SubtensorModule, Sudo
from bittensor.core.settings import DEFAULT_MEV_PROTECTION
from bittensor.core.types import ExtrinsicResponse
from bittensor.utils import float_to_u64

Expand All @@ -15,10 +17,13 @@ async def set_children_extrinsic(
hotkey_ss58: str,
netuid: int,
children: list[tuple[float, str]],
*,
mev_protection: bool = DEFAULT_MEV_PROTECTION,
period: Optional[int] = None,
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
wait_for_revealed_execution: bool = True,
) -> ExtrinsicResponse:
"""
Allows a coldkey to set children-keys.
Expand All @@ -29,6 +34,9 @@ async def set_children_extrinsic(
hotkey_ss58: The ``SS58`` address of the neuron's hotkey.
netuid: The netuid value.
children: A list of children with their proportions.
mev_protection: If True, encrypts and submits the transaction through the MEV Shield pallet to protect
against front-running and MEV attacks. The transaction remains encrypted in the mempool until validators
decrypt and execute it. If False, submits the transaction directly without encryption.
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
think of it as an expiration date for the transaction.
Expand Down Expand Up @@ -67,14 +75,26 @@ async def set_children_extrinsic(
],
)

response = await subtensor.sign_and_send_extrinsic(
call=call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
if mev_protection:
response = await submit_encrypted_extrinsic(
subtensor=subtensor,
wallet=wallet,
call=call,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
wait_for_revealed_execution=wait_for_revealed_execution,
)
else:
response = await subtensor.sign_and_send_extrinsic(
call=call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
return response

except Exception as error:
Expand All @@ -85,10 +105,13 @@ async def root_set_pending_childkey_cooldown_extrinsic(
subtensor: "AsyncSubtensor",
wallet: "Wallet",
cooldown: int,
*,
mev_protection: bool = DEFAULT_MEV_PROTECTION,
period: Optional[int] = None,
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
wait_for_revealed_execution: bool = True,
) -> ExtrinsicResponse:
"""
Allows a root coldkey to set children-keys.
Expand All @@ -97,6 +120,9 @@ async def root_set_pending_childkey_cooldown_extrinsic(
subtensor: The Subtensor client instance used for blockchain interaction.
wallet: The wallet used to sign the extrinsic (must be unlocked).
cooldown: The cooldown period in blocks.
mev_protection: If True, encrypts and submits the transaction through the MEV Shield pallet to protect
against front-running and MEV attacks. The transaction remains encrypted in the mempool until validators
decrypt and execute it. If False, submits the transaction directly without encryption.
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
transaction is not included in a block within that number of blocks, it will expire and be rejected. You can
think of it as an expiration date for the transaction.
Expand All @@ -119,14 +145,26 @@ async def root_set_pending_childkey_cooldown_extrinsic(

sudo_call = await Sudo(subtensor).sudo(call=call)

response = await subtensor.sign_and_send_extrinsic(
call=sudo_call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
if mev_protection:
response = await submit_encrypted_extrinsic(
subtensor=subtensor,
wallet=wallet,
call=sudo_call,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
wait_for_revealed_execution=wait_for_revealed_execution,
)
else:
response = await subtensor.sign_and_send_extrinsic(
call=sudo_call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
return response

except Exception as error:
Expand Down
Loading
Loading