Skip to content

Commit 9dc1b99

Browse files
committed
Registration.
1 parent 3abe6d0 commit 9dc1b99

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

bittensor_cli/cli.py

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

@@ -1752,6 +1752,7 @@ def wallet_transfer(
17521752
transfer_all: bool = typer.Option(
17531753
False, "--all", prompt=False, help="Transfer all available balance."
17541754
),
1755+
era: int = Options.era,
17551756
wallet_name: str = Options.wallet_name,
17561757
wallet_path: str = Options.wallet_path,
17571758
wallet_hotkey: str = Options.wallet_hotkey,
@@ -1800,12 +1801,13 @@ def wallet_transfer(
18001801
amount = FloatPrompt.ask("Enter amount (in TAO) to transfer.")
18011802
return self._run_command(
18021803
wallets.transfer(
1803-
wallet,
1804-
subtensor,
1805-
destination_ss58_address,
1806-
amount,
1807-
transfer_all,
1808-
prompt,
1804+
wallet=wallet,
1805+
subtensor=subtensor,
1806+
destination=destination_ss58_address,
1807+
amount=amount,
1808+
transfer_all=transfer_all,
1809+
era=era,
1810+
prompt=prompt,
18091811
)
18101812
)
18111813

@@ -5055,6 +5057,13 @@ def subnets_register(
50555057
wallet_hotkey: str = Options.wallet_hotkey,
50565058
network: Optional[list[str]] = Options.network,
50575059
netuid: int = Options.netuid,
5060+
era: Optional[
5061+
int
5062+
] = typer.Option( # Should not be Options.era bc this needs to be an Optional[int]
5063+
None,
5064+
help="Length (in blocks) for which the transaction should be valid. Note that it is possible that if you "
5065+
"use an era for this transaction that you may pay a different fee to register than the one stated.",
5066+
),
50585067
prompt: bool = Options.prompt,
50595068
quiet: bool = Options.quiet,
50605069
verbose: bool = Options.verbose,
@@ -5083,6 +5092,7 @@ def subnets_register(
50835092
wallet,
50845093
self.initialize_chain(network),
50855094
netuid,
5095+
era,
50865096
prompt,
50875097
)
50885098
)

bittensor_cli/src/bittensor/extrinsics/registration.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ async def burned_register_extrinsic(
676676
old_balance: Balance,
677677
wait_for_inclusion: bool = True,
678678
wait_for_finalization: bool = True,
679+
era: Optional[int] = None,
679680
prompt: bool = False,
680681
) -> bool:
681682
"""Registers the wallet to chain by recycling TAO.
@@ -704,13 +705,32 @@ async def burned_register_extrinsic(
704705
my_uid = await subtensor.query(
705706
"SubtensorModule", "Uids", [netuid, wallet.hotkey.ss58_address]
706707
)
708+
block_hash = await subtensor.substrate.get_chain_head()
707709

708710
print_verbose("Checking if already registered", status)
709711
neuron = await subtensor.neuron_for_uid(
710-
uid=my_uid,
711-
netuid=netuid,
712-
block_hash=subtensor.substrate.last_block_hash,
712+
uid=my_uid, netuid=netuid, block_hash=block_hash
713713
)
714+
if not era:
715+
current_block, tempo, blocks_since_last_step = await asyncio.gather(
716+
subtensor.substrate.get_block_number(block_hash=block_hash),
717+
subtensor.get_hyperparameter(
718+
"Tempo", netuid=netuid, block_hash=block_hash
719+
),
720+
subtensor.query(
721+
"SubtensorModule",
722+
"BlocksSinceLastStep",
723+
[netuid],
724+
block_hash=block_hash,
725+
),
726+
)
727+
validity_period = tempo - blocks_since_last_step
728+
era_ = {
729+
"period": validity_period,
730+
"current": current_block,
731+
}
732+
else:
733+
era_ = {"period": era}
714734

715735
if not neuron.is_null:
716736
console.print(
@@ -734,7 +754,7 @@ async def burned_register_extrinsic(
734754
},
735755
)
736756
success, err_msg = await subtensor.sign_and_send_extrinsic(
737-
call, wallet, wait_for_inclusion, wait_for_finalization
757+
call, wallet, wait_for_inclusion, wait_for_finalization, era=era_
738758
)
739759

740760
if not success:

bittensor_cli/src/bittensor/extrinsics/transfer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async def transfer_extrinsic(
2424
wallet: Wallet,
2525
destination: str,
2626
amount: Balance,
27+
era: int = 3,
2728
transfer_all: bool = False,
2829
wait_for_inclusion: bool = True,
2930
wait_for_finalization: bool = False,
@@ -84,7 +85,7 @@ async def do_transfer() -> tuple[bool, str, str]:
8485
call_params={"dest": destination, "value": amount.rao},
8586
)
8687
extrinsic = await subtensor.substrate.create_signed_extrinsic(
87-
call=call, keypair=wallet.coldkey
88+
call=call, keypair=wallet.coldkey, era={"period": era}
8889
)
8990
response = await subtensor.substrate.submit_extrinsic(
9091
extrinsic,

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@ async def sign_and_send_extrinsic(
10481048
wallet: Wallet,
10491049
wait_for_inclusion: bool = True,
10501050
wait_for_finalization: bool = False,
1051+
era: Optional[dict[str, int]] = None,
10511052
) -> tuple[bool, str]:
10521053
"""
10531054
Helper method to sign and submit an extrinsic call to chain.
@@ -1059,8 +1060,11 @@ async def sign_and_send_extrinsic(
10591060
10601061
:return: (success, error message)
10611062
"""
1063+
call_args = {"call": call, "keypair": wallet.coldkey}
1064+
if era is not None:
1065+
call_args["era"] = era
10621066
extrinsic = await self.substrate.create_signed_extrinsic(
1063-
call=call, keypair=wallet.coldkey
1067+
**call_args
10641068
) # sign with coldkey
10651069
try:
10661070
response = await self.substrate.submit_extrinsic(

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,11 @@ async def pow_register(
14361436

14371437

14381438
async def register(
1439-
wallet: Wallet, subtensor: "SubtensorInterface", netuid: int, prompt: bool
1439+
wallet: Wallet,
1440+
subtensor: "SubtensorInterface",
1441+
netuid: int,
1442+
era: Optional[int],
1443+
prompt: bool,
14401444
):
14411445
"""Register neuron by recycling some TAO."""
14421446

@@ -1534,6 +1538,7 @@ async def register(
15341538
netuid=netuid,
15351539
prompt=False,
15361540
old_balance=balance,
1541+
era=era,
15371542
)
15381543

15391544

bittensor_cli/src/commands/wallets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ async def transfer(
11881188
destination: str,
11891189
amount: float,
11901190
transfer_all: bool,
1191+
era: int,
11911192
prompt: bool,
11921193
):
11931194
"""Transfer token of amount to destination."""
@@ -1197,6 +1198,7 @@ async def transfer(
11971198
destination=destination,
11981199
amount=Balance.from_tao(amount),
11991200
transfer_all=transfer_all,
1201+
era=era,
12001202
prompt=prompt,
12011203
)
12021204

0 commit comments

Comments
 (0)