Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6600,6 +6600,7 @@ async def sign_and_send_extrinsic(
nonce: Optional[int] = None,
*,
period: Optional[int] = DEFAULT_PERIOD,
era_current: Optional[int] = None,
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
Expand All @@ -6619,6 +6620,8 @@ async def sign_and_send_extrinsic(
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.
era_current: The block number to anchor the mortal era to. If not provided, the substrate interface chooses
the anchor.
raise_error: Raises the relevant exception rather than returning `False` if unsuccessful.
wait_for_inclusion: Whether to wait until the extrinsic call is included on the chain
wait_for_finalization: Whether to wait until the extrinsic call is finalized on the chain
Expand Down Expand Up @@ -6657,6 +6660,8 @@ async def sign_and_send_extrinsic(

if period is not None:
extrinsic_data["era"] = {"period": period}
if era_current is not None:
extrinsic_data["era"]["current"] = era_current

extrinsic_response.extrinsic = await self.substrate.create_signed_extrinsic(
**extrinsic_data
Expand Down
4 changes: 3 additions & 1 deletion bittensor/core/extrinsics/asyncex/mev_shield.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ async def submit_encrypted_extrinsic(
inner_signing_keypair = getattr(wallet, sign_with)

effective_period = resolve_mev_shield_period(period)
era = {"period": effective_period}
current_block = await subtensor.substrate.get_block_number()
era = {"period": effective_period, "current": current_block}

current_nonce = await subtensor.substrate.get_account_next_index(
account_address=inner_signing_keypair.ss58_address
Expand All @@ -175,6 +176,7 @@ async def submit_encrypted_extrinsic(
call=extrinsic_call,
nonce=current_nonce,
period=effective_period,
era_current=current_block,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
Expand Down
4 changes: 3 additions & 1 deletion bittensor/core/extrinsics/mev_shield.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def submit_encrypted_extrinsic(
inner_signing_keypair = getattr(wallet, sign_with)

effective_period = resolve_mev_shield_period(period)
era = {"period": effective_period}
current_block = subtensor.substrate.get_block_number()
era = {"period": effective_period, "current": current_block}

current_nonce = subtensor.substrate.get_account_next_index(
account_address=inner_signing_keypair.ss58_address
Expand All @@ -173,6 +174,7 @@ def submit_encrypted_extrinsic(
call=extrinsic_call,
nonce=current_nonce,
period=effective_period,
era_current=current_block,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
Expand Down
5 changes: 5 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5267,6 +5267,7 @@ def sign_and_send_extrinsic(
nonce: Optional[int] = None,
*,
period: Optional[int] = DEFAULT_PERIOD,
era_current: Optional[int] = None,
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
Expand All @@ -5285,6 +5286,8 @@ def sign_and_send_extrinsic(
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.
era_current: The block number to anchor the mortal era to. If not provided, the substrate interface chooses
the anchor.
raise_error: Raises the relevant exception rather than returning `False` if unsuccessful.
wait_for_inclusion: Whether to wait until the extrinsic call is included on the chain
wait_for_finalization: Whether to wait until the extrinsic call is finalized on the chain
Expand Down Expand Up @@ -5324,6 +5327,8 @@ def sign_and_send_extrinsic(

if period is not None:
extrinsic_data["era"] = {"period": period}
if era_current is not None:
extrinsic_data["era"]["current"] = era_current

extrinsic_response.extrinsic = self.substrate.create_signed_extrinsic(
**extrinsic_data
Expand Down
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[mypy]
ignore_missing_imports = True
ignore_errors = True
follow_imports_for_stubs = True

[mypy-numpy.*]
follow_imports = skip

[mypy-numpy]
follow_imports = skip

[mypy-*.axon.*]
ignore_errors = False
Expand Down
72 changes: 64 additions & 8 deletions tests/unit_tests/extrinsics/asyncex/test_mev_shield.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async def test_submit_encrypted_extrinsic_success_with_revealed_execution(
signed_extrinsic_hash = f"0x{signed_extrinsic_hash_hex}"
current_nonce = 5
next_nonce = 6
current_block = 12345
block_hash = "0xblockhash"

mocked_unlock_wallet = mocker.patch.object(
Expand All @@ -144,6 +145,11 @@ async def test_submit_encrypted_extrinsic_success_with_revealed_execution(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = signed_extrinsic_hash_hex
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -221,7 +227,7 @@ async def test_submit_encrypted_extrinsic_success_with_revealed_execution(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -237,6 +243,7 @@ async def test_submit_encrypted_extrinsic_success_with_revealed_execution(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down Expand Up @@ -272,6 +279,7 @@ async def test_submit_encrypted_extrinsic_success_without_revealed_execution(
signed_extrinsic_hash = f"0x{signed_extrinsic_hash_hex}"
current_nonce = 5
next_nonce = 6
current_block = 12345

mocked_unlock_wallet = mocker.patch.object(
ExtrinsicResponse,
Expand All @@ -288,6 +296,11 @@ async def test_submit_encrypted_extrinsic_success_without_revealed_execution(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = signed_extrinsic_hash_hex
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -338,7 +351,7 @@ async def test_submit_encrypted_extrinsic_success_without_revealed_execution(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -354,6 +367,7 @@ async def test_submit_encrypted_extrinsic_success_without_revealed_execution(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down Expand Up @@ -484,6 +498,7 @@ async def test_submit_encrypted_extrinsic_encrypted_submitted_event_not_found(
mev_ciphertext = b"fake_ciphertext"
current_nonce = 5
next_nonce = 6
current_block = 12345

mocked_unlock_wallet = mocker.patch.object(
ExtrinsicResponse,
Expand All @@ -500,6 +515,11 @@ async def test_submit_encrypted_extrinsic_encrypted_submitted_event_not_found(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = "abcdef123456"
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -558,7 +578,7 @@ async def test_submit_encrypted_extrinsic_encrypted_submitted_event_not_found(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -574,6 +594,7 @@ async def test_submit_encrypted_extrinsic_encrypted_submitted_event_not_found(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down Expand Up @@ -604,6 +625,7 @@ async def test_submit_encrypted_extrinsic_failed_to_find_outcome(
signed_extrinsic_hash = f"0x{signed_extrinsic_hash_hex}"
current_nonce = 5
next_nonce = 6
current_block = 12345
block_hash = "0xblockhash"

mocked_unlock_wallet = mocker.patch.object(
Expand All @@ -621,6 +643,11 @@ async def test_submit_encrypted_extrinsic_failed_to_find_outcome(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = signed_extrinsic_hash_hex
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -695,7 +722,7 @@ async def test_submit_encrypted_extrinsic_failed_to_find_outcome(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -711,6 +738,7 @@ async def test_submit_encrypted_extrinsic_failed_to_find_outcome(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down Expand Up @@ -747,6 +775,7 @@ async def test_submit_encrypted_extrinsic_execution_failure(
signed_extrinsic_hash = f"0x{signed_extrinsic_hash_hex}"
current_nonce = 5
next_nonce = 6
current_block = 12345
block_hash = "0xblockhash"
error_message = "Execution failed"
formatted_error = "Formatted error: Execution failed"
Expand All @@ -766,6 +795,11 @@ async def test_submit_encrypted_extrinsic_execution_failure(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = signed_extrinsic_hash_hex
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -847,7 +881,7 @@ async def test_submit_encrypted_extrinsic_execution_failure(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -863,6 +897,7 @@ async def test_submit_encrypted_extrinsic_execution_failure(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down Expand Up @@ -898,6 +933,7 @@ async def test_submit_encrypted_extrinsic_sign_and_send_failure(
mev_ciphertext = b"fake_ciphertext"
current_nonce = 5
next_nonce = 6
current_block = 12345

mocked_unlock_wallet = mocker.patch.object(
ExtrinsicResponse,
Expand All @@ -914,6 +950,11 @@ async def test_submit_encrypted_extrinsic_sign_and_send_failure(
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = "abcdef123456"
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -963,7 +1004,7 @@ async def test_submit_encrypted_extrinsic_sign_and_send_failure(
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -979,6 +1020,7 @@ async def test_submit_encrypted_extrinsic_sign_and_send_failure(
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand All @@ -999,6 +1041,7 @@ async def test_submit_encrypted_extrinsic_with_hotkey(subtensor, fake_wallet, mo
mev_ciphertext = b"fake_ciphertext"
current_nonce = 5
next_nonce = 6
current_block = 12345

mocked_unlock_wallet = mocker.patch.object(
ExtrinsicResponse,
Expand All @@ -1015,6 +1058,11 @@ async def test_submit_encrypted_extrinsic_with_hotkey(subtensor, fake_wallet, mo
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = "abcdef123456"
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -1065,7 +1113,7 @@ async def test_submit_encrypted_extrinsic_with_hotkey(subtensor, fake_wallet, mo
call=call,
keypair=fake_wallet.hotkey,
nonce=next_nonce,
era={"period": 8},
era={"period": 8, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -1081,6 +1129,7 @@ async def test_submit_encrypted_extrinsic_with_hotkey(subtensor, fake_wallet, mo
call=mock_extrinsic_call,
nonce=current_nonce,
period=8,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand All @@ -1101,6 +1150,7 @@ async def test_submit_encrypted_extrinsic_with_period(subtensor, fake_wallet, mo
mev_ciphertext = b"fake_ciphertext"
current_nonce = 5
next_nonce = 6
current_block = 12345
period = 64

mocked_unlock_wallet = mocker.patch.object(
Expand All @@ -1118,6 +1168,11 @@ async def test_submit_encrypted_extrinsic_with_period(subtensor, fake_wallet, mo
"get_account_next_index",
new=mocker.AsyncMock(side_effect=[current_nonce, next_nonce]),
)
mocker.patch.object(
subtensor.substrate,
"get_block_number",
new=mocker.AsyncMock(return_value=current_block),
)
mock_signed_extrinsic = mocker.MagicMock()
mock_signed_extrinsic.extrinsic_hash.hex.return_value = "abcdef123456"
mocked_create_signed_extrinsic = mocker.patch.object(
Expand Down Expand Up @@ -1168,7 +1223,7 @@ async def test_submit_encrypted_extrinsic_with_period(subtensor, fake_wallet, mo
call=call,
keypair=fake_wallet.coldkey,
nonce=next_nonce,
era={"period": MAX_MEV_SHIELD_PERIOD},
era={"period": MAX_MEV_SHIELD_PERIOD, "current": current_block},
)
mocked_get_mev_shielded_ciphertext.assert_called_once_with(
signed_ext=mock_signed_extrinsic,
Expand All @@ -1184,6 +1239,7 @@ async def test_submit_encrypted_extrinsic_with_period(subtensor, fake_wallet, mo
call=mock_extrinsic_call,
nonce=current_nonce,
period=MAX_MEV_SHIELD_PERIOD,
era_current=current_block,
raise_error=False,
wait_for_inclusion=True,
wait_for_finalization=False,
Expand Down
Loading