Skip to content

Commit

Permalink
Merge pull request #268 from opentensor/release/8.4.1
Browse files Browse the repository at this point in the history
Release/8.4.1
  • Loading branch information
ibraheem-opentensor authored Dec 6, 2024
2 parents 1be041d + 362b22f commit 2833e36
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 101 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 8.4.1 /2024-12-05

## What's Changed
* Sometimes err_docs is a string. We want to handle this properly. by @thewhaleking in https://github.com/opentensor/btcli/pull/260
* Sudo Hyperparams by @thewhaleking in https://github.com/opentensor/btcli/pull/261
* Sorted netuids in `btcli r get-weights` by @thewhaleking in https://github.com/opentensor/btcli/pull/258
* Show hyperparams during `sudo set` only sometimes by @thewhaleking in https://github.com/opentensor/btcli/pull/262
* Update stake children help menu by @thewhaleking in https://github.com/opentensor/btcli/pull/264
* Updates bt-decode to 0.4.0 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/265
* Backmerge main to staging for 8.4.1 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/267

**Full Changelog**: https://github.com/opentensor/btcli/compare/v8.4.0...v8.4.1

## 8.4.0 /2024-11-27

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
from .cli import CLIManager


__version__ = "8.4.0"
__version__ = "8.4.1"

__all__ = ["CLIManager", "__version__"]
18 changes: 9 additions & 9 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GitError(Exception):
pass


__version__ = "8.4.0"
__version__ = "8.4.1"


