From 2637d8834b258d5d97870de887899c91ce613d15 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 7 Mar 2025 10:30:21 -0800 Subject: [PATCH 1/4] Updates the lengths --- bittensor_cli/src/bittensor/utils.py | 63 +++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 5fbf37bf8..ed8445f78 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -1097,38 +1097,30 @@ def prompt_for_identity( identity_fields = {} fields = [ - ("name", "[blue]Display name[/blue]", name), - ("url", "[blue]Web URL[/blue]", web_url), - ("image", "[blue]Image URL[/blue]", image_url), - ("discord", "[blue]Discord handle[/blue]", discord), - ("description", "[blue]Description[/blue]", description), - ("additional", "[blue]Additional information[/blue]", additional), - ("github_repo", "[blue]GitHub repository URL[/blue]", github_repo), + ("name", "[blue]Display name[/blue]", name, 256), + ("url", "[blue]Web URL[/blue]", web_url, 256), + ("image", "[blue]Image URL[/blue]", image_url, 1024), + ("discord", "[blue]Discord handle[/blue]", discord, 256), + ("description", "[blue]Description[/blue]", description, 1024), + ("additional", "[blue]Additional information[/blue]", additional, 1024), + ("github_repo", "[blue]GitHub repository URL[/blue]", github_repo, 256), ] - text_rejection = partial( - retry_prompt, - rejection=lambda x: sys.getsizeof(x) > 113, - rejection_text="[red]Error:[/red] Identity field must be <= 64 raw bytes.", - ) - if not any( - [ - name, - web_url, - image_url, - discord, - description, - additional, - github_repo, - ] + [name, web_url, image_url, discord, description, additional, github_repo] ): console.print( "\n[yellow]All fields are optional. Press Enter to skip and keep the default/existing value.[/yellow]\n" "[dark_sea_green3]Tip: Entering a space and pressing Enter will clear existing default value.\n" ) - for key, prompt, value in fields: + for key, prompt, value, byte_limit in fields: + text_rejection = partial( + retry_prompt, + rejection=lambda x: len(x.encode("utf-8")) > byte_limit, + rejection_text=f"[red]Error:[/red] {key} field must be <= {byte_limit} bytes.", + ) + if value: identity_fields[key] = value else: @@ -1170,50 +1162,51 @@ def prompt_for_subnet_identity( "subnet_name", "[blue]Subnet name [dim](optional)[/blue]", subnet_name, - lambda x: x and sys.getsizeof(x) > 113, - "[red]Error:[/red] Subnet name must be <= 64 raw bytes.", + lambda x: x and len(x.encode("utf-8")) > 256, + "[red]Error:[/red] Subnet name must be <= 256 bytes.", ), ( "github_repo", "[blue]GitHub repository URL [dim](optional)[/blue]", github_repo, - lambda x: x and not is_valid_github_url(x), + lambda x: x + and (not is_valid_github_url(x) or len(x.encode("utf-8")) > 1024), "[red]Error:[/red] Please enter a valid GitHub repository URL (e.g., https://github.com/username/repo).", ), ( "subnet_contact", "[blue]Contact email [dim](optional)[/blue]", subnet_contact, - lambda x: x and not is_valid_contact(x), + lambda x: x and (not is_valid_contact(x) or len(x.encode("utf-8")) > 1024), "[red]Error:[/red] Please enter a valid email address.", ), ( "subnet_url", "[blue]Subnet URL [dim](optional)[/blue]", subnet_url, - lambda x: x and sys.getsizeof(x) > 113, - "[red]Error:[/red] Please enter a valid URL.", + lambda x: x and len(x.encode("utf-8")) > 1024, + "[red]Error:[/red] Please enter a valid URL <= 1024 bytes.", ), ( "discord", "[blue]Discord handle [dim](optional)[/blue]", discord, - lambda x: x and sys.getsizeof(x) > 113, - "[red]Error:[/red] Please enter a valid Discord handle.", + lambda x: x and len(x.encode("utf-8")) > 256, + "[red]Error:[/red] Please enter a valid Discord handle <= 256 bytes.", ), ( "description", "[blue]Description [dim](optional)[/blue]", description, - lambda x: x and sys.getsizeof(x) > 113, - "[red]Error:[/red] Description must be <= 64 raw bytes.", + lambda x: x and len(x.encode("utf-8")) > 1024, + "[red]Error:[/red] Description must be <= 1024 bytes.", ), ( "additional", "[blue]Additional information [dim](optional)[/blue]", additional, - lambda x: x and sys.getsizeof(x) > 113, - "[red]Error:[/red] Additional information must be <= 64 raw bytes.", + lambda x: x and len(x.encode("utf-8")) > 1024, + "[red]Error:[/red] Additional information must be <= 1024 bytes.", ), ] From 58bc28a72f36e45ac22d2416e29e1107f8da64d5 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 7 Mar 2025 10:30:36 -0800 Subject: [PATCH 2/4] Remove outdated len check --- bittensor_cli/src/commands/wallets.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 3df948ba3..8710de3e9 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -1361,15 +1361,6 @@ async def set_id( "github_repo": github_repo.encode(), } - for field, value in identity_data.items(): - max_size = 64 # bytes - if len(value) > max_size: - err_console.print( - f"[red]Error:[/red] Identity field [white]{field}[/white] must be <= {max_size} bytes.\n" - f"Value '{value.decode()}' is {len(value)} bytes." - ) - return False - if not unlock_key(wallet).success: return False From b04a791d896d2124327cd7412287b7128431c103 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 7 Mar 2025 10:36:43 -0800 Subject: [PATCH 3/4] Update wallet-identity prompt --- bittensor_cli/cli.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 79f4d2fef..e041c8076 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2682,23 +2682,29 @@ def wallet_get_id( [bold]Note[/bold]: This command is primarily used for informational purposes and has no side effects on the blockchain network state. """ wallet = None - if coldkey_ss58: - if not is_valid_ss58_address(coldkey_ss58): - print_error("You entered an invalid ss58 address") - raise typer.Exit() - else: - coldkey_or_ss58 = Prompt.ask( - "Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]", - default=self.config.get("wallet_name") or defaults.wallet.name, - ) - if is_valid_ss58_address(coldkey_or_ss58): - coldkey_ss58 = coldkey_or_ss58 + if not wallet_name: + if coldkey_ss58: + if not is_valid_ss58_address(coldkey_ss58): + print_error("You entered an invalid ss58 address") + raise typer.Exit() else: - wallet_name = coldkey_or_ss58 if coldkey_or_ss58 else wallet_name - wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] + coldkey_or_ss58 = Prompt.ask( + "Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]", + default=self.config.get("wallet_name") or defaults.wallet.name, ) - coldkey_ss58 = wallet.coldkeypub.ss58_address + if is_valid_ss58_address(coldkey_or_ss58): + coldkey_ss58 = coldkey_or_ss58 + else: + wallet_name = coldkey_or_ss58 if coldkey_or_ss58 else wallet_name + wallet = self.wallet_ask( + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] + ) + coldkey_ss58 = wallet.coldkeypub.ss58_address + else: + wallet = self.wallet_ask( + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] + ) + coldkey_ss58 = wallet.coldkeypub.ss58_address self.verbosity_handler(quiet, verbose) return self._run_command( From 21f50dd7e5d29171381cf84566ecfbac2f749a2d Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 7 Mar 2025 10:42:48 -0800 Subject: [PATCH 4/4] Limits the len of subnet name when displayed in cli commands --- bittensor_cli/src/bittensor/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index ed8445f78..35e3394a2 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -1266,16 +1266,18 @@ def is_valid_contact(contact: str) -> bool: return bool(re.match(email_pattern, contact)) -def get_subnet_name(subnet_info) -> str: +def get_subnet_name(subnet_info, max_length: int = 20) -> str: """Get the subnet name, prioritizing subnet_identity.subnet_name over subnet.subnet_name. + Truncates the name if it exceeds max_length. Args: - subnet: The subnet dynamic info + subnet_info: The subnet dynamic info + max_length: Maximum length of the returned name. Names longer than this will be truncated with '...' Returns: - str: The subnet name or empty string if no name is found + str: The subnet name (truncated if necessary) or empty string if no name is found """ - return ( + name = ( subnet_info.subnet_identity.subnet_name if hasattr(subnet_info, "subnet_identity") and subnet_info.subnet_identity is not None @@ -1283,6 +1285,10 @@ def get_subnet_name(subnet_info) -> str: else (subnet_info.subnet_name if subnet_info.subnet_name is not None else "") ) + if len(name) > max_length: + return name[: max_length - 3] + "..." + return name + def print_linux_dependency_message(): """Prints the WebKit dependency message for Linux systems."""