Skip to content

Commit 3abe6d0

Browse files
committed
Allows user to set era period in all stake transactions. Still need to add tests.
1 parent f33b6b8 commit 3abe6d0

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

bittensor_cli/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ class Options:
279279
"--dashboard.path",
280280
help="Path to save the dashboard HTML file. For example: `~/.bittensor/dashboard`.",
281281
)
282+
era = typer.Option(
283+
3, help="Length (in blocks) for which the transaction should be valid."
284+
)
282285

283286

284287
def list_prompt(init_var: list, list_type: type, help_text: str) -> list:
@@ -3112,6 +3115,7 @@ def stake_add(
31123115
rate_tolerance: Optional[float] = Options.rate_tolerance,
31133116
safe_staking: Optional[bool] = Options.safe_staking,
31143117
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
3118+
era: int = Options.era,
31153119
prompt: bool = Options.prompt,
31163120
quiet: bool = Options.quiet,
31173121
verbose: bool = Options.verbose,
@@ -3305,6 +3309,7 @@ def stake_add(
33053309
safe_staking,
33063310
rate_tolerance,
33073311
allow_partial_stake,
3312+
era,
33083313
)
33093314
)
33103315

@@ -3356,6 +3361,7 @@ def stake_remove(
33563361
rate_tolerance: Optional[float] = Options.rate_tolerance,
33573362
safe_staking: Optional[bool] = Options.safe_staking,
33583363
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
3364+
era: int = Options.era,
33593365
prompt: bool = Options.prompt,
33603366
interactive: bool = typer.Option(
33613367
False,
@@ -3545,6 +3551,7 @@ def stake_remove(
35453551
include_hotkeys=include_hotkeys,
35463552
exclude_hotkeys=exclude_hotkeys,
35473553
prompt=prompt,
3554+
era=era,
35483555
)
35493556
)
35503557
elif (
@@ -3599,6 +3606,7 @@ def stake_remove(
35993606
safe_staking=safe_staking,
36003607
rate_tolerance=rate_tolerance,
36013608
allow_partial_stake=allow_partial_stake,
3609+
era=era,
36023610
)
36033611
)
36043612

@@ -3626,6 +3634,7 @@ def stake_move(
36263634
stake_all: bool = typer.Option(
36273635
False, "--stake-all", "--all", help="Stake all", prompt=False
36283636
),
3637+
era: int = Options.era,
36293638
prompt: bool = Options.prompt,
36303639
quiet: bool = Options.quiet,
36313640
verbose: bool = Options.verbose,
@@ -3753,6 +3762,7 @@ def stake_move(
37533762
destination_hotkey=destination_hotkey,
37543763
amount=amount,
37553764
stake_all=stake_all,
3765+
era=era,
37563766
interactive_selection=interactive_selection,
37573767
prompt=prompt,
37583768
)
@@ -3790,6 +3800,7 @@ def stake_transfer(
37903800
stake_all: bool = typer.Option(
37913801
False, "--stake-all", "--all", help="Stake all", prompt=False
37923802
),
3803+
era: int = Options.era,
37933804
prompt: bool = Options.prompt,
37943805
quiet: bool = Options.quiet,
37953806
verbose: bool = Options.verbose,
@@ -3910,6 +3921,7 @@ def stake_transfer(
39103921
dest_netuid=dest_netuid,
39113922
dest_coldkey_ss58=dest_ss58,
39123923
amount=amount,
3924+
era=era,
39133925
interactive_selection=interactive_selection,
39143926
stake_all=stake_all,
39153927
prompt=prompt,
@@ -3948,6 +3960,7 @@ def stake_swap(
39483960
"--all",
39493961
help="Swap all available stake",
39503962
),
3963+
era: int = Options.era,
39513964
prompt: bool = Options.prompt,
39523965
wait_for_inclusion: bool = Options.wait_for_inclusion,
39533966
wait_for_finalization: bool = Options.wait_for_finalization,
@@ -4010,6 +4023,7 @@ def stake_swap(
40104023
destination_netuid=dest_netuid,
40114024
amount=amount,
40124025
swap_all=swap_all,
4026+
era=era,
40134027
interactive_selection=interactive_selection,
40144028
prompt=prompt,
40154029
wait_for_inclusion=wait_for_inclusion,

bittensor_cli/src/commands/stake/add.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async def stake_add(
3838
safe_staking: bool,
3939
rate_tolerance: float,
4040
allow_partial_stake: bool,
41+
era: int,
4142
):
4243
"""
4344
Args:
@@ -53,6 +54,7 @@ async def stake_add(
5354
safe_staking: whether to use safe staking
5455
rate_tolerance: rate tolerance percentage for stake operations
5556
allow_partial_stake: whether to allow partial stake
57+
era: Blocks for which the transaction should be valid.
5658
5759
Returns:
5860
bool: True if stake operation is successful, False otherwise
@@ -86,7 +88,7 @@ async def safe_stake_extrinsic(
8688
},
8789
)
8890
extrinsic = await subtensor.substrate.create_signed_extrinsic(
89-
call=call, keypair=wallet.coldkey, nonce=next_nonce
91+
call=call, keypair=wallet.coldkey, nonce=next_nonce, era={"period": era}
9092
)
9193
try:
9294
response = await subtensor.substrate.submit_extrinsic(
@@ -105,7 +107,6 @@ async def safe_stake_extrinsic(
105107
err_out(f"\n{failure_prelude} with error: {format_error_message(e)}")
106108
return
107109
else:
108-
await response.process_events()
109110
if not await response.is_success:
110111
err_out(
111112
f"\n{failure_prelude} with error: {format_error_message(await response.error_message)}"
@@ -166,7 +167,7 @@ async def stake_extrinsic(
166167
},
167168
)
168169
extrinsic = await subtensor.substrate.create_signed_extrinsic(
169-
call=call, keypair=wallet.coldkey, nonce=next_nonce
170+
call=call, keypair=wallet.coldkey, nonce=next_nonce, era={"period": era}
170171
)
171172
try:
172173
response = await subtensor.substrate.submit_extrinsic(

bittensor_cli/src/commands/stake/move.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ async def move_stake(
444444
destination_hotkey: str,
445445
amount: float,
446446
stake_all: bool,
447+
era: int,
447448
interactive_selection: bool = False,
448449
prompt: bool = True,
449450
):
@@ -563,7 +564,7 @@ async def move_stake(
563564
},
564565
)
565566
extrinsic = await subtensor.substrate.create_signed_extrinsic(
566-
call=call, keypair=wallet.coldkey
567+
call=call, keypair=wallet.coldkey, era={"period": era}
567568
)
568569
response = await subtensor.substrate.submit_extrinsic(
569570
extrinsic, wait_for_inclusion=True, wait_for_finalization=False
@@ -622,6 +623,7 @@ async def transfer_stake(
622623
origin_netuid: int,
623624
dest_netuid: int,
624625
dest_coldkey_ss58: str,
626+
era: int,
625627
interactive_selection: bool = False,
626628
stake_all: bool = False,
627629
prompt: bool = True,
@@ -747,7 +749,7 @@ async def transfer_stake(
747749
)
748750

749751
extrinsic = await subtensor.substrate.create_signed_extrinsic(
750-
call=call, keypair=wallet.coldkey
752+
call=call, keypair=wallet.coldkey, era={"period": era}
751753
)
752754

753755
response = await subtensor.substrate.submit_extrinsic(
@@ -798,6 +800,7 @@ async def swap_stake(
798800
destination_netuid: int,
799801
amount: float,
800802
swap_all: bool = False,
803+
era: int = 3,
801804
interactive_selection: bool = False,
802805
prompt: bool = True,
803806
wait_for_inclusion: bool = True,
@@ -917,7 +920,7 @@ async def swap_stake(
917920
)
918921

919922
extrinsic = await subtensor.substrate.create_signed_extrinsic(
920-
call=call, keypair=wallet.coldkey
923+
call=call, keypair=wallet.coldkey, era={"period": era}
921924
)
922925

923926
response = await subtensor.substrate.submit_extrinsic(

bittensor_cli/src/commands/stake/remove.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async def unstake(
4141
safe_staking: bool,
4242
rate_tolerance: float,
4343
allow_partial_stake: bool,
44+
era: int,
4445
):
4546
"""Unstake from hotkey(s)."""
4647
with console.status(
@@ -302,6 +303,7 @@ async def unstake(
302303
current_stake=op["current_stake_balance"],
303304
hotkey_ss58=op["hotkey_ss58"],
304305
status=status,
306+
era=era,
305307
)
306308
else:
307309
await _safe_unstake_extrinsic(
@@ -313,6 +315,7 @@ async def unstake(
313315
price_limit=op["price_with_tolerance"],
314316
allow_partial_stake=allow_partial_stake,
315317
status=status,
318+
era=era,
316319
)
317320
else:
318321
for op in unstake_operations:
@@ -324,6 +327,7 @@ async def unstake(
324327
current_stake=op["current_stake_balance"],
325328
hotkey_ss58=op["hotkey_ss58"],
326329
status=status,
330+
era=era,
327331
)
328332
console.print(
329333
f"[{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]Unstaking operations completed."
@@ -338,6 +342,7 @@ async def unstake_all(
338342
all_hotkeys: bool = False,
339343
include_hotkeys: Optional[list[str]] = None,
340344
exclude_hotkeys: Optional[list[str]] = None,
345+
era: int = 3,
341346
prompt: bool = True,
342347
) -> bool:
343348
"""Unstakes all stakes from all hotkeys in all subnets."""
@@ -512,6 +517,7 @@ async def unstake_all(
512517
hotkey_name=hotkey_names.get(hotkey_ss58, hotkey_ss58),
513518
unstake_all_alpha=unstake_all_alpha,
514519
status=status,
520+
era=era,
515521
)
516522

517523

@@ -524,6 +530,7 @@ async def _unstake_extrinsic(
524530
current_stake: Balance,
525531
hotkey_ss58: str,
526532
status=None,
533+
era: int = 3,
527534
) -> None:
528535
"""Execute a standard unstake extrinsic.
529536
@@ -535,6 +542,7 @@ async def _unstake_extrinsic(
535542
wallet: Wallet instance
536543
subtensor: Subtensor interface
537544
status: Optional status for console updates
545+
era: blocks for which the transaction is valid
538546
"""
539547
err_out = partial(print_error, status=status)
540548
failure_prelude = (
@@ -557,7 +565,7 @@ async def _unstake_extrinsic(
557565
},
558566
)
559567
extrinsic = await subtensor.substrate.create_signed_extrinsic(
560-
call=call, keypair=wallet.coldkey
568+
call=call, keypair=wallet.coldkey, era={"period": era}
561569
)
562570

563571
try:
@@ -607,6 +615,7 @@ async def _safe_unstake_extrinsic(
607615
price_limit: Balance,
608616
allow_partial_stake: bool,
609617
status=None,
618+
era: int = 3,
610619
) -> None:
611620
"""Execute a safe unstake extrinsic with price limit.
612621
@@ -655,7 +664,7 @@ async def _safe_unstake_extrinsic(
655664
)
656665

657666
extrinsic = await subtensor.substrate.create_signed_extrinsic(
658-
call=call, keypair=wallet.coldkey, nonce=next_nonce
667+
call=call, keypair=wallet.coldkey, nonce=next_nonce, era={"period": era}
659668
)
660669

661670
try:
@@ -720,6 +729,7 @@ async def _unstake_all_extrinsic(
720729
hotkey_name: str,
721730
unstake_all_alpha: bool,
722731
status=None,
732+
era: int = 3,
723733
) -> None:
724734
"""Execute an unstake all extrinsic.
725735
@@ -770,8 +780,7 @@ async def _unstake_all_extrinsic(
770780
try:
771781
response = await subtensor.substrate.submit_extrinsic(
772782
extrinsic=await subtensor.substrate.create_signed_extrinsic(
773-
call=call,
774-
keypair=wallet.coldkey,
783+
call=call, keypair=wallet.coldkey, era={"period": era}
775784
),
776785
wait_for_inclusion=True,
777786
wait_for_finalization=False,

tests/e2e_tests/test_senate.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ def test_senate(local_chain, wallet_setup):
222222
assert proposals_after_nay_output[9].split()[4] == "1"
223223

224224
# Assert Alice has voted Nay
225-
assert proposals_after_nay_output[10].split()[0].strip(
226-
":"
227-
) == wallet_alice.hotkey.ss58_address
225+
assert (
226+
proposals_after_nay_output[10].split()[0].strip(":")
227+
== wallet_alice.hotkey.ss58_address
228+
)
228229

229230
# Assert vote casted as Nay
230231
assert proposals_after_nay_output[10].split()[1] == "Nay"

0 commit comments

Comments
 (0)