_core_version = re.match(r"^\d+\.\d+\.\d+", __version__).group(0)
Expand Down Expand Up @@ -3659,7 +3659,7 @@ def stake_set_children(
prompt: bool = Options.prompt,
):
"""
Set child hotkeys on specified subnets.
Set child hotkeys on a specified subnet (or all). Overrides currently set children.
Users can specify the 'proportion' to delegate to child hotkeys (ss58 address). The sum of proportions cannot be greater than 1.
Expand Down Expand Up @@ -3744,7 +3744,7 @@ def stake_revoke_children(
prompt: bool = Options.prompt,
):
"""
Remove all children hotkeys on a specified subnet.
Remove all children hotkeys on a specified subnet (or all).
This command is used to remove delegated authority from all child hotkeys, removing their position and influence on the subnet.
Expand Down Expand Up @@ -3884,12 +3884,12 @@ def sudo_set(
"""
self.verbosity_handler(quiet, verbose)

hyperparams = self._run_command(
sudo.get_hyperparameters(self.initialize_chain(network), netuid)
)

if not hyperparams:
raise typer.Exit()
if not param_name or not param_value:
hyperparams = self._run_command(
sudo.get_hyperparameters(self.initialize_chain(network), netuid)
)
if not hyperparams:
raise typer.Exit()

if not param_name:
hyperparam_list = [field.name for field in fields(SubnetHyperparameters)]
Expand Down
56 changes: 30 additions & 26 deletions bittensor_cli/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,32 +318,36 @@ class WalletValidationTypes(Enum):


HYPERPARAMS = {
"rho": "sudo_set_rho",
"kappa": "sudo_set_kappa",
"immunity_period": "sudo_set_immunity_period",
"min_allowed_weights": "sudo_set_min_allowed_weights",
"max_weights_limit": "sudo_set_max_weight_limit",
"tempo": "sudo_set_tempo",
"min_difficulty": "sudo_set_min_difficulty",
"max_difficulty": "sudo_set_max_difficulty",
"weights_version": "sudo_set_weights_version_key",
"weights_rate_limit": "sudo_set_weights_set_rate_limit",
"adjustment_interval": "sudo_set_adjustment_interval",
"activity_cutoff": "sudo_set_activity_cutoff",
"target_regs_per_interval": "sudo_set_target_registrations_per_interval",
"min_burn": "sudo_set_min_burn",
"max_burn": "sudo_set_max_burn",
"bonds_moving_avg": "sudo_set_bonds_moving_average",
"max_regs_per_block": "sudo_set_max_registrations_per_block",
"serving_rate_limit": "sudo_set_serving_rate_limit",
"max_validators": "sudo_set_max_allowed_validators",
"adjustment_alpha": "sudo_set_adjustment_alpha",
"difficulty": "sudo_set_difficulty",
"commit_reveal_weights_interval": "sudo_set_commit_reveal_weights_interval",
"commit_reveal_weights_enabled": "sudo_set_commit_reveal_weights_enabled",
"alpha_values": "sudo_set_alpha_values",
"liquid_alpha_enabled": "sudo_set_liquid_alpha_enabled",
"registration_allowed": "sudo_set_network_registration_allowed",
# btcli name: (subtensor method, sudo bool)
"rho": ("sudo_set_rho", False),
"kappa": ("sudo_set_kappa", False),
"immunity_period": ("sudo_set_immunity_period", False),
"min_allowed_weights": ("sudo_set_min_allowed_weights", False),
"max_weights_limit": ("sudo_set_max_weight_limit", False),
"tempo": ("sudo_set_tempo", True),
"min_difficulty": ("sudo_set_min_difficulty", False),
"max_difficulty": ("sudo_set_max_difficulty", False),
"weights_version": ("sudo_set_weights_version_key", False),
"weights_rate_limit": ("sudo_set_weights_set_rate_limit", False),
"adjustment_interval": ("sudo_set_adjustment_interval", True),
"activity_cutoff": ("sudo_set_activity_cutoff", False),
"target_regs_per_interval": ("sudo_set_target_registrations_per_interval", True),
"min_burn": ("sudo_set_min_burn", False),
"max_burn": ("sudo_set_max_burn", False),
"bonds_moving_avg": ("sudo_set_bonds_moving_average", False),
"max_regs_per_block": ("sudo_set_max_registrations_per_block", True),
"serving_rate_limit": ("sudo_set_serving_rate_limit", False),
"max_validators": ("sudo_set_max_allowed_validators", True),
"adjustment_alpha": ("sudo_set_adjustment_alpha", False),
"difficulty": ("sudo_set_difficulty", False),
"commit_reveal_weights_interval": (
"sudo_set_commit_reveal_weights_interval",
False,
),
"commit_reveal_weights_enabled": ("sudo_set_commit_reveal_weights_enabled", False),
"alpha_values": ("sudo_set_alpha_values", False),
"liquid_alpha_enabled": ("sudo_set_liquid_alpha_enabled", False),
"registration_allowed": ("sudo_set_network_registration_allowed", False),
}

# Help Panels for cli help
Expand Down
7 changes: 2 additions & 5 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,7 @@ async def get_neuron_for_pubkey_and_subnet():
if not success:
success, err_msg = (
False,
format_error_message(
await response.error_message,
substrate=subtensor.substrate,
),
format_error_message(await response.error_message),
)
# Look error here
# https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs
Expand Down Expand Up @@ -795,7 +792,7 @@ async def run_faucet_extrinsic(
if not await response.is_success:
err_console.print(
f":cross_mark: [red]Failed[/red]: "
f"{format_error_message(await response.error_message, subtensor.substrate)}"
f"{format_error_message(await response.error_message)}"
)
if attempts == max_allowed_attempts:
raise MaxAttemptsException
Expand Down
4 changes: 2 additions & 2 deletions bittensor_cli/src/bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ async def _do_set_weights():
console.print(":white_heavy_check_mark: [green]Finalized[/green]")
return True
else:
fmt_err = format_error_message(error_message, subtensor.substrate)
fmt_err = format_error_message(error_message)
err_console.print(f":cross_mark: [red]Failed[/red]: {fmt_err}")
return False

except SubstrateRequestException as e:
fmt_err = format_error_message(e, subtensor.substrate)
fmt_err = format_error_message(e)
err_console.print(":cross_mark: [red]Failed[/red]: error:{}".format(fmt_err))
return False
4 changes: 2 additions & 2 deletions bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def get_transfer_fee() -> Balance:
payment_info = {"partialFee": int(2e7)} # assume 0.02 Tao
err_console.print(
f":cross_mark: [red]Failed to get payment info[/red]:[bold white]\n"
f" {format_error_message(e, subtensor.substrate)}[/bold white]\n"
f" {format_error_message(e)}[/bold white]\n"
f" Defaulting to default transfer fee: {payment_info['partialFee']}"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ async def do_transfer() -> tuple[bool, str, str]:
return (
False,
"",
format_error_message(await response.error_message, subtensor.substrate),
format_error_message(await response.error_message),
)

# Validate destination address.
Expand Down
8 changes: 3 additions & 5 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,9 @@ async def sign_and_send_extrinsic(
if await response.is_success:
return True, ""
else:
return False, format_error_message(
await response.error_message, substrate=self.substrate
)
return False, format_error_message(await response.error_message)
except SubstrateRequestException as e:
return False, format_error_message(e, substrate=self.substrate)
return False, format_error_message(e)

async def get_children(self, hotkey, netuid) -> tuple[bool, list, str]:
"""
Expand Down Expand Up @@ -947,7 +945,7 @@ async def get_children(self, hotkey, netuid) -> tuple[bool, list, str]:
else:
return True, [], ""
except SubstrateRequestException as e:
return False, [], format_error_message(e, self.substrate)
return False, [], format_error_message(e)

async def get_subnet_hyperparameters(
self, netuid: int, block_hash: Optional[str] = None
Expand Down
25 changes: 4 additions & 21 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,13 @@ def get_explorer_url_for_network(
return explorer_urls


def format_error_message(
error_message: Union[dict, Exception], substrate: "AsyncSubstrateInterface"
) -> str:
def format_error_message(error_message: Union[dict, Exception]) -> str:
"""
Formats an error message from the Subtensor error information for use in extrinsics.
Args:
error_message: A dictionary containing the error information from Subtensor, or a SubstrateRequestException
containing dictionary literal args.
substrate: The initialised SubstrateInterface object to use.
Returns:
str: A formatted error message string.
Expand Down Expand Up @@ -509,22 +506,8 @@ def format_error_message(
err_data = error_message.get("data", "")

# subtensor custom error marker
if err_data.startswith("Custom error:") and substrate:
if substrate.metadata:
try:
pallet = substrate.metadata.get_metadata_pallet(
"SubtensorModule"
)
error_index = int(err_data.split("Custom error:")[-1])

error_dict = pallet.errors[error_index].value
err_type = error_dict.get("message", err_type)
err_docs = error_dict.get("docs", [])
err_description = err_docs[0] if err_docs else err_description
except (AttributeError, IndexError):
err_console.print(
"Substrate pallets data unavailable. This is usually caused by an uninitialized substrate."
)
if err_data.startswith("Custom error:"):
err_description = f"{err_data} | Please consult https://docs.bittensor.com/subtensor-nodes/subtensor-error-messages"
else:
err_description = err_data

Expand All @@ -538,7 +521,7 @@ def format_error_message(
err_docs = error_message.get("docs", [err_description])
err_description = err_docs[0] if err_docs else err_description

return f"Subtensor returned `{err_name}({err_type})` error. This means: '{err_description}'."
return f"Subtensor returned `{err_name}({err_type})` error. This means: `{err_description}`."


def convert_blocks_to_time(blocks: int, block_time: int = 12) -> tuple[int, int, int]:
Expand Down
22 changes: 11 additions & 11 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,13 @@ async def get_weights(

uid_to_weights[uid][netuid] = normalized_weight
rows: list[list[str]] = []
sorted_netuids: list = list(netuids)
sorted_netuids.sort()
for uid in uid_to_weights:
row = [str(uid)]

uid_weights = uid_to_weights[uid]
for netuid in netuids:
for netuid in sorted_netuids:
if netuid in uid_weights:
row.append("{:0.2f}%".format(uid_weights[netuid] * 100))
else:
Expand All @@ -879,24 +881,23 @@ async def get_weights(

if not no_cache:
db_cols = [("UID", "INTEGER")]
for netuid in netuids:
for netuid in sorted_netuids:
db_cols.append((f"_{netuid}", "TEXT"))
create_table("rootgetweights", db_cols, rows)
netuids = list(netuids)
update_metadata_table(
"rootgetweights",
{"rows": json.dumps(rows), "netuids": json.dumps(netuids)},
{"rows": json.dumps(rows), "netuids": json.dumps(sorted_netuids)},
)
else:
metadata = get_metadata_table("rootgetweights")
rows = json.loads(metadata["rows"])
netuids = json.loads(metadata["netuids"])
sorted_netuids = json.loads(metadata["netuids"])

_min_lim = limit_min_col if limit_min_col is not None else 0
_max_lim = limit_max_col + 1 if limit_max_col is not None else len(netuids)
_max_lim = min(_max_lim, len(netuids))
_max_lim = limit_max_col + 1 if limit_max_col is not None else len(sorted_netuids)
_max_lim = min(_max_lim, len(sorted_netuids))

if _min_lim is not None and _min_lim > len(netuids):
if _min_lim is not None and _min_lim > len(sorted_netuids):
err_console.print("Minimum limit greater than number of netuids")
return

Expand All @@ -915,8 +916,7 @@ async def get_weights(
style="rgb(50,163,219)",
no_wrap=True,
)
netuids = list(netuids)
for netuid in netuids[_min_lim:_max_lim]:
for netuid in sorted_netuids[_min_lim:_max_lim]:
table.add_column(
f"[white]{netuid}",
header_style="overline white",
Expand All @@ -939,7 +939,7 @@ async def get_weights(

else:
html_cols = [{"title": "UID", "field": "UID"}]
for netuid in netuids[_min_lim:_max_lim]:
for netuid in sorted_netuids[_min_lim:_max_lim]:
html_cols.append({"title": str(netuid), "field": f"_{netuid}"})
render_table(
"rootgetweights",
Expand Down
6 changes: 2 additions & 4 deletions bittensor_cli/src/commands/stake/children_hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def set_childkey_take_extrinsic(
except SubstrateRequestException as e:
return (
False,
f"Exception occurred while setting childkey take: {format_error_message(e, subtensor.substrate)}",
f"Exception occurred while setting childkey take: {format_error_message(e)}",
)


Expand All @@ -232,9 +232,7 @@ async def get_childkey_take(subtensor, hotkey: str, netuid: int) -> Optional[int
return int(childkey_take_.value)

except SubstrateRequestException as e:
err_console.print(
f"Error querying ChildKeys: {format_error_message(e, subtensor.substrate)}"
)
err_console.print(f"Error querying ChildKeys: {format_error_message(e)}")
return None


Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/commands/subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def _find_event_attributes_in_extrinsic_receipt(
await response.process_events()
if not await response.is_success:
err_console.print(
f":cross_mark: [red]Failed[/red]: {format_error_message(await response.error_message, substrate)}"
f":cross_mark: [red]Failed[/red]: {format_error_message(await response.error_message)}"
)
await asyncio.sleep(0.5)
return False
Expand Down
10 changes: 8 additions & 2 deletions bittensor_cli/src/commands/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def set_hyperparameter_extrinsic(
if not unlock_key(wallet).success:
return False

extrinsic = HYPERPARAMS.get(parameter)
extrinsic, sudo_ = HYPERPARAMS.get(parameter, ("", False))
if extrinsic is None:
err_console.print(":cross_mark: [red]Invalid hyperparameter specified.[/red]")
return False
Expand Down Expand Up @@ -144,11 +144,17 @@ async def set_hyperparameter_extrinsic(
call_params[str(value_argument["name"])] = value

# create extrinsic call
call = await substrate.compose_call(
call_ = await substrate.compose_call(
call_module="AdminUtils",
call_function=extrinsic,
call_params=call_params,
)
if sudo_:
call = await substrate.compose_call(
call_module="Sudo", call_function="sudo", call_params={"call": call_}
)
else:
call = call_
success, err_msg = await subtensor.sign_and_send_extrinsic(
call, wallet, wait_for_inclusion, wait_for_finalization
)
Expand Down
Loading

0 comments on commit 2833e36

Please sign in to comment.