Skip to content

Commit faa5049

Browse files
authored
Merge branch 'staging' into fix/zyzniewski/e2e_python-version
2 parents caee76f + 4da9592 commit faa5049

26 files changed

+1775
-642
lines changed

bittensor_cli/cli.py

Lines changed: 278 additions & 124 deletions
Large diffs are not rendered by default.

bittensor_cli/src/__init__.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -746,23 +746,26 @@ def __init__(self):
746746
self.SU = self.SUDO
747747

748748
class General(Gettable):
749-
HEADER = "#4196D6" # Light Blue
750-
LINKS = "#8CB9E9" # Sky Blue
751-
HINT = "#A2E5B8" # Mint Green
752-
COLDKEY = "#9EF5E4" # Aqua
753-
HOTKEY = "#ECC39D" # Light Orange/Peach
754-
SUBHEADING_MAIN = "#7ECFEC" # Light Cyan
755-
SUBHEADING = "#AFEFFF" # Pale Blue
756-
SUBHEADING_EXTRA_1 = "#96A3C5" # Grayish Blue
757-
SUBHEADING_EXTRA_2 = "#6D7BAF" # Slate Blue
758-
CONFIRMATION_Y_N_Q = "#EE8DF8" # Light Purple/Pink
759-
SYMBOL = "#E7CC51" # Gold
760-
BALANCE = "#4F91C6" # Medium Blue
761-
COST = "#53B5A0" # Teal
762-
SUCCESS = "#53B5A0" # Teal
763-
NETUID = "#CBA880" # Tan
764-
NETUID_EXTRA = "#DDD5A9" # Light Khaki
765-
TEMPO = "#67A3A5" # Grayish Teal
749+
HEADER = "#57878B" # Mid Blue Green
750+
LINKS = "#8CAAAE" # Pale Blue
751+
HINT = "#6C8871" # Muted Green
752+
COLDKEY = "#676B72" # Dark Grey Blue
753+
HOTKEY = "#747065" # Dark Orange Grey
754+
SUBHEADING_MAIN = "#8AA499" # Muted Blue Green
755+
SUBHEADING = "#9BAC9C" # Pale Green
756+
SUBHEADING_EXTRA_1 = "#C596A3" # Dusty Rose
757+
SUBHEADING_EXTRA_2 = "#9BAC9C" # Pale Green
758+
CONFIRMATION_Y_N_Q = "#EFB7AB" # Pale Pink
759+
SYMBOL = "#FE917A" # Salmon Orange
760+
SUBNET_NAME = "#C596A3" # Dusty Rose
761+
VALIDATOR_NAME = "#9BAC9C" # Mid Lime Green
762+
MINER_NAME = "#A17E7E" # Dusty Red
763+
BALANCE = "#757B7B" # Muted teal Blue
764+
COST = "#8EB27A" # Green
765+
SUCCESS = "#3D7F71" # Dark Teal
766+
NETUID = "#BDC1C6" # GREY_400
767+
NETUID_EXTRA = "#D4D0C1" # Light Yellow Grey
768+
TEMPO = "#927A71" # Dark Tan Brown
766769
# aliases
767770
CK = COLDKEY
768771
HK = HOTKEY
@@ -777,25 +780,25 @@ class Stake(Gettable):
777780
STAKE_AMOUNT = "#53B5A0" # Teal
778781
STAKE_ALPHA = "#53B5A0" # Teal
779782
STAKE_SWAP = "#67A3A5" # Grayish Teal
780-
TAO = "#4F91C6" # Medium Blue
781-
SLIPPAGE_TEXT = "#C25E7C" # Rose
782-
SLIPPAGE_PERCENT = "#E7B195" # Light Coral
783-
NOT_REGISTERED = "#EB6A6C" # Salmon Red
784-
EXTRA_1 = "#D781BB" # Pink
783+
TAO = "#8AA499" # Faded Blue Green
784+
SLIPPAGE_TEXT = "#BA938A" # Brown Salmon
785+
SLIPPAGE_PERCENT = "#CD8B7B" # Muted Salmon
786+
NOT_REGISTERED = "#A87D7D" # Medium Red brown
787+
EXTRA_1 = "#A45E44" # Deep Autumn Orange
785788
# aliases
786789
AMOUNT = STAKE_AMOUNT
787790
ALPHA = STAKE_ALPHA
788791
SWAP = STAKE_SWAP
789792

