diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py
index 2528368094..8f7f3292b9 100644
--- a/bittensor/core/extrinsics/registration.py
+++ b/bittensor/core/extrinsics/registration.py
@@ -22,7 +22,6 @@
from retry import retry
from rich.prompt import Confirm
-from bittensor.core.settings import bt_console
from bittensor.utils import format_error_message
from bittensor.utils.btlogging import logging
from bittensor.utils.networking import ensure_connected
@@ -142,24 +141,22 @@ def register_extrinsic(
Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``.
"""
if not subtensor.subnet_exists(netuid):
- bt_console.print(
- ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist.".format(
- netuid
- )
+ logging.error(
+ f":cross_mark: Failed: Subnet {netuid} does not exist."
)
return False
- with bt_console.status(
- f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..."
- ):
- neuron = subtensor.get_neuron_for_pubkey_and_subnet(
- wallet.hotkey.ss58_address, netuid=netuid
+ logging.info(
+ f":satellite: Checking Account on subnet {netuid}..."
+ )
+ neuron = subtensor.get_neuron_for_pubkey_and_subnet(
+ wallet.hotkey.ss58_address, netuid=netuid
+ )
+ if not neuron.is_null:
+ logging.debug(
+ f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}."
)
- if not neuron.is_null:
- logging.debug(
- f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}"
- )
- return True
+ return True
if prompt:
if not Confirm.ask(
@@ -178,14 +175,14 @@ def register_extrinsic(
# Attempt rolling registration.
attempts = 1
while True:
- bt_console.print(
- ":satellite: Registering...({}/{})".format(attempts, max_allowed_attempts)
+ logging.info(
+ f":satellite: Registering... ({attempts}/{max_allowed_attempts})"
)
# Solve latest POW.
if cuda:
if not torch.cuda.is_available():
if prompt:
- bt_console.print("CUDA is not available.")
+ logging.info("CUDA is not available.")
return False
pow_result: Optional[POWSolution] = create_pow(
subtensor,
@@ -218,73 +215,71 @@ def register_extrinsic(
netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address
)
if is_registered:
- bt_console.print(
- f":white_heavy_check_mark: [green]Already registered on netuid:{netuid}[/green]"
+ logging.info(
+ f":white_heavy_check_mark: Already registered on netuid: {netuid}."
)
return True
# pow successful, proceed to submit pow to chain for registration
else:
- with bt_console.status(":satellite: Submitting POW..."):
- # check if pow result is still valid
- while not pow_result.is_stale(subtensor=subtensor):
- result: tuple[bool, Optional[str]] = _do_pow_register(
- self=subtensor,
- netuid=netuid,
- wallet=wallet,
- pow_result=pow_result,
- wait_for_inclusion=wait_for_inclusion,
- wait_for_finalization=wait_for_finalization,
- )
- success, err_msg = result
-
- if not success:
- # Look error here
- # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs
- if "HotKeyAlreadyRegisteredInSubNet" in err_msg:
- bt_console.print(
- f":white_heavy_check_mark: [green]Already Registered on [bold]subnet:{netuid}[/bold][/green]"
- )
- return True
+ logging.info(":satellite: Submitting POW...")
+ # check if pow result is still valid
+ while not pow_result.is_stale(subtensor=subtensor):
+ result: tuple[bool, Optional[str]] = _do_pow_register(
+ self=subtensor,
+ netuid=netuid,
+ wallet=wallet,
+ pow_result=pow_result,
+ wait_for_inclusion=wait_for_inclusion,
+ wait_for_finalization=wait_for_finalization,
+ )
+ success, err_msg = result
+
+ if not success:
+ # Look error here
+ # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs
+ if "HotKeyAlreadyRegisteredInSubNet" in err_msg:
+ logging.info(
+ f":white_heavy_check_mark: Already Registered on subnet {netuid}."
+ )
+ return True
- bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
- time.sleep(0.5)
+ logging.error(f":cross_mark: Failed: {err_msg}")
+ time.sleep(0.5)
- # Successful registration, final check for neuron and pubkey
+ # Successful registration, final check for neuron and pubkey
+ else:
+ logging.info(":satellite: Checking Balance...")
+ is_registered = subtensor.is_hotkey_registered(
+ hotkey_ss58=wallet.hotkey.ss58_address,
+ netuid=netuid,
+ )
+ if is_registered:
+ logging.info(
+ ":white_heavy_check_mark: Registered"
+ )
+ return True
else:
- bt_console.print(":satellite: Checking Balance...")
- is_registered = subtensor.is_hotkey_registered(
- hotkey_ss58=wallet.hotkey.ss58_address,
- netuid=netuid,
+ # neuron not found, try again
+ logging.error(
+ ":cross_mark: Unknown error. Neuron not found."
)
- if is_registered:
- bt_console.print(
- ":white_heavy_check_mark: [green]Registered[/green]"
- )
- return True
- else:
- # neuron not found, try again
- bt_console.print(
- ":cross_mark: [red]Unknown error. Neuron not found.[/red]"
- )
- continue
- else:
- # Exited loop because pow is no longer valid.
- bt_console.print("[red]POW is stale.[/red]")
- # Try again.
- continue
+ continue
+ else:
+ # Exited loop because pow is no longer valid.
+ logging.error("POW is stale.")
+ # Try again.
+ continue
if attempts < max_allowed_attempts:
# Failed registration, retry pow
attempts += 1
- bt_console.print(
- ":satellite: Failed registration, retrying pow ...({}/{})".format(
- attempts, max_allowed_attempts
- )
+ logging.info(
+ f":satellite: Failed registration, retrying pow ... ({attempts}/{max_allowed_attempts})"
)
else:
# Failed to register after max attempts.
- bt_console.print("[red]No more attempts.[/red]")
+ logging.error("No more attempts.")
return False
@@ -370,82 +365,70 @@ def burned_register_extrinsic(
success (bool): Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``.
"""
if not subtensor.subnet_exists(netuid):
- bt_console.print(
- ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist.".format(
- netuid
- )
+ logging.error(
+ f":cross_mark: Failed error: subnet {netuid} does not exist."
)
return False
try:
wallet.unlock_coldkey()
except KeyFileError:
- bt_console.print(
- ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]"
+ logging.error(
+ ":cross_mark: Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid."
)
return False
- with bt_console.status(
- f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..."
- ):
- neuron = subtensor.get_neuron_for_pubkey_and_subnet(
- wallet.hotkey.ss58_address, netuid=netuid
- )
-
- old_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
-
- recycle_amount = subtensor.recycle(netuid=netuid)
- if not neuron.is_null:
- bt_console.print(
- ":white_heavy_check_mark: [green]Already Registered[/green]:\n"
- "uid: [bold white]{}[/bold white]\n"
- "netuid: [bold white]{}[/bold white]\n"
- "hotkey: [bold white]{}[/bold white]\n"
- "coldkey: [bold white]{}[/bold white]".format(
- neuron.uid, neuron.netuid, neuron.hotkey, neuron.coldkey
- )
- )
- return True
+ logging.info(
+ f":satellite: Checking Account on subnet {netuid} ..."
+ )
+ neuron = subtensor.get_neuron_for_pubkey_and_subnet(
+ wallet.hotkey.ss58_address, netuid=netuid
+ )
+
+ old_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
+
+ recycle_amount = subtensor.recycle(netuid=netuid)
+ if not neuron.is_null:
+ logging.info(":white_heavy_check_mark: Already Registered")
+ logging.info(f"\t\tuid: {neuron.uid}")
+ logging.info(f"\t\tnetuid: {neuron.netuid}")
+ logging.info(f"\t\thotkey: {neuron.hotkey}")
+ logging.info(f"\t\tcoldkey: {neuron.coldkey}")
+ return True
if prompt:
# Prompt user for confirmation.
if not Confirm.ask(f"Recycle {recycle_amount} to register on subnet:{netuid}?"):
return False
- with bt_console.status(":satellite: Recycling TAO for Registration..."):
- success, err_msg = _do_burned_register(
- self=subtensor,
- netuid=netuid,
- wallet=wallet,
- wait_for_inclusion=wait_for_inclusion,
- wait_for_finalization=wait_for_finalization,
+ logging.info(":satellite: Recycling TAO for Registration...")
+ success, err_msg = _do_burned_register(
+ self=subtensor,
+ netuid=netuid,
+ wallet=wallet,
+ wait_for_inclusion=wait_for_inclusion,
+ wait_for_finalization=wait_for_finalization,
+ )
+
+ if not success:
+ logging.error(f":cross_mark: Failed: {err_msg}")
+ time.sleep(0.5)
+ return False
+ # Successful registration, final check for neuron and pubkey
+ else:
+ logging.info(":satellite: Checking Balance...")
+ block = subtensor.get_current_block()
+ new_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address, block=block)
+
+ logging.info(
+ f"Balance: {old_balance} :arrow_right: {new_balance}"
)
-
- if not success:
- bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
- time.sleep(0.5)
- return False
- # Successful registration, final check for neuron and pubkey
+ is_registered = subtensor.is_hotkey_registered(
+ netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address
+ )
+ if is_registered:
+ logging.info(":white_heavy_check_mark: Registered")
+ return True
else:
- bt_console.print(":satellite: Checking Balance...")
- block = subtensor.get_current_block()
- new_balance = subtensor.get_balance(
- wallet.coldkeypub.ss58_address, block=block
- )
-
- bt_console.print(
- "Balance:\n [blue]{}[/blue] :arrow_right: [green]{}[/green]".format(
- old_balance, new_balance
- )
- )
- is_registered = subtensor.is_hotkey_registered(
- netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address
- )
- if is_registered:
- bt_console.print(":white_heavy_check_mark: [green]Registered[/green]")
- return True
- else:
- # neuron not found, try again
- bt_console.print(
- ":cross_mark: [red]Unknown error. Neuron not found.[/red]"
- )
- return False
+ # neuron not found, try again
+ logging.error(":cross_mark: Unknown error. Neuron not found.")
+ return False
diff --git a/bittensor/core/extrinsics/root.py b/bittensor/core/extrinsics/root.py
index 1fd7e7b26e..129e852777 100644
--- a/bittensor/core/extrinsics/root.py
+++ b/bittensor/core/extrinsics/root.py
@@ -7,7 +7,7 @@
from retry import retry
from rich.prompt import Confirm
-from bittensor.core.settings import bt_console, version_as_int
+from bittensor.core.settings import version_as_int
from bittensor.utils import format_error_message, weight_utils
from bittensor.utils.btlogging import logging
from bittensor.utils.networking import ensure_connected
@@ -80,8 +80,8 @@ def root_register_extrinsic(
try:
wallet.unlock_coldkey()
except KeyFileError:
- bt_console.print(
- ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]"
+ logging.error(
+ "Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid."
)
return False
@@ -89,8 +89,8 @@ def root_register_extrinsic(
netuid=0, hotkey_ss58=wallet.hotkey.ss58_address
)
if is_registered:
- bt_console.print(
- ":white_heavy_check_mark: [green]Already registered on root network.[/green]"
+ logging.info(
+ ":white_heavy_check_mark: Already registered on root network."
)
return True
@@ -99,30 +99,28 @@ def root_register_extrinsic(
if not Confirm.ask("Register to root network?"):
return False
- with bt_console.status(":satellite: Registering to root network..."):
- success, err_msg = _do_root_register(
- wallet=wallet,
- wait_for_inclusion=wait_for_inclusion,
- wait_for_finalization=wait_for_finalization,
- )
+ logging.info(":satellite: Registering to root network...")
+ success, err_msg = _do_root_register(
+ wallet=wallet,
+ wait_for_inclusion=wait_for_inclusion,
+ wait_for_finalization=wait_for_finalization,
+ )
- if not success:
- bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
- time.sleep(0.5)
+ if not success:
+ logging.error(f":cross_mark: Failed: {err_msg}")
+ time.sleep(0.5)
- # Successful registration, final check for neuron and pubkey
+ # Successful registration, final check for neuron and pubkey
+ else:
+ is_registered = subtensor.is_hotkey_registered(
+ netuid=0, hotkey_ss58=wallet.hotkey.ss58_address
+ )
+ if is_registered:
+ logging.success(":white_heavy_check_mark: Registered")
+ return True
else:
- is_registered = subtensor.is_hotkey_registered(
- netuid=0, hotkey_ss58=wallet.hotkey.ss58_address
- )
- if is_registered:
- bt_console.print(":white_heavy_check_mark: [green]Registered[/green]")
- return True
- else:
- # neuron not found, try again
- bt_console.print(
- ":cross_mark: [red]Unknown error. Neuron not found.[/red]"
- )
+ # neuron not found, try again
+ logging.error(":cross_mark: Unknown error. Neuron not found.")
@ensure_connected
@@ -222,8 +220,8 @@ def set_root_weights_extrinsic(
try:
wallet.unlock_coldkey()
except KeyFileError:
- bt_console.print(
- ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]"
+ logging.error(
+ ":cross_mark: Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid."
)
return False
@@ -252,8 +250,8 @@ def set_root_weights_extrinsic(
formatted_weights = weight_utils.normalize_max_weight(
x=weights, limit=max_weight_limit
)
- bt_console.print(
- f"\nRaw Weights -> Normalized weights: \n\t{weights} -> \n\t{formatted_weights}\n"
+ logging.info(
+ f"Raw Weights -> Normalized weights: {weights} -> {formatted_weights}"
)
# Ask before moving on.
@@ -265,46 +263,36 @@ def set_root_weights_extrinsic(
):
return False
- with bt_console.status(
- ":satellite: Setting root weights on [white]{}[/white] ...".format(
- subtensor.network
+ logging.info(
+ f":satellite: Setting root weights on {subtensor.network} ..."
+ )
+ try:
+ weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit(
+ netuids, weights
)
- ):
- try:
- weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit(
- netuids, weights
- )
- success, error_message = _do_set_root_weights(
- wallet=wallet,
- netuid=0,
- uids=weight_uids,
- vals=weight_vals,
- version_key=version_key,
- wait_for_finalization=wait_for_finalization,
- wait_for_inclusion=wait_for_inclusion,
- )
+ success, error_message = _do_set_root_weights(
+ wallet=wallet,
+ netuid=0,
+ uids=weight_uids,
+ vals=weight_vals,
+ version_key=version_key,
+ wait_for_finalization=wait_for_finalization,
+ wait_for_inclusion=wait_for_inclusion,
+ )
+
+ if not wait_for_finalization and not wait_for_inclusion:
+ return True
- bt_console.print(success, error_message)
-
- if not wait_for_finalization and not wait_for_inclusion:
- return True
-
- if success is True:
- bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]")
- logging.success(
- prefix="Set weights",
- suffix="Finalized: " + str(success),
- )
- return True
- else:
- bt_console.print(f":cross_mark: [red]Failed[/red]: {error_message}")
- logging.warning(
- prefix="Set weights",
- suffix="Failed: " + str(error_message),
- )
- return False
-
- except Exception as e:
- bt_console.print(":cross_mark: [red]Failed[/red]: error:{}".format(e))
- logging.warning(prefix="Set weights", suffix="Failed: " + str(e))
+ if success is True:
+ logging.info(":white_heavy_check_mark: Finalized")
+ logging.success(f"Set weights {str(success)}")
+ return True
+ else:
+ logging.error(
+ f":cross_mark: Failed set weights. {str(error_message)}"
+ )
return False
+
+ except Exception as e:
+ logging.error(f":cross_mark: Failed set weights. {str(e)}")
+ return False
diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py
index 490f9c268e..ac712cd8cb 100644
--- a/bittensor/core/extrinsics/serving.py
+++ b/bittensor/core/extrinsics/serving.py
@@ -23,7 +23,7 @@
from bittensor.core.errors import MetadataError
from bittensor.core.extrinsics.utils import submit_extrinsic
-from bittensor.core.settings import version_as_int, bt_console
+from bittensor.core.settings import version_as_int
from bittensor.utils import format_error_message, networking as net
from bittensor.utils.btlogging import logging
from bittensor.utils.networking import ensure_connected
@@ -219,10 +219,9 @@ def serve_axon_extrinsic(
if axon.external_ip is None:
try:
external_ip = net.get_external_ip()
- bt_console.print(
- f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]"
+ logging.success(
+ f":white_heavy_check_mark: Found external ip: {external_ip}"
)
- logging.success(prefix="External IP", suffix=f"{external_ip}")
except Exception as e:
raise RuntimeError(
f"Unable to attain your external ip. Check your internet connection. error: {e}"
diff --git a/bittensor/core/extrinsics/set_weights.py b/bittensor/core/extrinsics/set_weights.py
index 7680061c5b..98f4c16917 100644
--- a/bittensor/core/extrinsics/set_weights.py
+++ b/bittensor/core/extrinsics/set_weights.py
@@ -24,7 +24,7 @@
from rich.prompt import Confirm
from bittensor.core.extrinsics.utils import submit_extrinsic
-from bittensor.core.settings import bt_console, version_as_int
+from bittensor.core.settings import version_as_int
from bittensor.utils import format_error_message, weight_utils
from bittensor.utils.btlogging import logging
from bittensor.utils.networking import ensure_connected
@@ -157,38 +157,33 @@ def set_weights_extrinsic(
):
return False, "Prompt refused."
- with bt_console.status(
- f":satellite: Setting weights on [white]{subtensor.network}[/white] ..."
- ):
- try:
- success, error_message = do_set_weights(
- self=subtensor,
- wallet=wallet,
- netuid=netuid,
- uids=weight_uids,
- vals=weight_vals,
- version_key=version_key,
- wait_for_finalization=wait_for_finalization,
- wait_for_inclusion=wait_for_inclusion,
- )
-
- if not wait_for_finalization and not wait_for_inclusion:
- return True, "Not waiting for finalization or inclusion."
-
- if success is True:
- bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]")
- logging.success(
- msg=str(success),
- prefix="Set weights",
- suffix="Finalized: ",
- )
- return True, "Successfully set weights and Finalized."
- else:
- error_message = format_error_message(error_message)
- logging.error(error_message)
- return False, error_message
-
- except Exception as e:
- bt_console.print(f":cross_mark: [red]Failed[/red]: error:{e}")
- logging.debug(str(e))
- return False, str(e)
+ logging.info(
+ f":satellite: Setting weights on {subtensor.network} ..."
+ )
+ try:
+ success, error_message = do_set_weights(
+ self=subtensor,
+ wallet=wallet,
+ netuid=netuid,
+ uids=weight_uids,
+ vals=weight_vals,
+ version_key=version_key,
+ wait_for_finalization=wait_for_finalization,
+ wait_for_inclusion=wait_for_inclusion,
+ )
+
+ if not wait_for_finalization and not wait_for_inclusion:
+ return True, "Not waiting for finalization or inclusion."
+
+ if success is True:
+ logging.success(f"Finalized! Set weights: {str(success)}")
+ return True, "Successfully set weights and Finalized."
+ else:
+ error_message = format_error_message(error_message)
+ logging.error(error_message)
+ return False, error_message
+
+ except Exception as e:
+ logging.error(f":cross_mark: Failed.: Error: {e}")
+ logging.debug(str(e))
+ return False, str(e)
diff --git a/bittensor/core/extrinsics/transfer.py b/bittensor/core/extrinsics/transfer.py
index 896fecbf96..aaa2795583 100644
--- a/bittensor/core/extrinsics/transfer.py
+++ b/bittensor/core/extrinsics/transfer.py
@@ -21,13 +21,14 @@
from rich.prompt import Confirm
from bittensor.core.extrinsics.utils import submit_extrinsic
-from bittensor.core.settings import bt_console, NETWORK_EXPLORER_MAP
+from bittensor.core.settings import NETWORK_EXPLORER_MAP
from bittensor.utils import (
get_explorer_url_for_network,
format_error_message,
is_valid_bittensor_address_or_public_key,
)
from bittensor.utils.balance import Balance
+from bittensor.utils.btlogging import logging
from bittensor.utils.networking import ensure_connected
# For annotation purposes
@@ -121,9 +122,7 @@ def transfer_extrinsic(
"""
# Validate destination address.
if not is_valid_bittensor_address_or_public_key(dest):
- bt_console.print(
- f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {dest}[/bold white]"
- )
+ logging.error(f"Invalid destination address: {dest}")
return False
if isinstance(dest, bytes):
@@ -140,15 +139,15 @@ def transfer_extrinsic(
transfer_balance = amount
# Check balance.
- with bt_console.status(":satellite: Checking Balance..."):
- account_balance = subtensor.get_balance(wallet.coldkey.ss58_address)
- # check existential deposit.
- existential_deposit = subtensor.get_existential_deposit()
-
- with bt_console.status(":satellite: Transferring..."):
- fee = subtensor.get_transfer_fee(
- wallet=wallet, dest=dest, value=transfer_balance.rao
- )
+ logging.info(":satellite: Checking Balance...")
+ account_balance = subtensor.get_balance(wallet.coldkey.ss58_address)
+ # check existential deposit.
+ existential_deposit = subtensor.get_existential_deposit()
+
+ logging.info(":satellite: Transferring...")
+ fee = subtensor.get_transfer_fee(
+ wallet=wallet, dest=dest, value=transfer_balance.rao
+ )
if not keep_alive:
# Check if the transfer should keep_alive the account
@@ -156,12 +155,10 @@ def transfer_extrinsic(
# Check if we have enough balance.
if account_balance < (transfer_balance + fee + existential_deposit):
- bt_console.print(
- ":cross_mark: [red]Not enough balance[/red]:[bold white]\n"
- f" balance: {account_balance}\n"
- f" amount: {transfer_balance}\n"
- f" for fee: {fee}[/bold white]"
- )
+ logging.error(":cross_mark: Not enough balance:")
+ logging.info(f"\t\tBalance: \t{account_balance}")
+ logging.info(f"\t\tAmount: \t{transfer_balance}")
+ logging.info(f"\t\tFor fee: \t{fee}")
return False
# Ask before moving on.
@@ -175,41 +172,41 @@ def transfer_extrinsic(
):
return False
- with bt_console.status(":satellite: Transferring..."):
- success, block_hash, error_message = do_transfer(
- self=subtensor,
- wallet=wallet,
- dest=dest,
- transfer_balance=transfer_balance,
- wait_for_finalization=wait_for_finalization,
- wait_for_inclusion=wait_for_inclusion,
- )
+ logging.info(":satellite: Transferring...")
+ success, block_hash, error_message = do_transfer(
+ self=subtensor,
+ wallet=wallet,
+ dest=dest,
+ transfer_balance=transfer_balance,
+ wait_for_finalization=wait_for_finalization,
+ wait_for_inclusion=wait_for_inclusion,
+ )
- if success:
- bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]")
- bt_console.print(f"[green]Block Hash: {block_hash}[/green]")
+ if success:
+ logging.success(":white_heavy_check_mark: Finalized")
+ logging.info(f"Block Hash: {block_hash}")
- explorer_urls = get_explorer_url_for_network(
- subtensor.network, block_hash, NETWORK_EXPLORER_MAP
+ explorer_urls = get_explorer_url_for_network(
+ subtensor.network, block_hash, NETWORK_EXPLORER_MAP
+ )
+ if explorer_urls != {} and explorer_urls:
+ logging.info(
+ f"Opentensor Explorer Link: {explorer_urls.get('opentensor')}"
)
- if explorer_urls != {} and explorer_urls:
- bt_console.print(
- f"[green]Opentensor Explorer Link: {explorer_urls.get('opentensor')}[/green]"
- )
- bt_console.print(
- f"[green]Taostats Explorer Link: {explorer_urls.get('taostats')}[/green]"
- )
- else:
- bt_console.print(
- f":cross_mark: [red]Failed[/red]: {format_error_message(error_message)}"
+ logging.info(
+ f"Taostats Explorer Link: {explorer_urls.get('taostats')}"
)
+ else:
+ logging.error(
+ f":cross_mark: Failed: {format_error_message(error_message)}"
+ )
if success:
- with bt_console.status(":satellite: Checking Balance..."):
- new_balance = subtensor.get_balance(wallet.coldkey.ss58_address)
- bt_console.print(
- f"Balance:\n [blue]{account_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
- )
- return True
+ logging.info(":satellite: Checking Balance...")
+ new_balance = subtensor.get_balance(wallet.coldkey.ss58_address)
+ logging.success(
+ f"Balance: {account_balance} :arrow_right: {new_balance}"
+ )
+ return True
return False
diff --git a/bittensor/core/metagraph.py b/bittensor/core/metagraph.py
index 208eaa6b9f..75e8d947c9 100644
--- a/bittensor/core/metagraph.py
+++ b/bittensor/core/metagraph.py
@@ -1249,12 +1249,11 @@ def load_from_path(self, dir_path: str) -> "Metagraph":
with open(graph_filename, "rb") as graph_file:
state_dict = pickle.load(graph_file)
except pickle.UnpicklingError:
- settings.bt_console.print(
+ logging.info(
"Unable to load file. Attempting to restore metagraph using torch."
)
- settings.bt_console.print(
- ":warning:[yellow]Warning:[/yellow] This functionality exists to load "
- "metagraph state from legacy saves, but will not be supported in the future."
+ logging.warning(
+ ":warning: This functionality exists to load metagraph state from legacy saves, but will not be supported in the future."
)
try:
import torch as real_torch
@@ -1264,7 +1263,7 @@ def load_from_path(self, dir_path: str) -> "Metagraph":
state_dict[key] = state_dict[key].detach().numpy()
del real_torch
except (RuntimeError, ImportError):
- settings.bt_console.print("Unable to load file. It may be corrupted.")
+ logging.error("Unable to load file. It may be corrupted.")
raise
self.n = state_dict["n"]
diff --git a/bittensor/core/settings.py b/bittensor/core/settings.py
index fe2a707b4e..8413b5329f 100644
--- a/bittensor/core/settings.py
+++ b/bittensor/core/settings.py
@@ -23,36 +23,6 @@
from pathlib import Path
from munch import munchify
-from rich.console import Console
-from rich.traceback import install
-
-# Rich console.
-__console__ = Console()
-__use_console__ = True
-
-# Remove overdue locals in debug training.
-install(show_locals=False)
-
-
-def turn_console_off():
- global __use_console__
- global __console__
- from io import StringIO
-
- __use_console__ = False
- __console__ = Console(file=StringIO(), stderr=False)
-
-
-def turn_console_on():
- global __use_console__
- global __console__
- __use_console__ = True
- __console__ = Console()
-
-
-turn_console_off()
-
-bt_console = __console__
HOME_DIR = Path.home()
diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py
index 3ca0dc146d..3e3c61b017 100644
--- a/bittensor/core/subtensor.py
+++ b/bittensor/core/subtensor.py
@@ -1735,9 +1735,7 @@ def get_transfer_fee(
call=call, keypair=wallet.coldkeypub
)
except Exception as e:
- settings.bt_console.print(
- f":cross_mark: [red]Failed to get payment info[/red]:[bold white]\n {e}[/bold white]"
- )
+ logging.error(f"Failed to get payment info. {e}")
payment_info = {"partialFee": int(2e7)} # assume 0.02 Tao
fee = Balance.from_rao(payment_info["partialFee"])
diff --git a/bittensor/utils/btlogging/format.py b/bittensor/utils/btlogging/format.py
index 1aa505c82c..9e279a3b26 100644
--- a/bittensor/utils/btlogging/format.py
+++ b/bittensor/utils/btlogging/format.py
@@ -54,6 +54,8 @@ def _success(self, message: str, *args, **kws):
":white_heavy_check_mark:": "✅",
":cross_mark:": "❌",
":satellite:": "🛰️",
+ ":warning:": "⚠️",
+ ":arrow_right:": "➡️",
}
@@ -64,6 +66,8 @@ def _success(self, message: str, *args, **kws):
"": Style.RESET_ALL,
"": Fore.GREEN,
"": Style.RESET_ALL,
+ "": Fore.MAGENTA,
+ "": Style.RESET_ALL,
}
diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py
index abc4758bf8..66d7cc7595 100644
--- a/bittensor/utils/btlogging/loggingmachine.py
+++ b/bittensor/utils/btlogging/loggingmachine.py
@@ -49,7 +49,8 @@
def _concat_message(msg="", prefix="", suffix=""):
"""Concatenates a message with optional prefix and suffix."""
- msg = f"{f'{prefix} - ' if prefix else ''}{msg}{f' - {suffix}' if suffix else ''}"
+ empty_pref_suf = [None, ""]
+ msg = f"{f'{prefix} - ' if prefix not in empty_pref_suf else ''}{msg}{f' - {suffix}' if suffix not in empty_pref_suf else ''}"
return msg
@@ -443,27 +444,27 @@ def info(self, msg="", prefix="", suffix="", *args, **kwargs):
def success(self, msg="", prefix="", suffix="", *args, **kwargs):
"""Wraps success message with prefix and suffix."""
- msg = f"{prefix} - {msg} - {suffix}"
+ msg = _concat_message(msg, prefix, suffix)
self._logger.success(msg, *args, **kwargs)
def warning(self, msg="", prefix="", suffix="", *args, **kwargs):
"""Wraps warning message with prefix and suffix."""
- msg = f"{prefix} - {msg} - {suffix}"
+ msg = _concat_message(msg, prefix, suffix)
self._logger.warning(msg, *args, **kwargs)
def error(self, msg="", prefix="", suffix="", *args, **kwargs):
"""Wraps error message with prefix and suffix."""
- msg = f"{prefix} - {msg} - {suffix}"
+ msg = _concat_message(msg, prefix, suffix)
self._logger.error(msg, *args, **kwargs)
def critical(self, msg="", prefix="", suffix="", *args, **kwargs):
"""Wraps critical message with prefix and suffix."""
- msg = f"{prefix} - {msg} - {suffix}"
+ msg = _concat_message(msg, prefix, suffix)
self._logger.critical(msg, *args, **kwargs)
def exception(self, msg="", prefix="", suffix="", *args, **kwargs):
"""Wraps exception message with prefix and suffix."""
- msg = f"{prefix} - {msg} - {suffix}"
+ msg = _concat_message(msg, prefix, suffix)
self._logger.exception(msg, *args, **kwargs)
def on(self):
diff --git a/bittensor/utils/registration.py b/bittensor/utils/registration.py
index 46c39d3d40..4dd6d8ec67 100644
--- a/bittensor/utils/registration.py
+++ b/bittensor/utils/registration.py
@@ -30,12 +30,12 @@
from queue import Empty, Full
from typing import Any, Callable, Optional, Union, TYPE_CHECKING
-import backoff
import numpy
from Crypto.Hash import keccak
+from retry import retry
from rich import console as rich_console, status as rich_status
+from rich.console import Console
-from bittensor.core.settings import bt_console
from bittensor.utils.btlogging import logging
from bittensor.utils.formatting import get_human_readable, millify
from bittensor.utils.register_cuda import solve_cuda
@@ -488,12 +488,16 @@ class RegistrationStatistics:
class RegistrationStatisticsLogger:
"""Logs statistics for a registration."""
- console: rich_console.Console
status: Optional[rich_status.Status]
def __init__(
- self, console: rich_console.Console, output_in_place: bool = True
+ self,
+ console: Optional[rich_console.Console] = None,
+ output_in_place: bool = True,
) -> None:
+ if console is None:
+ console = Console()
+
self.console = console
if output_in_place:
@@ -649,7 +653,7 @@ def _solve_for_difficulty_fast(
start_time_perpetual = time.time()
- logger = RegistrationStatisticsLogger(bt_console, output_in_place)
+ logger = RegistrationStatisticsLogger(output_in_place=output_in_place)
logger.start()
solution = None
@@ -735,7 +739,7 @@ def _solve_for_difficulty_fast(
return solution
-@backoff.on_exception(backoff.constant, Exception, interval=1, max_tries=3)
+@retry(Exception, tries=3, delay=1)
def _get_block_with_retry(
subtensor: "Subtensor", netuid: int
) -> tuple[int, int, bytes]:
@@ -953,7 +957,7 @@ def _solve_for_difficulty_fast_cuda(
start_time_perpetual = time.time()
- logger = RegistrationStatisticsLogger(bt_console, output_in_place)
+ logger = RegistrationStatisticsLogger(output_in_place=output_in_place)
logger.start()
hash_rates = [0] * n_samples # The last n true hash_rates
diff --git a/requirements/prod.txt b/requirements/prod.txt
index bed65e9d2e..17c73f6f25 100644
--- a/requirements/prod.txt
+++ b/requirements/prod.txt
@@ -1,7 +1,6 @@
wheel
setuptools~=70.0.0
aiohttp~=3.9
-backoff
bittensor-cli
bt-decode
colorama~=0.4.6
diff --git a/scripts/environments/apple_m1_environment.yml b/scripts/environments/apple_m1_environment.yml
index 25824aa64e..7d949c7e4e 100644
--- a/scripts/environments/apple_m1_environment.yml
+++ b/scripts/environments/apple_m1_environment.yml
@@ -126,7 +126,6 @@ dependencies:
- argparse==1.4.0
- arrow==1.2.3
- async-timeout==4.0.2
- - backoff==2.1.0
- blinker==1.6.2
- cachetools==4.2.4
- certifi==2024.2.2
diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py
index f876d249bd..3c6badb91c 100644
--- a/tests/helpers/__init__.py
+++ b/tests/helpers/__init__.py
@@ -18,7 +18,6 @@
import os
from .helpers import ( # noqa: F401
CLOSE_IN_VALUE,
- MockConsole,
__mock_wallet_factory__,
)
from bittensor_wallet.mock.wallet_mock import ( # noqa: F401
diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py
index 417bd643b3..41109ee5e6 100644
--- a/tests/helpers/helpers.py
+++ b/tests/helpers/helpers.py
@@ -22,14 +22,11 @@
from bittensor_wallet.mock.wallet_mock import get_mock_hotkey
from bittensor_wallet.mock.wallet_mock import get_mock_wallet
-from rich.console import Console
-from rich.text import Text
-
from bittensor.utils.balance import Balance
from bittensor.core.chain_data import AxonInfo, NeuronInfo, PrometheusInfo
-def __mock_wallet_factory__(*args, **kwargs) -> _MockWallet:
+def __mock_wallet_factory__(*_, **__) -> _MockWallet:
"""Returns a mock wallet object."""
mock_wallet = get_mock_wallet()
@@ -118,53 +115,3 @@ def get_mock_neuron_by_uid(uid: int, **kwargs) -> NeuronInfo:
return get_mock_neuron(
uid=uid, hotkey=get_mock_hotkey(uid), coldkey=get_mock_coldkey(uid), **kwargs
)
-
-
-class MockStatus:
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_value, traceback):
- pass
-
- def start(self):
- pass
-
- def stop(self):
- pass
-
- def update(self, *args, **kwargs):
- MockConsole().print(*args, **kwargs)
-
-
-class MockConsole:
- """
- Mocks the console object for status and print.
- Captures the last print output as a string.
- """
-
- captured_print = None
-
- def status(self, *args, **kwargs):
- return MockStatus()
-
- def print(self, *args, **kwargs):
- console = Console(
- width=1000, no_color=True, markup=False
- ) # set width to 1000 to avoid truncation
- console.begin_capture()
- console.print(*args, **kwargs)
- self.captured_print = console.end_capture()
-
- def clear(self, *args, **kwargs):
- pass
-
- @staticmethod
- def remove_rich_syntax(text: str) -> str:
- """
- Removes rich syntax from the given text.
- Removes markup and ansi syntax.
- """
- output_no_syntax = Text.from_ansi(Text.from_markup(text).plain).plain
-
- return output_no_syntax
diff --git a/tests/integration_tests/test_subtensor_integration.py b/tests/integration_tests/test_subtensor_integration.py
index 552e5ab993..bacb340f2c 100644
--- a/tests/integration_tests/test_subtensor_integration.py
+++ b/tests/integration_tests/test_subtensor_integration.py
@@ -30,7 +30,6 @@
from bittensor.utils.mock import MockSubtensor
from tests.helpers import (
get_mock_coldkey,
- MockConsole,
get_mock_keypair,
get_mock_wallet,
)
@@ -52,12 +51,6 @@ def setUp(self):
@classmethod
def setUpClass(cls) -> None:
- # mock rich console status
- mock_console = MockConsole()
- cls._mock_console_patcher = patch(
- "bittensor.core.settings.bt_console", mock_console
- )
- cls._mock_console_patcher.start()
# Keeps the same mock network for all tests. This stops the network from being re-setup for each test.
cls._mock_subtensor = MockSubtensor()
cls._do_setup_subnet()
@@ -69,10 +62,6 @@ def _do_setup_subnet(cls):
# Setup the mock subnet 3
cls._mock_subtensor.create_subnet(netuid=3)
- @classmethod
- def tearDownClass(cls) -> None:
- cls._mock_console_patcher.stop()
-
def test_network_overrides(self):
"""Tests that the network overrides the chain_endpoint."""
# Argument importance: chain_endpoint (arg) > network (arg) > config.subtensor.chain_endpoint > config.subtensor.network
@@ -284,15 +273,10 @@ def test_registration_multiprocessed_already_registered(self):
)
self.subtensor._do_pow_register = MagicMock(return_value=(True, None))
- with patch("bittensor.core.settings.bt_console") as mock_set_status:
- # Need to patch the console status to avoid opening a parallel live display
- mock_set_status.__enter__ = MagicMock(return_value=True)
- mock_set_status.__exit__ = MagicMock(return_value=True)
-
- # should return True
- assert self.subtensor.register(
- wallet=wallet, netuid=3, num_processes=3, update_interval=5
- )
+ # should return True
+ assert self.subtensor.register(
+ wallet=wallet, netuid=3, num_processes=3, update_interval=5
+ )
# calls until True and once again before exiting subtensor class
# This assertion is currently broken when difficulty is too low