790793
class Pools(Gettable):
791-
TAO = "#4F91C6" # Medium Blue
792-
ALPHA_IN = "#D09FE9" # Light Purple
793-
ALPHA_OUT = "#AB7CC8" # Medium Purple
794-
RATE = "#F8D384" # Light Orange
795-
TAO_EQUIV = "#8CB9E9" # Sky Blue
796-
EMISSION = "#F8D384" # Light Orange
797-
EXTRA_1 = "#CAA8FB" # Lavender
798-
EXTRA_2 = "#806DAF" # Dark Purple
794+
TAO = "#8AA499" # Faded Blue Green
795+
ALPHA_IN = "#C1913C" # Mustard
796+
ALPHA_OUT = "#B49766" # Khaki Mustard
797+
RATE = "#A46844" # Deep Orange
798+
TAO_EQUIV = "#93BBAF" # Teal Blue
799+
EMISSION = "#B58065" # Med Orange
800+
EXTRA_1 = "#919170" # Autumn green
801+
EXTRA_2 = "#667862" # Forest green
799802

800803
class Grey(Gettable):
801804
GREY_100 = "#F8F9FA" # Almost White
@@ -820,9 +823,9 @@ class Grey(Gettable):
820823
G_900 = GREY_900
821824

822825
class Sudo(Gettable):
823-
HYPERPARAMETER = "#4F91C6" # Medium Blue
824-
VALUE = "#D09FE9" # Light Purple
825-
NORMALIZED = "#AB7CC8" # Medium Purple
826+
HYPERPARAMETER = "#93AFA3" # Forest
827+
VALUE = "#B58065" # Burnt Orange
828+
NORMALIZED = "#A87575" # Burnt Red
826829
# aliases
827830
HYPERPARAM = HYPERPARAMETER
828831
NORMAL = NORMALIZED

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ def tao_to_alpha_with_slippage(
749749
self, tao: Balance
750750
) -> tuple[Balance, Balance, float]:
751751
"""
752-
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool state.
752+
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool
753+
state.
754+
753755
Args:
754756
tao: Amount of TAO to stake.
755757
Returns:
@@ -792,7 +794,9 @@ def alpha_to_tao_with_slippage(
792794
self, alpha: Balance
793795
) -> tuple[Balance, Balance, float]:
794796
"""
795-
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool state.
797+
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool
798+
state.
799+
796800
Args:
797801
alpha: Amount of Alpha to stake.
798802
Returns:

bittensor_cli/src/bittensor/extrinsics/registration.py

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ async def get_neuron_for_pubkey_and_subnet():
524524
if prompt:
525525
if not Confirm.ask(
526526
f"Continue Registration?\n"
527-
f" hotkey [{COLOR_PALETTE['GENERAL']['HOTKEY']}]({wallet.hotkey_str})[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]:\t[{COLOR_PALETTE['GENERAL']['HOTKEY']}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
528-
f" coldkey [{COLOR_PALETTE['GENERAL']['COLDKEY']}]({wallet.name})[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]:\t[{COLOR_PALETTE['GENERAL']['COLDKEY']}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]\n"
529-
f" network:\t\t[{COLOR_PALETTE['GENERAL']['LINKS']}]{subtensor.network}[/{COLOR_PALETTE['GENERAL']['LINKS']}]\n"
527+
f" hotkey [{COLOR_PALETTE.G.HK}]({wallet.hotkey_str})[/{COLOR_PALETTE.G.HK}]:"
528+
f"\t[{COLOR_PALETTE.G.HK}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE.G.HK}]\n"
529+
f" coldkey [{COLOR_PALETTE.G.CK}]({wallet.name})[/{COLOR_PALETTE.G.CK}]:"
530+
f"\t[{COLOR_PALETTE.G.CK}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE.G.CK}]\n"
531+
f" network:\t\t[{COLOR_PALETTE.G.LINKS}]{subtensor.network}[/{COLOR_PALETTE.G.LINKS}]\n"
530532
):
531533
return False
532534

@@ -611,7 +613,6 @@ async def get_neuron_for_pubkey_and_subnet():
611613
if not wait_for_finalization and not wait_for_inclusion:
612614
success, err_msg = True, ""
613615
else:
614-
await response.process_events()
615616
success = await response.is_success
616617
if not success:
617618
success, err_msg = (
@@ -676,8 +677,9 @@ async def burned_register_extrinsic(
676677
old_balance: Balance,
677678
wait_for_inclusion: bool = True,
678679
wait_for_finalization: bool = True,
680+
era: Optional[int] = None,
679681
prompt: bool = False,
680-
) -> bool:
682+
) -> tuple[bool, str]:
681683
"""Registers the wallet to chain by recycling TAO.
682684
683685
:param subtensor: The SubtensorInterface object to use for the call, initialized
@@ -688,10 +690,11 @@ async def burned_register_extrinsic(
688690
`False` if the extrinsic fails to enter the block within the timeout.
689691
:param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning `True`,
690692
or returns `False` if the extrinsic fails to be finalized within the timeout.
693+
:param era: the period (in blocks) for which the transaction should remain valid.
691694
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
692695
693-
:return: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
694-
finalization/inclusion, the response is `True`.
696+
:return: (success, msg), where success is `True` if extrinsic was finalized or included in the block. If we did not
697+
wait for finalization/inclusion, the response is `True`.
695698
"""
696699

697700
if not (unlock_status := unlock_key(wallet, print_out=False)).success:
@@ -704,23 +707,42 @@ async def burned_register_extrinsic(
704707
my_uid = await subtensor.query(
705708
"SubtensorModule", "Uids", [netuid, wallet.hotkey.ss58_address]
706709
)
710+
block_hash = await subtensor.substrate.get_chain_head()
707711

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

715737
if not neuron.is_null:
716738
console.print(
717739
":white_heavy_check_mark: [dark_sea_green3]Already Registered[/dark_sea_green3]:\n"
718-
f"uid: [{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]{neuron.uid}[/{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]\n"
719-
f"netuid: [{COLOR_PALETTE['GENERAL']['NETUID']}]{neuron.netuid}[/{COLOR_PALETTE['GENERAL']['NETUID']}]\n"
720-
f"hotkey: [{COLOR_PALETTE['GENERAL']['HOTKEY']}]{neuron.hotkey}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
721-
f"coldkey: [{COLOR_PALETTE['GENERAL']['COLDKEY']}]{neuron.coldkey}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]"
740+
f"uid: [{COLOR_PALETTE.G.NETUID_EXTRA}]{neuron.uid}[/{COLOR_PALETTE.G.NETUID_EXTRA}]\n"
741+
f"netuid: [{COLOR_PALETTE.G.NETUID}]{neuron.netuid}[/{COLOR_PALETTE.G.NETUID}]\n"
742+
f"hotkey: [{COLOR_PALETTE.G.HK}]{neuron.hotkey}[/{COLOR_PALETTE.G.HK}]\n"
743+
f"coldkey: [{COLOR_PALETTE.G.CK}]{neuron.coldkey}[/{COLOR_PALETTE.G.CK}]"
722744
)
723-
return True
745+
return True, "Already registered"
724746

725747
with console.status(
726748
":satellite: Recycling TAO for Registration...", spinner="aesthetic"
@@ -734,13 +756,13 @@ async def burned_register_extrinsic(
734756
},
735757
)
736758
success, err_msg = await subtensor.sign_and_send_extrinsic(
737-
call, wallet, wait_for_inclusion, wait_for_finalization
759+
call, wallet, wait_for_inclusion, wait_for_finalization, era=era_
738760
)
739761

740762
if not success:
741763
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
742764
await asyncio.sleep(0.5)
743-
return False
765+
return False, err_msg
744766
# Successful registration, final check for neuron and pubkey
745767
else:
746768
with console.status(":satellite: Checking Balance...", spinner="aesthetic"):
@@ -761,20 +783,21 @@ async def burned_register_extrinsic(
761783

762784
console.print(
763785
"Balance:\n"
764-
f" [blue]{old_balance}[/blue] :arrow_right: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
786+
f" [blue]{old_balance}[/blue] :arrow_right: "
787+
f"[{COLOR_PALETTE.S.STAKE_AMOUNT}]{new_balance}[/{COLOR_PALETTE.S.STAKE_AMOUNT}]"
765788
)
766789

767790
if len(netuids_for_hotkey) > 0:
768791
console.print(
769792
f":white_heavy_check_mark: [green]Registered on netuid {netuid} with UID {my_uid}[/green]"
770793
)
771-
return True
794+
return True, f"Registered on {netuid} with UID {my_uid}"
772795
else:
773796
# neuron not found, try again
774797
err_console.print(
775798
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
776799
)
777-
return False
800+
return False, "Unknown error. Neuron not found."
778801

779802

780803
async def run_faucet_extrinsic(
@@ -894,7 +917,6 @@ async def run_faucet_extrinsic(
894917
)
895918

896919
# process if registration successful, try again if pow is still valid
897-
await response.process_events()
898920
if not await response.is_success:
899921
err_console.print(
900922
f":cross_mark: [red]Failed[/red]: "
@@ -1737,7 +1759,8 @@ async def swap_hotkey_extrinsic(
17371759
)
17381760
if not len(netuids_registered) > 0:
17391761
err_console.print(
1740-
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. Please register and try again"
1762+
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. "
1763+
f"Please register and try again"
17411764
)
17421765
return False
17431766

@@ -1754,7 +1777,8 @@ async def swap_hotkey_extrinsic(
17541777
):
17551778
return False
17561779
print_verbose(
1757-
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with {new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
1780+
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with "
1781+
f"{new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
17581782
)
17591783
with console.status(":satellite: Swapping hotkeys...", spinner="aesthetic"):
17601784
call = await subtensor.substrate.compose_call(

bittensor_cli/src/bittensor/extrinsics/root.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async def root_register_extrinsic(
291291
wait_for_inclusion: bool = True,
292292
wait_for_finalization: bool = True,
293293
prompt: bool = False,
294-
) -> bool:
294+
) -> tuple[bool, str]:
295295
r"""Registers the wallet to root network.
296296
297297
:param subtensor: The SubtensorInterface object
@@ -302,12 +302,12 @@ async def root_register_extrinsic(
302302
or returns `False` if the extrinsic fails to be finalized within the timeout.
303303
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
304304
305-
:return: `True` if extrinsic was finalized or included in the block. If we did not wait for finalization/inclusion,
306-
the response is `True`.
305+
:return: (success, msg), with success being `True` if extrinsic was finalized or included in the block. If we did
306+
not wait for finalization/inclusion, the response is `True`.
307307
"""
308308

309-
if not unlock_key(wallet).success:
310-
return False
309+
if not (unlock := unlock_key(wallet)).success:
310+
return False, unlock.message
311311

312312
print_verbose(f"Checking if hotkey ({wallet.hotkey_str}) is registered on root")
313313
is_registered = await is_hotkey_registered(
@@ -317,7 +317,7 @@ async def root_register_extrinsic(
317317
console.print(
318318
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
319319
)
320-
return True
320+
return True, "Already registered on root network"
321321

322322
with console.status(":satellite: Registering to root network...", spinner="earth"):
323323
call = await subtensor.substrate.compose_call(
@@ -334,8 +334,8 @@ async def root_register_extrinsic(
334334

335335
if not success:
336336
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
337-
time.sleep(0.5)
338-
return False
337+
await asyncio.sleep(0.5)
338+
return False, err_msg
339339

340340
# Successful registration, final check for neuron and pubkey
341341
else:
@@ -348,13 +348,13 @@ async def root_register_extrinsic(
348348
console.print(
349349
f":white_heavy_check_mark: [green]Registered with UID {uid}[/green]"
350350
)
351-
return True
351+
return True, f"Registered with UID {uid}"
352352
else:
353353
# neuron not found, try again
354354
err_console.print(
355355
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
356356
)
357-
return False
357+
return False, "Unknown error. Neuron not found."
358358

359359

360360
async def set_root_weights_extrinsic(
@@ -410,7 +410,6 @@ async def _do_set_weights():
410410
if not wait_for_finalization and not wait_for_inclusion:
411411
return True, "Not waiting for finalization or inclusion."
412412

413-
await response.process_events()
414413
if await response.is_success:
415414
return True, "Successfully set weights."
416415
else:

bittensor_cli/src/bittensor/extrinsics/transfer.py

Lines changed: 5 additions & 3 deletions
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,
@@ -36,6 +37,7 @@ async def transfer_extrinsic(
3637
:param wallet: Bittensor wallet object to make transfer from.
3738
:param destination: Destination public key address (ss58_address or ed25519) of recipient.
3839
:param amount: Amount to stake as Bittensor balance.
40+
:param era: Length (in blocks) for which the transaction should be valid.
3941
:param transfer_all: Whether to transfer all funds from this wallet to the destination address.
4042
:param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`,
4143
or returns `False` if the extrinsic fails to enter the block within the timeout.
@@ -84,7 +86,7 @@ async def do_transfer() -> tuple[bool, str, str]:
8486
call_params={"dest": destination, "value": amount.rao},
8587
)
8688
extrinsic = await subtensor.substrate.create_signed_extrinsic(
87-
call=call, keypair=wallet.coldkey
89+
call=call, keypair=wallet.coldkey, era={"period": era}
8890
)
8991
response = await subtensor.substrate.submit_extrinsic(
9092
extrinsic,
@@ -96,7 +98,6 @@ async def do_transfer() -> tuple[bool, str, str]:
9698
return True, "", ""
9799

98100
# Otherwise continue with finalization.
99-
await response.process_events()
100101
if await response.is_success:
101102
block_hash_ = response.block_hash
102103
return True, block_hash_, ""
@@ -155,7 +156,8 @@ async def do_transfer() -> tuple[bool, str, str]:
155156
if not Confirm.ask(
156157
"Do you want to transfer:[bold white]\n"
157158
f" amount: [bright_cyan]{amount}[/bright_cyan]\n"
158-
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : [bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
159+
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : "
160+
f"[bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
159161
f" to: [bright_magenta]{destination}[/bright_magenta]\n for fee: [bright_cyan]{fee}[/bright_cyan]"
160162
):
161163
return False

0 commit comments

Comments
 (0)