From 36384f39605eb8ae110f187913882958cbc9e68d Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 3 Feb 2024 15:04:50 +0800 Subject: [PATCH 01/23] - rename classes wallet to Wallet, config to Config - optimize imports --- cybertensor/__init__.py | 7 ++- cybertensor/axon.py | 24 ++++---- cybertensor/cli.py | 15 ++--- cybertensor/commands/delegates.py | 33 +++++------ cybertensor/commands/inspect.py | 15 ++--- cybertensor/commands/list.py | 9 +-- cybertensor/commands/metagraph.py | 2 +- cybertensor/commands/network.py | 31 ++++++----- cybertensor/commands/overview.py | 17 +++--- cybertensor/commands/register.py | 20 ++++--- cybertensor/commands/root.py | 19 ++++--- cybertensor/commands/stake.py | 31 ++++++----- cybertensor/commands/transfer.py | 9 +-- cybertensor/commands/unstake.py | 17 +++--- cybertensor/commands/utils.py | 15 ++--- cybertensor/commands/wallets.py | 51 ++++++++--------- cybertensor/config.py | 22 ++++---- cybertensor/ctlogging.py | 13 +++-- cybertensor/cwtensor.py | 80 ++++++++++++++------------- cybertensor/dendrite.py | 15 ++--- cybertensor/keyfile.py | 4 +- cybertensor/messages/delegation.py | 14 ++--- cybertensor/messages/log_utilities.py | 8 +-- cybertensor/messages/network.py | 11 ++-- cybertensor/messages/prometheus.py | 10 ++-- cybertensor/messages/registration.py | 13 +++-- cybertensor/messages/root.py | 8 +-- cybertensor/messages/serving.py | 8 +-- cybertensor/messages/set_weights.py | 4 +- cybertensor/messages/staking.py | 15 ++--- cybertensor/messages/transfer.py | 5 +- cybertensor/messages/unstaking.py | 15 ++--- cybertensor/threadpool.py | 7 ++- cybertensor/utils/registration.py | 9 +-- cybertensor/wallet.py | 33 +++++------ 35 files changed, 320 insertions(+), 289 deletions(-) diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index 724bbac..b6e7f4c 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -195,12 +195,13 @@ def __init__( from .tensor import * from .axon import axon as axon from .dendrite import dendrite as dendrite +from .config import Config configs = [ axon.config(), - cybertensor.config(), + Config(), PriorityThreadPoolExecutor.config(), - wallet.config(), + Wallet.config(), logging.config(), ] -defaults = config.merge_all(configs) +defaults = Config.merge_all(configs) diff --git a/cybertensor/axon.py b/cybertensor/axon.py index df74730..7d746bc 100644 --- a/cybertensor/axon.py +++ b/cybertensor/axon.py @@ -40,7 +40,9 @@ from starlette.responses import Response import cybertensor -from cybertensor.keypair import Keypair +from .keypair import Keypair +from .wallet import Wallet +from .config import Config """ Create and init Axon, which services Forward and Backward requests from other neurons. """ @@ -167,8 +169,8 @@ def info(self) -> "cybertensor.AxonInfo": def __init__( self, - wallet: "cybertensor.wallet" = None, - config: Optional["cybertensor.config"] = None, + wallet: "Wallet" = None, + config: Optional["Config"] = None, port: Optional[int] = None, ip: Optional[str] = None, external_ip: Optional[str] = None, @@ -177,9 +179,9 @@ def __init__( ) -> "cybertensor.axon": r"""Creates a new cybertensor.Axon object from passed arguments. Args: - config (:obj:`Optional[cybertensor.config]`, `optional`): + config (:obj:`Optional[Config]`, `optional`): cybertensor.axon.config() - wallet (:obj:`Optional[cybertensor.wallet]`, `optional`): + wallet (:obj:`Optional[Wallet]`, `optional`): cybertensor wallet with hotkey and coldkeypub. port (:type:`Optional[int]`, `optional`): Binding port. @@ -213,7 +215,7 @@ def __init__( self.config = config # Get wallet or use default. - self.wallet = wallet or cybertensor.wallet() + self.wallet = wallet or Wallet() # Build axon objects. self.uuid = str(uuid.uuid1()) @@ -409,16 +411,16 @@ def attach( return self @classmethod - def config(cls) -> "cybertensor.config": + def config(cls) -> "Config": """ Parses command-line arguments to form a cybertensor configuration object. Returns: - cybertensor.config: Configuration object with settings from command-line arguments. + Config: Configuration object with settings from command-line arguments. """ parser = argparse.ArgumentParser() axon.add_args(parser) # Add specific axon-related arguments - return cybertensor.config(parser, args=[]) + return Config(parser, args=[]) @classmethod def help(cls): @@ -543,12 +545,12 @@ async def some_endpoint(body_dict: dict = Depends(verify_body_integrity)): return body_dict @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): """ This method checks the configuration for the axon's port and wallet. Args: - config (cybertensor.config): The config object holding axon settings. + config (Config): The config object holding axon settings. Raises: AssertionError: If the axon or external ports are not in range [1024, 65535] diff --git a/cybertensor/cli.py b/cybertensor/cli.py index 65079f1..a5f79b9 100644 --- a/cybertensor/cli.py +++ b/cybertensor/cli.py @@ -23,6 +23,7 @@ import cybertensor from .commands import * from .commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand +from .config import Config # Create a console instance for CLI display. console = cybertensor.__console__ @@ -139,14 +140,14 @@ class cli: def __init__( self, - config: Optional["cybertensor.config"] = None, + config: Optional["Config"] = None, args: Optional[List[str]] = None, ): """ Initializes a cybertensor.CLI object. Args: - config (cybertensor.config, optional): The configuration settings for the CLI. + config (Config, optional): The configuration settings for the CLI. args (List[str], optional): List of command line arguments. """ # Turns on console for cli. @@ -214,7 +215,7 @@ def __create_parser__() -> "argparse.ArgumentParser": return parser @staticmethod - def create_config(args: List[str]) -> "cybertensor.config": + def create_config(args: List[str]) -> "Config": """ From the argument parser, add config to cybertensor.executor and local config @@ -222,7 +223,7 @@ def create_config(args: List[str]) -> "cybertensor.config": args (List[str]): List of command line arguments. Returns: - cybertensor.config: The configuration object for Cybertensor CLI. + Config: The configuration object for Cybertensor CLI. """ parser = cli.__create_parser__() @@ -231,15 +232,15 @@ def create_config(args: List[str]) -> "cybertensor.config": parser.print_help() sys.exit() - return cybertensor.config(parser, args=args) + return Config(parser, args=args) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): """ Checks if the essential configuration exists under different command Args: - config (cybertensor.config): The configuration settings for the CLI. + config (Config): The configuration settings for the CLI. """ # Check if command exists, if so, run the corresponding check_config. # If command doesn't exist, inform user and exit the program. diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py index 8c9d2d0..3d70a2b 100644 --- a/cybertensor/commands/delegates.py +++ b/cybertensor/commands/delegates.py @@ -29,13 +29,14 @@ import cybertensor from . import defaults +from ..wallet import Wallet from .utils import DelegatesDetails -def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: try: wallet_names = next(os.walk(os.path.expanduser(path)))[1] - return [cybertensor.wallet(path=path, name=name) for name in wallet_names] + return [Wallet(path=path, name=name) for name in wallet_names] except StopIteration: # No wallet files found. wallets = [] @@ -48,7 +49,7 @@ def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: # Uses rich console to pretty print a table of delegates. def show_delegates( # TODO revisit - config: "cybertensor.config", + config: "Config", delegates: List["cybertensor.DelegateInfo"], prev_delegates: Optional[List["cybertensor.DelegateInfo"]], width: Optional[int] = None, @@ -257,7 +258,7 @@ class DelegateStakeCommand: def run(cli): """Delegates stake to a chain delegate.""" config = cli.config.copy() - wallet = cybertensor.wallet(config=config) + wallet = Wallet(config=config) cwtensor = cybertensor.cwtensor(config=config) cwtensor.delegate( wallet=wallet, @@ -286,11 +287,11 @@ def add_args(parser: argparse.ArgumentParser): delegate_stake_parser.add_argument( "--amount", dest="amount", type=float, required=False ) - cybertensor.wallet.add_args(delegate_stake_parser) + Wallet.add_args(delegate_stake_parser) cybertensor.cwtensor.add_args(delegate_stake_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.get("delegatekey"): # Check for delegates. with cybertensor.__console__.status(":satellite: Loading delegates..."): @@ -381,7 +382,7 @@ class DelegateUnstakeCommand: def run(cli): """Undelegates stake from a chain delegate.""" config = cli.config.copy() - wallet = cybertensor.wallet(config=config) + wallet = Wallet(config=config) cwtensor = cybertensor.cwtensor(config=config) cwtensor.undelegate( wallet=wallet, @@ -410,11 +411,11 @@ def add_args(parser: argparse.ArgumentParser): undelegate_stake_parser.add_argument( "--amount", dest="amount", type=float, required=False ) - cybertensor.wallet.add_args(undelegate_stake_parser) + Wallet.add_args(undelegate_stake_parser) cybertensor.cwtensor.add_args(undelegate_stake_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -542,7 +543,7 @@ def add_args(parser: argparse.ArgumentParser): cybertensor.cwtensor.add_args(list_delegates_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): pass @@ -580,7 +581,7 @@ class NominateCommand: @staticmethod def run(cli): r"""Nominate wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) # Unlock the wallet. @@ -624,11 +625,11 @@ def add_args(parser: argparse.ArgumentParser): nominate_parser = parser.add_parser( "nominate", help="""Become a delegate on the network""" ) - cybertensor.wallet.add_args(nominate_parser) + Wallet.add_args(nominate_parser) cybertensor.cwtensor.add_args(nominate_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -687,7 +688,7 @@ def run(cli): if config.get("all", d=None) is True: wallets = _get_coldkey_wallets_for_path(config.wallet.path) else: - wallets = [cybertensor.wallet(config=config)] + wallets = [Wallet(config=config)] cwtensor = cybertensor.cwtensor(config=config) table = Table(show_footer=True, pad_edge=False, box=None, expand=True) @@ -829,11 +830,11 @@ def add_args(parser: argparse.ArgumentParser): help="""Check all coldkey wallets.""", default=False, ) - cybertensor.wallet.add_args(delegate_stake_parser) + Wallet.add_args(delegate_stake_parser) cybertensor.cwtensor.add_args(delegate_stake_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if ( not config.get("all", d=None) and not config.is_set("wallet.name") diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py index e01972b..0798222 100644 --- a/cybertensor/commands/inspect.py +++ b/cybertensor/commands/inspect.py @@ -27,21 +27,22 @@ import cybertensor from . import defaults from .utils import get_delegates_details, DelegatesDetails +from ..wallet import Wallet console = cybertensor.__console__ -def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: try: wallet_names = next(os.walk(os.path.expanduser(path)))[1] - return [cybertensor.wallet(path=path, name=name) for name in wallet_names] + return [Wallet(path=path, name=name) for name in wallet_names] except StopIteration: # No wallet files found. wallets = [] return wallets -def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: +def _get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]: hotkey_wallets = [] hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys" try: @@ -50,7 +51,7 @@ def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: hotkey_files = [] for hotkey_file_name in hotkey_files: try: - hotkey_for_name = cybertensor.wallet( + hotkey_for_name = Wallet( path=wallet.path, name=wallet.name, hotkey=hotkey_file_name ) if ( @@ -110,7 +111,7 @@ def run(cli) -> None: if cli.config.get("all", d=False) is True: wallets = _get_coldkey_wallets_for_path(cli.config.wallet.path) else: - wallets = [cybertensor.wallet(config=cli.config)] + wallets = [Wallet(config=cli.config)] cwtensor = cybertensor.cwtensor(config=cli.config) netuids = cwtensor.get_all_subnet_netuids() @@ -217,7 +218,7 @@ def run(cli) -> None: cybertensor.__console__.print(table) @staticmethod - def check_config(config: "cybertensor.config") -> None: + def check_config(config: "Config") -> None: if ( not config.get("all", d=None) and not config.is_set("wallet.name") @@ -238,5 +239,5 @@ def add_args(parser: argparse.ArgumentParser) -> None: default=False, ) - cybertensor.wallet.add_args(inspect_parser) + Wallet.add_args(inspect_parser) cybertensor.cwtensor.add_args(inspect_parser) diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py index b8d2ea8..2a2a13b 100644 --- a/cybertensor/commands/list.py +++ b/cybertensor/commands/list.py @@ -23,6 +23,7 @@ from rich.tree import Tree import cybertensor +from ..wallet import Wallet console = cybertensor.__console__ @@ -64,7 +65,7 @@ def run(cli): root = Tree("Wallets") for w_name in wallets: - wallet_for_name = cybertensor.wallet(path=cli.config.wallet.path, name=w_name) + wallet_for_name = Wallet(path=cli.config.wallet.path, name=w_name) try: if ( wallet_for_name.coldkeypub_file.exists_on_device() @@ -84,7 +85,7 @@ def run(cli): hotkeys = next(os.walk(os.path.expanduser(hotkeys_path))) if len(hotkeys) > 1: for h_name in hotkeys[2]: - hotkey_for_name = cybertensor.wallet( + hotkey_for_name = Wallet( path=cli.config.wallet.path, name=w_name, hotkey=h_name ) try: @@ -108,11 +109,11 @@ def run(cli): print(root) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): pass @staticmethod def add_args(parser: argparse.ArgumentParser): list_parser = parser.add_parser("list", help="""List wallets""") - cybertensor.wallet.add_args(list_parser) + Wallet.add_args(list_parser) cybertensor.cwtensor.add_args(list_parser) diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py index a4583db..10c2b13 100644 --- a/cybertensor/commands/metagraph.py +++ b/cybertensor/commands/metagraph.py @@ -233,7 +233,7 @@ def run(cli): console.print(table) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): check_netuid_set(config, cwtensor=cybertensor.cwtensor(config=config)) @staticmethod diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py index 733decc..e6407a5 100644 --- a/cybertensor/commands/network.py +++ b/cybertensor/commands/network.py @@ -27,6 +27,7 @@ import cybertensor from . import defaults +from ..wallet import Wallet from .utils import DelegatesDetails, check_netuid_set console = cybertensor.__console__ @@ -70,7 +71,7 @@ class RegisterSubnetworkCommand: def run(cli): r"""Register a subnetwork""" config = cli.config.copy() - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=config) # Call register command. cwtensor.register_subnetwork( @@ -79,7 +80,7 @@ def run(cli): ) @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -91,7 +92,7 @@ def add_args(cls, parser: argparse.ArgumentParser): help="""Create a new cybertensor subnetwork on this chain.""", ) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) class SubnetLockCostCommand: @@ -137,7 +138,7 @@ def run(cli): ) @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): pass @classmethod @@ -247,7 +248,7 @@ def run(cli): cybertensor.__console__.print(table) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): pass @staticmethod @@ -294,7 +295,7 @@ class SubnetSudoCommand: def run(cli): r"""Set subnet hyperparameters.""" config = cli.config.copy() - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=config) print("\n") SubnetHyperparamsCommand.run(cli) @@ -314,7 +315,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -331,7 +332,7 @@ def add_args(parser: argparse.ArgumentParser): parser.add_argument("--param", dest="param", type=str, required=False) parser.add_argument("--value", dest="value", type=str, required=False) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @@ -402,7 +403,7 @@ def run(cli): cybertensor.__console__.print(table) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("netuid") and not config.no_prompt: check_netuid_set(config, cybertensor.cwtensor(config=config)) @@ -483,7 +484,7 @@ def run(cli): cybertensor.__console__.print(table) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("netuid") and not config.no_prompt: check_netuid_set(config, cybertensor.cwtensor(config=config)) @@ -510,7 +511,7 @@ class SubnetSetWeightsCommand: @staticmethod def run(cli): r"""Set weights for subnetwork.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) # Get values if not set. @@ -557,11 +558,11 @@ def add_args(parser: argparse.ArgumentParser): "--netuid", dest="netuid", type=int, required=False, default=False ) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -683,10 +684,10 @@ def add_args(parser: argparse.ArgumentParser): "--netuid", dest="netuid", type=int, required=False, default=False ) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("netuid") and not config.no_prompt: check_netuid_set(config, cybertensor.cwtensor(config=config)) diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index 7081d11..ce0ab54 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -34,6 +34,7 @@ get_coldkey_wallets_for_path, get_all_wallets_for_path, ) +from ..wallet import Wallet console = cybertensor.__console__ @@ -80,7 +81,7 @@ class OverviewCommand: def run(cli: "cybertensor.cli"): r"""Prints an overview for the wallet's colkey.""" console = cybertensor.__console__ - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor: "cybertensor.cwtensor" = cybertensor.cwtensor(config=cli.config) all_hotkeys = [] @@ -100,7 +101,7 @@ def run(cli: "cybertensor.cli"): all_hotkeys = get_all_wallets_for_path(cli.config.wallet.path) else: # We are only printing keys for a single coldkey - coldkey_wallet = cybertensor.wallet(config=cli.config) + coldkey_wallet = Wallet(config=cli.config) if ( coldkey_wallet.coldkeypub_file.exists_on_device() and not coldkey_wallet.coldkeypub_file.is_encrypted() @@ -148,7 +149,7 @@ def run(cli: "cybertensor.cli"): all_wallet_names = set([wallet.name for wallet in all_hotkeys]) all_coldkey_wallets = [ - cybertensor.wallet(name=wallet_name) for wallet_name in all_wallet_names + Wallet(name=wallet_name) for wallet_name in all_wallet_names ] hotkey_coldkey_to_hotkey_wallet = {} @@ -273,7 +274,7 @@ def run(cli: "cybertensor.cli"): de_registered_neurons.append(de_registered_neuron) # Add this hotkey to the wallets dict - wallet_ = cybertensor.Wallet( + wallet_ = Wallet( name=wallet, ) wallet_.hotkey = hotkey_addr @@ -552,7 +553,7 @@ def overview_sort_function(row): @staticmethod def _get_neurons_for_netuid( - args_tuple: Tuple["cybertensor.Config", int, List[str]] + args_tuple: Tuple["Config", int, List[str]] ) -> Tuple[int, List["cybertensor.NeuronInfoLite"], Optional[str]]: cwtensor_config, netuid, hot_wallets = args_tuple @@ -580,7 +581,7 @@ def _get_neurons_for_netuid( def _get_de_registered_stake_for_coldkey_wallet( args_tuple, ) -> Tuple[ - "cybertensor.Wallet", List[Tuple[str, "cybertensor.Balance"]], Optional[str] + "Wallet", List[Tuple[str, "cybertensor.Balance"]], Optional[str] ]: cwtensor_config, all_hotkey_addresses, coldkey_wallet = args_tuple @@ -686,11 +687,11 @@ def add_args(parser: argparse.ArgumentParser): help="""Set the netuid(s) to filter by.""", default=[], ) - cybertensor.wallet.add_args(overview_parser) + Wallet.add_args(overview_parser) cybertensor.cwtensor.add_args(overview_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if ( not config.is_set("wallet.name") and not config.no_prompt diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py index 4c62c5c..8a93d70 100644 --- a/cybertensor/commands/register.py +++ b/cybertensor/commands/register.py @@ -22,9 +22,11 @@ from rich.prompt import Prompt, Confirm import cybertensor -from cybertensor import Balance -from cybertensor.commands import defaults -from cybertensor.commands.utils import check_netuid_set, check_for_cuda_reg_config +from ..utils.balance import Balance +from . import defaults +from ..config import Config +from .utils import check_netuid_set, check_for_cuda_reg_config +from ..wallet import Wallet console = cybertensor.__console__ @@ -63,7 +65,7 @@ class RegisterCommand: def run(cli): r"""Register neuron by recycling some GBOOT.""" config = cli.config.copy() - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=config) # Verify subnet exists @@ -101,7 +103,7 @@ def run(cli): ) @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): check_netuid_set(config, cwtensor=cybertensor.cwtensor(config=config)) if not config.is_set("wallet.name") and not config.no_prompt: @@ -124,7 +126,7 @@ def add_args(cls, parser: argparse.ArgumentParser): default=argparse.SUPPRESS, ) - cybertensor.wallet.add_args(register_parser) + Wallet.add_args(register_parser) cybertensor.cwtensor.add_args(register_parser) @@ -165,7 +167,7 @@ class PowRegisterCommand: @staticmethod def run(cli): r"""Register neuron.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) # Verify subnet exists @@ -279,11 +281,11 @@ def add_args(parser: argparse.ArgumentParser): required=False, ) - cybertensor.wallet.add_args(register_parser) + Wallet.add_args(register_parser) cybertensor.cwtensor.add_args(register_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): # if ( # not config.is_set("cwtensor.network") # and not config.no_prompt diff --git a/cybertensor/commands/root.py b/cybertensor/commands/root.py index fdd37b8..649f0f9 100644 --- a/cybertensor/commands/root.py +++ b/cybertensor/commands/root.py @@ -29,6 +29,7 @@ import cybertensor from . import defaults from .utils import DelegatesDetails +from ..wallet import Wallet console = cybertensor.__console__ @@ -55,7 +56,7 @@ class RootRegisterCommand: @staticmethod def run(cli): r"""Register to root network.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) cwtensor.root_register(wallet=wallet, prompt=not cli.config.no_prompt) @@ -66,11 +67,11 @@ def add_args(parser: argparse.ArgumentParser): "register", help="""Register a wallet to the root network.""" ) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -197,7 +198,7 @@ def add_args(parser: argparse.ArgumentParser): cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): pass @@ -225,7 +226,7 @@ class RootSetWeightsCommand: @staticmethod def run(cli): r"""Set weights for root network.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) subnets: List[cybertensor.SubnetInfo] = cwtensor.get_all_subnets_info() @@ -276,11 +277,11 @@ def add_args(parser: argparse.ArgumentParser): parser.add_argument("--netuids", dest="netuids", type=str, required=False) parser.add_argument("--weights", dest="weights", type=str, required=False) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -395,9 +396,9 @@ def add_args(parser: argparse.ArgumentParser): "get_weights", help="""Get weights for root network.""" ) - cybertensor.wallet.add_args(parser) + Wallet.add_args(parser) cybertensor.cwtensor.add_args(parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): pass diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index d6c9796..60e436f 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -22,8 +22,9 @@ from rich.prompt import Confirm import cybertensor -from cybertensor.utils.balance import Balance +from ..utils.balance import Balance from .utils import get_hotkey_wallets_for_wallet +from ..wallet import Wallet console = cybertensor.__console__ @@ -60,14 +61,14 @@ class StakeCommand: def run(cli): r"""Stake token of amount to hotkey(s).""" config = cli.config.copy() - wallet = cybertensor.wallet(config=config) + wallet = Wallet(config=config) cwtensor = cybertensor.cwtensor(config=config) # Get the hotkey_names (if any) and the hotkeys. hotkeys_to_stake_to: List[Tuple[Optional[str], str]] = [] if config.get("all_hotkeys"): # Stake to all hotkeys. - all_hotkeys: List[cybertensor.wallet] = get_hotkey_wallets_for_wallet( + all_hotkeys: List[Wallet] = get_hotkey_wallets_for_wallet( wallet=wallet ) # Get the hotkeys to exclude. (d)efault to no exclusions. @@ -88,7 +89,7 @@ def run(cli): else: # If the hotkey is not a valid address, we assume it is a hotkey name. # We then get the hotkey from the wallet and add it to the list. - wallet_ = cybertensor.wallet( + wallet_ = Wallet( config=config, hotkey=hotkey_or_hotkey_name ) hotkeys_to_stake_to.append( @@ -102,7 +103,7 @@ def run(cli): hotkeys_to_stake_to = [(None, hotkey_or_name)] else: # Hotkey is not a valid address, so we assume it is a hotkey name. - wallet_ = cybertensor.wallet(config=config, hotkey=hotkey_or_name) + wallet_ = Wallet(config=config, hotkey=hotkey_or_name) hotkeys_to_stake_to = [ (wallet_.hotkey_str, wallet_.hotkey.address) ] @@ -111,7 +112,7 @@ def run(cli): # so we stake to that single hotkey. assert config.wallet.hotkey is not None hotkeys_to_stake_to = [ - (None, cybertensor.wallet(config=config).hotkey.address) + (None, Wallet(config=config).hotkey.address) ] # Get coldkey balance @@ -199,7 +200,7 @@ def run(cli): ) @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) @@ -273,7 +274,7 @@ def add_args(cls, parser: argparse.ArgumentParser): default=False, help="""To specify all hotkeys. Specifying hotkeys will exclude them from this all.""", ) - cybertensor.wallet.add_args(stake_parser) + Wallet.add_args(stake_parser) cybertensor.cwtensor.add_args(stake_parser) @@ -294,17 +295,17 @@ def add_args(cls, parser: argparse.ArgumentParser): from typing import List, Tuple, Optional, Dict -def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: try: wallet_names = next(os.walk(os.path.expanduser(path)))[1] - return [cybertensor.wallet(path=path, name=name) for name in wallet_names] + return [Wallet(path=path, name=name) for name in wallet_names] except StopIteration: # No wallet files found. wallets = [] return wallets -def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: +def _get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]: hotkey_wallets = [] hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys" try: @@ -313,7 +314,7 @@ def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: hotkey_files = [] for hotkey_file_name in hotkey_files: try: - hotkey_for_name = cybertensor.wallet( + hotkey_for_name = Wallet( path=wallet.path, name=wallet.name, hotkey=hotkey_file_name ) if ( @@ -359,7 +360,7 @@ def run(cli): if cli.config.get("all", d=False) is True: wallets = _get_coldkey_wallets_for_path(cli.config.wallet.path) else: - wallets = [cybertensor.wallet(config=cli.config)] + wallets = [Wallet(config=cli.config)] # TODO revisit # registered_delegate_info: Optional[ @@ -530,7 +531,7 @@ def get_all_wallet_accounts( cybertensor.__console__.print(table) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if ( not config.get("all", d=None) and not config.is_set("wallet.name") @@ -551,5 +552,5 @@ def add_args(parser: argparse.ArgumentParser): default=False, ) - cybertensor.wallet.add_args(list_parser) + Wallet.add_args(list_parser) cybertensor.cwtensor.add_args(list_parser) diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py index 5ae3957..4ea4445 100644 --- a/cybertensor/commands/transfer.py +++ b/cybertensor/commands/transfer.py @@ -24,6 +24,7 @@ import cybertensor from . import defaults +from ..wallet import Wallet console = cybertensor.__console__ @@ -56,7 +57,7 @@ class TransferCommand: @staticmethod def run(cli): r"""Transfer token of amount to destination.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) cwtensor = cybertensor.cwtensor(config=cli.config) cwtensor.transfer( wallet=wallet, @@ -67,7 +68,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -82,7 +83,7 @@ def check_config(config: "cybertensor.config"): # Get current balance and print to user. if not config.no_prompt: - wallet = cybertensor.wallet(config=config) + wallet = Wallet(config=config) cwtensor = cybertensor.cwtensor(config=config) with cybertensor.__console__.status(":satellite: Checking Balance..."): account_balance = cwtensor.get_balance(wallet.coldkeypub.address) @@ -121,5 +122,5 @@ def add_args(parser: argparse.ArgumentParser): "--amount", dest="amount", type=float, required=False ) - cybertensor.wallet.add_args(transfer_parser) + Wallet.add_args(transfer_parser) cybertensor.cwtensor.add_args(transfer_parser) diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py index 4be7c61..c44a19d 100644 --- a/cybertensor/commands/unstake.py +++ b/cybertensor/commands/unstake.py @@ -23,9 +23,10 @@ from tqdm import tqdm import cybertensor -from cybertensor.utils.balance import Balance +from ..utils.balance import Balance from . import defaults from .utils import get_hotkey_wallets_for_wallet +from ..wallet import Wallet console = cybertensor.__console__ @@ -58,7 +59,7 @@ class UnStakeCommand: """ @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -148,14 +149,14 @@ def add_args(command_parser): default=False, help="""To specify all hotkeys. Specifying hotkeys will exclude them from this all.""", ) - cybertensor.wallet.add_args(unstake_parser) + Wallet.add_args(unstake_parser) cybertensor.cwtensor.add_args(unstake_parser) @staticmethod def run(cli): r"""Unstake token of amount from hotkey(s).""" config = cli.config.copy() - wallet = cybertensor.wallet(config=config) + wallet = Wallet(config=config) cwtensor: cybertensor.cwtensor = cybertensor.cwtensor(config=cli.config) # Get the hotkey_names (if any) and the hotkeys. @@ -165,7 +166,7 @@ def run(cli): hotkeys_to_unstake_from = [(None, cli.config.get("hotkey_address"))] elif cli.config.get("all_hotkeys"): # Stake to all hotkeys. - all_hotkeys: List[cybertensor.wallet] = get_hotkey_wallets_for_wallet( + all_hotkeys: List[Wallet] = get_hotkey_wallets_for_wallet( wallet=wallet ) # Get the hotkeys to exclude. (d)efault to no exclusions. @@ -186,7 +187,7 @@ def run(cli): else: # If the hotkey is not a valid address, we assume it is a hotkey name. # We then get the hotkey from the wallet and add it to the list. - wallet_ = cybertensor.wallet( + wallet_ = Wallet( config=cli.config, hotkey=hotkey_or_hotkey_name ) hotkeys_to_unstake_from.append( @@ -200,7 +201,7 @@ def run(cli): hotkeys_to_unstake_from = [(None, hotkey_or_name)] else: # Hotkey is not a valid address, so we assume it is a hotkey name. - wallet_ = cybertensor.wallet( + wallet_ = Wallet( config=cli.config, hotkey=hotkey_or_name ) hotkeys_to_unstake_from = [ @@ -211,7 +212,7 @@ def run(cli): # so we stake to that single hotkey. assert cli.config.wallet.hotkey is not None hotkeys_to_unstake_from = [ - (None, cybertensor.wallet(config=cli.config).hotkey.address) + (None, Wallet(config=cli.config).hotkey.address) ] final_hotkeys: List[Tuple[str, str]] = [] diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py index 5a8d01f..7afc11d 100644 --- a/cybertensor/commands/utils.py +++ b/cybertensor/commands/utils.py @@ -26,6 +26,7 @@ from rich.prompt import Confirm, PromptBase import cybertensor +from .wallets import Wallet from . import defaults console = cybertensor.__console__ @@ -47,7 +48,7 @@ def check_choice(self, value: str) -> bool: def check_netuid_set( - config: "cybertensor.config", + config: "Config", cwtensor: "cybertensor.cwtensor", allow_none: bool = False, ): @@ -78,7 +79,7 @@ def check_netuid_set( raise ValueError('netuid must be an integer or "None" (if applicable)') -def check_for_cuda_reg_config(config: "cybertensor.config") -> None: +def check_for_cuda_reg_config(config: "Config") -> None: """Checks, when CUDA is available, if the user would like to register with their CUDA device.""" if torch.cuda.is_available(): if not config.no_prompt: @@ -131,7 +132,7 @@ def check_for_cuda_reg_config(config: "cybertensor.config") -> None: config.pow_register.cuda.use_cuda = defaults.pow_register.cuda.use_cuda -def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: +def get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]: hotkey_wallets = [] hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys" try: @@ -140,7 +141,7 @@ def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: hotkey_files = [] for hotkey_file_name in hotkey_files: try: - hotkey_for_name = cybertensor.wallet( + hotkey_for_name = Wallet( path=wallet.path, name=wallet.name, hotkey=hotkey_file_name ) if ( @@ -153,17 +154,17 @@ def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]: return hotkey_wallets -def get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: try: wallet_names = next(os.walk(os.path.expanduser(path)))[1] - return [cybertensor.wallet(path=path, name=name) for name in wallet_names] + return [Wallet(path=path, name=name) for name in wallet_names] except StopIteration: # No wallet files found. wallets = [] return wallets -def get_all_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def get_all_wallets_for_path(path: str) -> List["Wallet"]: all_wallets = [] cold_wallets = get_coldkey_wallets_for_path(path) for cold_wallet in cold_wallets: diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index 6f3bbed..9dca48d 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -26,6 +26,7 @@ import cybertensor from . import defaults +from ..wallet import Wallet # TODO rewrite to use raw pubkey against hex or rewrite keypair/keyfile to use hex @@ -57,7 +58,7 @@ class RegenColdkeyCommand: def run(cli): r"""Creates a new coldkey under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) json_str: Optional[str] = None json_password: Optional[str] = None @@ -80,7 +81,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -150,7 +151,7 @@ def add_args(parser: argparse.ArgumentParser): action="store_false", help="""Overwrite the old coldkey with the newly generated coldkey""", ) - cybertensor.wallet.add_args(regen_coldkey_parser) + Wallet.add_args(regen_coldkey_parser) cybertensor.cwtensor.add_args(regen_coldkey_parser) @@ -178,7 +179,7 @@ class RegenColdkeypubCommand: def run(cli): r"""Creates a new coldkeypub under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) wallet.regenerate_coldkeypub( address=cli.config.get("address"), public_key=cli.config.get("public_key_hex"), @@ -186,7 +187,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -235,7 +236,7 @@ def add_args(parser: argparse.ArgumentParser): action="store_true", help="""Overwrite the old coldkeypub file with the newly generated coldkeypub""", ) - cybertensor.wallet.add_args(regen_coldkeypub_parser) + Wallet.add_args(regen_coldkeypub_parser) cybertensor.cwtensor.add_args(regen_coldkeypub_parser) @@ -267,7 +268,7 @@ class RegenHotkeyCommand: def run(cli): r"""Creates a new coldkey under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) json_str: Optional[str] = None json_password: Optional[str] = None @@ -290,7 +291,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -365,7 +366,7 @@ def add_args(parser: argparse.ArgumentParser): default=False, help="""Overwrite the old hotkey with the newly generated hotkey""", ) - cybertensor.wallet.add_args(regen_hotkey_parser) + Wallet.add_args(regen_hotkey_parser) cybertensor.cwtensor.add_args(regen_hotkey_parser) @@ -393,7 +394,7 @@ class NewHotkeyCommand: def run(cli): """Creates a new hotke under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) wallet.create_new_hotkey( n_words=cli.config.n_words, use_password=cli.config.use_password, @@ -401,7 +402,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -442,7 +443,7 @@ def add_args(parser: argparse.ArgumentParser): default=False, help="""Overwrite the old hotkey with the newly generated hotkey""", ) - cybertensor.wallet.add_args(new_hotkey_parser) + Wallet.add_args(new_hotkey_parser) cybertensor.cwtensor.add_args(new_hotkey_parser) @@ -470,7 +471,7 @@ class NewColdkeyCommand: def run(cli): r"""Creates a new coldkey under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) wallet.create_new_coldkey( n_words=cli.config.n_words, use_password=cli.config.use_password, @@ -478,7 +479,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -515,7 +516,7 @@ def add_args(parser: argparse.ArgumentParser): default=False, help="""Overwrite the old coldkey with the newly generated coldkey""", ) - cybertensor.wallet.add_args(new_coldkey_parser) + Wallet.add_args(new_coldkey_parser) cybertensor.cwtensor.add_args(new_coldkey_parser) @@ -544,7 +545,7 @@ class WalletCreateCommand: def run(cli): r"""Creates a new coldkey and hotkey under this wallet.""" - wallet = cybertensor.wallet(config=cli.config) + wallet = Wallet(config=cli.config) wallet.create_new_coldkey( n_words=cli.config.n_words, use_password=cli.config.use_password, @@ -557,7 +558,7 @@ def run(cli): ) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.name") and not config.no_prompt: wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name) config.wallet.name = str(wallet_name) @@ -603,15 +604,15 @@ def add_args(parser: argparse.ArgumentParser): default=False, help="""Overwrite the old hotkey with the newly generated hotkey""", ) - cybertensor.wallet.add_args(new_coldkey_parser) + Wallet.add_args(new_coldkey_parser) cybertensor.cwtensor.add_args(new_coldkey_parser) -def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]: +def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: """Get all coldkey wallet names from path.""" try: wallet_names = next(os.walk(os.path.expanduser(path)))[1] - return [cybertensor.wallet(path=path, name=name) for name in wallet_names] + return [Wallet(path=path, name=name) for name in wallet_names] except StopIteration: # No wallet files found. wallets = [] @@ -646,7 +647,7 @@ def run(cli): if config.get("all", d=False) is True: wallets = _get_coldkey_wallets_for_path(config.wallet.path) else: - wallets = [cybertensor.wallet(config=config)] + wallets = [Wallet(config=config)] for wallet in wallets: print("\n===== ", wallet, " =====") @@ -666,11 +667,11 @@ def add_args(parser: argparse.ArgumentParser): help="""Set true to avoid prompting the user.""", default=False, ) - cybertensor.wallet.add_args(update_wallet_parser) + Wallet.add_args(update_wallet_parser) cybertensor.cwtensor.add_args(update_wallet_parser) @staticmethod - def check_config(config: "cybertensor.Config"): + def check_config(config: "Config"): if config.get("all", d=False) is False: if not config.no_prompt: if Confirm.ask("Do you want to update all legacy wallets?"): @@ -811,11 +812,11 @@ def add_args(parser: argparse.ArgumentParser): balance_parser = parser.add_parser( "balance", help="""Checks the balance of the wallet.""" ) - cybertensor.wallet.add_args(balance_parser) + Wallet.add_args(balance_parser) cybertensor.cwtensor.add_args(balance_parser) @staticmethod - def check_config(config: "cybertensor.config"): + def check_config(config: "Config"): if not config.is_set("wallet.path") and not config.no_prompt: path = Prompt.ask("Enter wallets path", default=defaults.wallet.path) config.wallet.path = str(path) diff --git a/cybertensor/config.py b/cybertensor/config.py index ca05f79..c561c75 100644 --- a/cybertensor/config.py +++ b/cybertensor/config.py @@ -33,7 +33,7 @@ class InvalidConfigFile(Exception): pass -class config(DefaultMunch): +class Config(DefaultMunch): """ Implementation of the config class, which manages the config of different cybertensor modules. """ @@ -52,7 +52,7 @@ class config(DefaultMunch): Default value for the Config. Defaults to None. This default will be returned for attributes that are undefined. Returns: - config (cybertensor.config): + config (Config): Nested config object created from parser arguments. """ @@ -130,7 +130,7 @@ def __init__( config_file_path = None # Parse args not strict - config_params = config.__parse_args__(args=args, parser=parser, strict=False) + config_params = Config.__parse_args__(args=args, parser=parser, strict=False) # 2. Optionally check for --strict ## strict=True when passed in OR when --strict is set @@ -147,12 +147,12 @@ def __init__( print("Error in loading: {} using default parser settings".format(e)) # 2. Continue with loading in params. - params = config.__parse_args__(args=args, parser=parser, strict=strict) + params = Config.__parse_args__(args=args, parser=parser, strict=strict) _config = self # Splits params and add to config - config.__split_params__(params=params, _config=_config) + Config.__split_params__(params=params, _config=_config) # Make the is_set map _config["__is_set"] = {} @@ -203,7 +203,7 @@ def __init__( cmd_parser._defaults.clear() # Needed for quirk of argparse ## Reparse the args, but this time with the defaults as argparse.SUPPRESS - params_no_defaults = config.__parse_args__( + params_no_defaults = Config.__parse_args__( args=args, parser=parser_no_defaults, strict=strict ) @@ -233,7 +233,7 @@ def __split_params__(params: argparse.Namespace, _config: "config"): head = getattr(head, keys[0]) keys = keys[1:] else: - head[keys[0]] = config() + head[keys[0]] = Config() head = head[keys[0]] keys = keys[1:] if len(keys) == 1: @@ -272,7 +272,7 @@ def __deepcopy__(self, memo) -> "config": _default = self.__default__ config_state = self.__getstate__() - config_copy = config() + config_copy = Config() memo[id(self)] = config_copy config_copy.__setstate__(config_state) @@ -293,7 +293,7 @@ def _remove_private_keys(d): d.pop("__is_set", None) for k, v in list(d.items()): if isinstance(v, dict): - config._remove_private_keys(v) + Config._remove_private_keys(v) return d def __str__(self) -> str: @@ -301,7 +301,7 @@ def __str__(self) -> str: visible = copy.deepcopy(self.toDict()) visible.pop("__parser", None) visible.pop("__is_set", None) - cleaned = config._remove_private_keys(visible) + cleaned = Config._remove_private_keys(visible) return "\n" + yaml.dump(cleaned, sort_keys=False) def copy(self) -> "config": @@ -372,7 +372,7 @@ def is_set(self, param_name: str) -> bool: T = TypeVar("T", bound="DefaultConfig") -class DefaultConfig(config): +class DefaultConfig(Config): """ A Config with a set of default values. """ diff --git a/cybertensor/ctlogging.py b/cybertensor/ctlogging.py index b85905f..aa52502 100644 --- a/cybertensor/ctlogging.py +++ b/cybertensor/ctlogging.py @@ -25,7 +25,8 @@ import torch from loguru import logger -import cybertensor +from .config import Config + logger = logger.opt(colors=True) # Remove default sink. @@ -51,7 +52,7 @@ class logging: def __new__( cls, - config: "cybertensor.config" = None, + config: "Config" = None, debug: bool = None, trace: bool = None, record_log: bool = None, @@ -59,7 +60,7 @@ def __new__( ): r"""Instantiate cybertensor logging system backend. Args: - config (:obj:`cybertensor.config`, `optional`): + config (:obj:`Config`, `optional`): cybertensor.logging.config() debug (:obj:`bool`, `optional`): Turn on debug. @@ -129,11 +130,11 @@ def __new__( @classmethod def config(cls): """Get config from the argument parser - Return: cybertensor.config object + Return: Config object """ parser = argparse.ArgumentParser() logging.add_args(parser) - return cybertensor.config(parser, args=[]) + return Config(parser, args=[]) @classmethod def help(cls): @@ -183,7 +184,7 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None): pass @classmethod - def check_config(cls, config: "cybertensor.config"): + def check_config(cls, config: "Config"): """Check config""" assert config.logging diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index c3427fc..28233ae 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -68,6 +68,8 @@ from .utils import U16_NORMALIZED_FLOAT, coin_from_str from .utils.balance import Balance from .utils.registration import POWSolution +from .wallet import Wallet +from .config import Config logger = logger.opt(colors=True) @@ -80,10 +82,10 @@ class cwtensor: """ @staticmethod - def config() -> "cybertensor.config": + def config() -> "Config": parser = argparse.ArgumentParser() cwtensor.add_args(parser) - return cybertensor.config(parser, args=[]) + return Config(parser, args=[]) @classmethod def help(cls): @@ -159,7 +161,7 @@ def determine_chain_endpoint_and_network( return "unknown", {} @staticmethod - def setup_config(network: str, config: "cybertensor.config"): + def setup_config(network: str, config: "Config"): if network is not None: ( evaluated_network, @@ -197,12 +199,12 @@ def setup_config(network: str, config: "cybertensor.config"): def __init__( self, network: str = None, - config: "cybertensor.config" = None, + config: "Config" = None, _mock: bool = False, ) -> None: r"""Initializes a cwtensor chain interface. Args: - config (:obj:`cybertensor.config`, `optional`): + config (:obj:`Config`, `optional`): cybertensor.cwtensor.config() network (default='local or ws://127.0.0.1:9946', type=str) The cwtensor network flag. The likely choices are: @@ -255,7 +257,7 @@ def __repr__(self) -> str: ##################### def nominate( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, ) -> bool: """Becomes a delegate for the hotkey.""" @@ -267,7 +269,7 @@ def nominate( def _do_nominate( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, ) -> bool: nominate_msg = {"become_delegate": {"hotkey": wallet.hotkey.address}} @@ -296,7 +298,7 @@ def make_call_with_retry(): def delegate( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -314,7 +316,7 @@ def delegate( def _do_delegation( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: str, amount: "Balance", wait_for_finalization: bool = True, @@ -346,7 +348,7 @@ def make_call_with_retry(): def undelegate( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -364,7 +366,7 @@ def undelegate( def _do_undelegation( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: str, amount: "Balance", wait_for_finalization: bool = True, @@ -399,7 +401,7 @@ def make_call_with_retry(): def set_weights( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, uids: Union[torch.LongTensor, torch.Tensor, list], weights: Union[torch.FloatTensor, torch.Tensor, list], @@ -420,7 +422,7 @@ def set_weights( def _do_set_weights( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", uids: List[int], vals: List[int], netuid: int, @@ -463,7 +465,7 @@ def make_call_with_retry(): ###################### def register( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, wait_for_finalization: bool = True, prompt: bool = False, @@ -496,14 +498,14 @@ def register( def _do_pow_register( self, netuid: int, - wallet: "cybertensor.wallet", + wallet: "Wallet", pow_result: POWSolution, wait_for_finalization: bool = True, ) -> Tuple[bool, Optional[str]]: """Sends a (POW) register extrinsic to the chain. Args: netuid (int): the subnet to register on. - wallet (cybertensor.wallet): the wallet to register. + wallet (Wallet): the wallet to register. pow_result (POWSolution): the pow result to register. wait_for_finalization (bool): if true, waits for the extrinsic to be finalized. Returns: @@ -547,7 +549,7 @@ def make_call_with_retry(): def burned_register( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, wait_for_finalization: bool = True, prompt: bool = False, @@ -565,7 +567,7 @@ def _do_burned_register( self, netuid: int, burn: int, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, ) -> Tuple[bool, Optional[str]]: burned_register_msg = { @@ -602,7 +604,7 @@ def make_call_with_retry(): ################## def transfer( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", dest: str, amount: Union[Balance, float], wait_for_inclusion: bool = True, @@ -629,7 +631,7 @@ def get_transfer_fee( def _do_transfer( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", dest: Address, transfer_balance: Balance, wait_for_inclusion: bool = True, @@ -637,7 +639,7 @@ def _do_transfer( ) -> Tuple[bool, Optional[str], Optional[str]]: """Sends a transfer extrinsic to the chain. Args: - wallet (:obj:`cybertensor.wallet`): Wallet object. + wallet (:obj:`Wallet`): Wallet object. dest (:obj:`str`): Destination public key address. transfer_balance (:obj:`Balance`): Amount to transfer. wait_for_inclusion (:obj:`bool`): If true, waits for inclusion. @@ -680,7 +682,7 @@ def get_existential_deposit(self, block: Optional[int] = None) -> Optional[Balan ################# def register_subnetwork( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization=True, prompt: bool = False, ) -> bool: @@ -693,7 +695,7 @@ def register_subnetwork( def set_hyperparameter( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, parameter: str, value, @@ -716,7 +718,7 @@ def set_hyperparameter( def serve( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", ip: str, port: int, protocol: int, @@ -749,7 +751,7 @@ def serve_axon( def _do_serve_axon( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", call_params: AxonServeCallParams, wait_for_finalization: bool = True, ) -> Tuple[bool, Optional[str]]: @@ -778,7 +780,7 @@ def make_call_with_retry(): def serve_prometheus( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", port: int, netuid: int, wait_for_finalization: bool = True, @@ -793,14 +795,14 @@ def serve_prometheus( def _do_serve_prometheus( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", call_params: PrometheusServeCallParams, wait_for_finalization: bool = True, ) -> Tuple[bool, Optional[str]]: """ Sends a serve prometheus extrinsic to the chain. Args: - wallet (:obj:`cybertensor.wallet`): Wallet object. + wallet (:obj:`Wallet`): Wallet object. call_params (:obj:`PrometheusServeCallParams`): Prometheus serve call parameters. wait_for_finalization (:obj:`bool`): If true, waits for finalization. Returns: @@ -836,7 +838,7 @@ def make_call_with_retry(): ################# def add_stake( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -854,7 +856,7 @@ def add_stake( def add_stake_multiple( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkeys: List[str], amounts: List[Union[Balance, float]] = None, wait_for_finalization: bool = True, @@ -872,14 +874,14 @@ def add_stake_multiple( def _do_stake( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: str, amount: Balance, wait_for_finalization: bool = True, ) -> bool: """Sends a stake extrinsic to the chain. Args: - wallet (:obj:`cybertensor.wallet`): Wallet object that can sign the extrinsic. + wallet (:obj:`Wallet`): Wallet object that can sign the extrinsic. hotkey (:obj:`str`): Hotkey address to stake to. amount (:obj:`Balance`): Amount to stake. wait_for_finalization (:obj:`bool`): If true, waits for finalization before returning. @@ -919,7 +921,7 @@ def make_call_with_retry(): ################### def unstake_multiple( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkeys: List[str], amounts: List[Union[Balance, float]] = None, wait_for_finalization: bool = True, @@ -937,7 +939,7 @@ def unstake_multiple( def unstake( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -955,14 +957,14 @@ def unstake( def _do_unstake( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: str, amount: Balance, wait_for_finalization: bool = False, ) -> bool: """Sends an unstake extrinsic to the chain. Args: - wallet (:obj:`cybertensor.wallet`): Wallet object that can sign the extrinsic. + wallet (:obj:`Wallet`): Wallet object that can sign the extrinsic. hotkey (:obj:`str`): Hotkey address to unstake from. amount (:obj:`Balance`): Amount to unstake. wait_for_finalization (:obj:`bool`): If true, waits for finalization before returning. @@ -1002,7 +1004,7 @@ def make_call_with_retry(): def root_register( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, prompt: bool = False, ) -> bool: @@ -1016,7 +1018,7 @@ def root_register( def _do_root_register( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, ) -> Tuple[bool, Optional[str]]: root_register_msg = {"root_register": {"hotkey": wallet.hotkey.address}} @@ -1045,7 +1047,7 @@ def make_call_with_retry(): def root_set_weights( self, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuids: Union[torch.LongTensor, torch.Tensor, list], weights: Union[torch.FloatTensor, torch.Tensor, list], version_key: int = 0, diff --git a/cybertensor/dendrite.py b/cybertensor/dendrite.py index 91286c0..9c1dd2d 100644 --- a/cybertensor/dendrite.py +++ b/cybertensor/dendrite.py @@ -30,6 +30,7 @@ from fastapi import Response import cybertensor +from .wallet import Wallet class dendrite(torch.nn.Module): @@ -80,7 +81,7 @@ class dendrite(torch.nn.Module): NOTE: When working with async aiohttp client sessions, it is recommended to use a context manager. Example with a context manager: - >>> aysnc with dendrite(wallet = cybertensor.wallet()) as d: + >>> aysnc with dendrite(wallet = Wallet()) as d: >>> print(d) >>> d( ) # ping axon >>> d( [] ) # ping multiple @@ -89,7 +90,7 @@ class dendrite(torch.nn.Module): However, you are able to safely call dendrite.query() without a context manager in a synchronous setting. Example without a context manager: - >>> d = dendrite(wallet = cybertensor.wallet() ) + >>> d = dendrite(wallet = Wallet() ) >>> print(d) >>> d( ) # ping axon >>> d( [] ) # ping multiple @@ -97,15 +98,15 @@ class dendrite(torch.nn.Module): """ def __init__( - self, wallet: Optional[Union[cybertensor.wallet, cybertensor.keypair]] = None + self, wallet: Optional[Union[Wallet, cybertensor.keypair]] = None ): """ Initializes the Dendrite object, setting up essential properties. Args: - wallet (Optional[Union['cybertensor.wallet', 'cybertensor.keypair']], optional): + wallet (Optional[Union['Wallet', 'cybertensor.keypair']], optional): The user's wallet or keypair used for signing messages. Defaults to None, - in which case a new cybertensor.wallet().hotkey is generated and used. + in which case a new Wallet().hotkey is generated and used. """ # Initialize the parent class super(dendrite, self).__init__() @@ -118,8 +119,8 @@ def __init__( # If a wallet or keypair is provided, use its hotkey. If not, generate a new one. self.keypair = ( - wallet.hotkey if isinstance(wallet, cybertensor.wallet) else wallet - ) or cybertensor.wallet().hotkey + wallet.hotkey if isinstance(wallet, Wallet) else wallet + ) or Wallet().hotkey self.synapse_history: list = [] diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index abe3adf..91a10b1 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -37,8 +37,8 @@ from termcolor import colored import cybertensor -from cybertensor import __chain_address_prefix__ -from cybertensor.errors import KeyFileError +from . import __chain_address_prefix__ +from .errors import KeyFileError NACL_SALT = b"\x13q\x83\xdf\xf1Z\t\xbc\x9c\x90\xb5Q\x879\xe9\xb1" diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py index 1cb43a3..3b7962e 100644 --- a/cybertensor/messages/delegation.py +++ b/cybertensor/messages/delegation.py @@ -24,7 +24,7 @@ from rich.prompt import Confirm import cybertensor -from cybertensor.utils.balance import Balance +from ..utils.balance import Balance from ..errors import * logger = logger.opt(colors=True) @@ -32,12 +32,12 @@ def nominate_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, ) -> bool: r"""Becomes a delegate for the hotkey. Args: - wallet ( cybertensor.wallet ): + wallet ( Wallet ): The wallet to become a delegate for. Returns: success (bool): @@ -95,7 +95,7 @@ def nominate_message( def delegate_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = False, @@ -103,7 +103,7 @@ def delegate_message( ) -> bool: r"""Delegates the specified amount of stake to the passed delegate. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. delegate (Optional[str]): address of the delegate. @@ -229,7 +229,7 @@ def delegate_message( def undelegate_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", delegate: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -237,7 +237,7 @@ def undelegate_message( ) -> bool: r"""Un-delegates stake from the passed delegate. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. delegate (Optional[str]): address of the delegate. diff --git a/cybertensor/messages/log_utilities.py b/cybertensor/messages/log_utilities.py index ab1317c..7ee7bde 100644 --- a/cybertensor/messages/log_utilities.py +++ b/cybertensor/messages/log_utilities.py @@ -19,7 +19,7 @@ class ValidatorLogger: Including console log styling, console table print and prometheus. Args: - config (:obj:`cybertensor.Config`, `optional`): + config (:obj:`Config`, `optional`): cybertensor.server.config() """ @@ -576,7 +576,7 @@ def print_weights_table( ) def print_console_validator_identifier( - self, uid: int, wallet: "cybertensor.wallet", external_ip: str + self, uid: int, wallet: "Wallet", external_ip: str ): r"""Console print for validator identifier.""" @@ -670,7 +670,7 @@ class ValidatorPrometheus: r""" Prometheis logging object for validator. Args: - config (:obj:`cybertensor.Config`, `optional`): + config (:obj:`Config`, `optional`): cybertensor.server.config() """ @@ -698,7 +698,7 @@ def log_run_info( parameters: torch.nn.parameter.Parameter, uid: int, network: str, - wallet: "cybertensor.wallet", + wallet: "Wallet", ): r"""Set up prometheus running info.""" diff --git a/cybertensor/messages/network.py b/cybertensor/messages/network.py index 8ee4923..39b26a4 100644 --- a/cybertensor/messages/network.py +++ b/cybertensor/messages/network.py @@ -22,12 +22,13 @@ from rich.prompt import Confirm import cybertensor -from cybertensor import Balance +from ..utils.balance import Balance +from ..wallet import Wallet def register_subnetwork_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, prompt: bool = False, ) -> bool: @@ -35,7 +36,7 @@ def register_subnetwork_message( Args: cwtensor (cybertensor.cwtensor): the CWTensor - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. wait_for_finalization (bool): If set, waits for the transaction to be finalized on the chain before returning true, @@ -114,7 +115,7 @@ def register_subnetwork_message( def set_hyperparameter_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, parameter: str, value, @@ -125,7 +126,7 @@ def set_hyperparameter_message( Args: cwtensor (cybertensor.cwtensor): the CWTensor - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. netuid (int): Subnetwork uid. diff --git a/cybertensor/messages/prometheus.py b/cybertensor/messages/prometheus.py index c073df5..ec667fe 100644 --- a/cybertensor/messages/prometheus.py +++ b/cybertensor/messages/prometheus.py @@ -20,13 +20,15 @@ import json import cybertensor -import cybertensor.utils.networking as net -from cybertensor.types import PrometheusServeCallParams + +from ..wallet import Wallet +from ..utils import networking as net +from ..types import PrometheusServeCallParams def prometheus_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", port: int, netuid: int, ip: int = None, @@ -36,7 +38,7 @@ def prometheus_message( Args: cwtensor (cybertensor.cwtensor): cybertensor cwtensor object. - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. ip (str): endpoint host port i.e. 192.122.31.4 diff --git a/cybertensor/messages/registration.py b/cybertensor/messages/registration.py index 76dba06..72ed393 100644 --- a/cybertensor/messages/registration.py +++ b/cybertensor/messages/registration.py @@ -24,13 +24,14 @@ from rich.prompt import Confirm import cybertensor -from cybertensor import Balance -from cybertensor.utils.registration import POWSolution, create_pow +from ..utils.balance import Balance +from ..utils.registration import POWSolution, create_pow +from ..wallet import Wallet def register_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, wait_for_finalization: bool = True, prompt: bool = False, @@ -45,7 +46,7 @@ def register_message( ) -> bool: r"""Registers the wallet to chain. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. netuid (int): The netuid of the subnet to register on. @@ -211,14 +212,14 @@ def register_message( def burned_register_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, wait_for_finalization: bool = True, prompt: bool = False, ) -> bool: r"""Registers the wallet to chain by recycling GBOOT. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. netuid (int): The netuid of the subnet to register on. diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index b55f440..32155ce 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -32,13 +32,13 @@ def root_register_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", wait_for_finalization: bool = True, prompt: bool = False, ) -> bool: r"""Registers the wallet to root network. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning true, @@ -98,7 +98,7 @@ def root_register_message( def set_root_weights_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuids: Union[torch.LongTensor, list], weights: Union[torch.FloatTensor, list], version_key: int = 0, @@ -107,7 +107,7 @@ def set_root_weights_message( ) -> bool: r"""Sets the given weights and values on chain for wallet hotkey account. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. netuids (List[int]): netuid of the subnet to set weights for. diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py index 492c981..b95434d 100644 --- a/cybertensor/messages/serving.py +++ b/cybertensor/messages/serving.py @@ -21,13 +21,13 @@ from rich.prompt import Confirm import cybertensor -import cybertensor.utils.networking as net -from cybertensor.types import AxonServeCallParams +from ..utils import networking as net +from ..types import AxonServeCallParams def serve_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", ip: str, port: int, protocol: int, @@ -39,7 +39,7 @@ def serve_message( ) -> bool: r"""Subscribes an cybertensor endpoint to the substensor chain. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. ip (str): endpoint host port i.e. 192.122.31.4 diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index e5d8105..8acf8d4 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -31,7 +31,7 @@ def set_weights_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, uids: Union[torch.LongTensor, list], weights: Union[torch.FloatTensor, list], @@ -41,7 +41,7 @@ def set_weights_message( ) -> bool: r"""Sets the given weights and values on chain for wallet hotkey account. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. netuid (int): netuid of the subnet to set weights for. diff --git a/cybertensor/messages/staking.py b/cybertensor/messages/staking.py index 1f57673..7020cee 100644 --- a/cybertensor/messages/staking.py +++ b/cybertensor/messages/staking.py @@ -23,12 +23,13 @@ from rich.prompt import Confirm import cybertensor -from cybertensor.utils.balance import Balance +from ..utils.balance import Balance +from ..wallet import Wallet def add_stake_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -36,7 +37,7 @@ def add_stake_message( ) -> bool: r"""Adds the specified amount of stake to passed hotkey uid. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. hotkey (Optional[str]): address of the hotkey account to stake to @@ -194,7 +195,7 @@ def add_stake_message( def add_stake_multiple_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkeys: List[str], amounts: List[Union[Balance, float]] = None, wait_for_finalization: bool = True, @@ -202,7 +203,7 @@ def add_stake_multiple_message( ) -> bool: r"""Adds stake to each hotkey in the list, using each amount, from a common coldkey. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object for the coldkey. hotkeys (List[str]): List of hotkeys to stake to. @@ -405,7 +406,7 @@ def add_stake_multiple_message( def __do_add_stake_single( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: str, amount: "cybertensor.Balance", wait_for_finalization: bool = True, @@ -413,7 +414,7 @@ def __do_add_stake_single( r""" Executes a stake call to the chain using the wallet and amount specified. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. hotkey (str): Hotkey to stake to. diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py index 530661f..63f177a 100644 --- a/cybertensor/messages/transfer.py +++ b/cybertensor/messages/transfer.py @@ -26,11 +26,12 @@ import cybertensor from ..utils import is_valid_address from ..utils.balance import Balance +from ..wallet import Wallet def transfer_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", dest: Union[Address, str], amount: Union[Balance, float], wait_for_inclusion: bool = True, @@ -40,7 +41,7 @@ def transfer_message( ) -> bool: r"""Transfers funds from this wallet to the destination public key address Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object to make transfer from. dest (Union[cosmpy.crypto.address.Address, str]): Destination public key address of a receiver. diff --git a/cybertensor/messages/unstaking.py b/cybertensor/messages/unstaking.py index 24dec48..4560625 100644 --- a/cybertensor/messages/unstaking.py +++ b/cybertensor/messages/unstaking.py @@ -23,12 +23,13 @@ from rich.prompt import Confirm import cybertensor -from cybertensor.utils.balance import Balance +from ..utils.balance import Balance +from ..wallet import Wallet def __do_remove_stake_single( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: str, amount: "cybertensor.Balance", wait_for_finalization: bool = True, @@ -36,7 +37,7 @@ def __do_remove_stake_single( r""" Executes an unstake call to the chain using the wallet and amount specified. Args: - wallet (cybertensor.wallet): + wallet (Wallet): Cybertensor wallet object. hotkey (str): Hotkey address to unstake from. @@ -73,7 +74,7 @@ def __do_remove_stake_single( def unstake_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: Optional[str] = None, amount: Union[Balance, float] = None, wait_for_finalization: bool = True, @@ -81,7 +82,7 @@ def unstake_message( ) -> bool: r"""Removes stake into the wallet coldkey from the specified hotkey uid. Args: - wallet (cybertensor.wallet): + wallet (Wallet): cybertensor wallet object. hotkey (Optional[str]): address of the hotkey to unstake from. @@ -193,7 +194,7 @@ def unstake_message( def unstake_multiple_message( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", hotkey: List[str], amounts: List[Union[Balance, float]] = None, wait_for_finalization: bool = True, @@ -201,7 +202,7 @@ def unstake_multiple_message( ) -> bool: r"""Removes stake from each hotkey in the list, using each amount, to a common coldkey. Args: - wallet (cybertensor.wallet): + wallet (Wallet): The wallet with the coldkey to unstake to. hotkey (List[str]): List of hotkeys to unstake from. diff --git a/cybertensor/threadpool.py b/cybertensor/threadpool.py index 1b2694c..5893735 100644 --- a/cybertensor/threadpool.py +++ b/cybertensor/threadpool.py @@ -20,6 +20,7 @@ from loguru import logger import cybertensor +from .config import Config # Workers are created as daemon threads. This is done to allow the interpreter # to exit when there are still idle threads in a ThreadPoolExecutor's thread @@ -193,13 +194,13 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None): pass @classmethod - def config(cls) -> "cybertensor.config": + def config(cls) -> "Config": """Get config from the argument parser - Return: cybertensor.config object + Return: Config object """ parser = argparse.ArgumentParser() PriorityThreadPoolExecutor.add_args(parser) - return cybertensor.config(parser, args=[]) + return Config(parser, args=[]) @property def is_empty(self): diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py index 73f1d76..95206d6 100644 --- a/cybertensor/utils/registration.py +++ b/cybertensor/utils/registration.py @@ -17,6 +17,7 @@ from rich import status as rich_status import cybertensor +from ..wallet import Wallet from ._register_cuda import solve_cuda from .formatting import get_human_readable, millify @@ -453,7 +454,7 @@ def update(self, stats: RegistrationStatistics, verbose: bool = False) -> None: def _solve_for_difficulty_fast( cwtensor, - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, output_in_place: bool = True, num_processes: Optional[int] = None, @@ -799,7 +800,7 @@ def _check_for_newest_block_and_update( def _solve_for_difficulty_fast_cuda( cwtensor: "cybertensor.cwtensor", - wallet: "cybertensor.wallet", + wallet: "Wallet", netuid: int, output_in_place: bool = True, update_interval: int = 50_000, @@ -814,7 +815,7 @@ def _solve_for_difficulty_fast_cuda( Args: cwtensor: cybertensor.cwtensor The cwtensor node to grab blocks - wallet: cybertensor.wallet + wallet: Wallet The wallet to register netuid: int The netuid of the subnet to register to. @@ -1039,7 +1040,7 @@ def create_pow( Args: cwtensor (:obj:`cybertensor.cwtensor.cwtensor`, `required`): The cwtensor to create a proof of work for. - wallet (:obj:`cybertensor.wallet.wallet`, `required`): + wallet (:obj:`Wallet.wallet`, `required`): The wallet to create a proof of work for. netuid (:obj:`int`, `required`): The netuid for the subnet to create a proof of work for. diff --git a/cybertensor/wallet.py b/cybertensor/wallet.py index abab5d4..36e4bc7 100644 --- a/cybertensor/wallet.py +++ b/cybertensor/wallet.py @@ -24,8 +24,9 @@ from termcolor import colored import cybertensor -from cybertensor.keypair import Keypair -from cybertensor.utils import is_valid_cybertensor_address_or_public_key +from .config import Config +from .keypair import Keypair +from .utils import is_valid_cybertensor_address_or_public_key def display_mnemonic_msg(keypair: Keypair, key_type: str): @@ -55,7 +56,7 @@ def display_mnemonic_msg(keypair: Keypair, key_type: str): ) -class wallet: +class Wallet: """ Cybertensor wallet maintenance class. Each wallet contains a coldkey and a hotkey. The coldkey is the user's primary key for holding stake in their wallet @@ -65,16 +66,16 @@ class wallet: """ @classmethod - def config(cls) -> "cybertensor.config": + def config(cls) -> "Config": """ Get config from the argument parser. Returns: - cybertensor.config: Config object. + Config: Config object. """ parser = argparse.ArgumentParser() cls.add_args(parser) - return cybertensor.config(parser, args=[]) + return Config(parser, args=[]) @classmethod def help(cls): @@ -127,7 +128,7 @@ def __init__( name: str = None, hotkey: str = None, path: str = None, - config: "cybertensor.config" = None, + config: "Config" = None, ): r""" Initialize the cybertensor wallet object containing a hot and coldkey. @@ -136,11 +137,11 @@ def __init__( name (str, optional): The name of the wallet to unlock for running cybertensor. Defaults to 'default'. hotkey (str, optional): The name of hotkey used to running the miner. Defaults to 'default'. path (str, optional): The path to your cybertensor wallets. Defaults to '~/.cybertensor/wallets/'. - config (cybertensor.config, optional): cybertensor.wallet.config(). Defaults to None. + config (Config, optional): Wallet.config(). Defaults to None. """ # Fill config from passed args using command line defaults. if config is None: - config = wallet.config() + config = Wallet.config() self.config = copy.deepcopy(config) self.config.wallet.name = name or self.config.wallet.get( "name", cybertensor.defaults.wallet.name @@ -430,7 +431,7 @@ def new_coldkey( overwrite (bool, optional): Will this operation overwrite the coldkey under the same path //coldkey Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created coldkey. """ self.create_new_coldkey(n_words, use_password, overwrite, suppress) @@ -451,7 +452,7 @@ def create_new_coldkey( overwrite (bool, optional): Will this operation overwrite the coldkey under the same path //coldkey Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created coldkey. """ mnemonic = Keypair.generate_mnemonic(n_words) @@ -478,7 +479,7 @@ def new_hotkey( overwrite (bool, optional): Will this operation overwrite the hotkey under the same path //hotkeys/ Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created hotkey. """ self.create_new_hotkey(n_words, use_password, overwrite, suppress) @@ -499,7 +500,7 @@ def create_new_hotkey( overwrite (bool, optional): Will this operation overwrite the hotkey under the same path //hotkeys/ Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created hotkey. """ mnemonic = Keypair.generate_mnemonic(n_words) @@ -526,7 +527,7 @@ def regenerate_coldkeypub( overwrite (bool, optional) (default: False): Will this operation overwrite the coldkeypub (if exists) under the same path //coldkeypub Returns: - wallet (cybertensor.wallet): + wallet (Wallet): newly re-generated Wallet with coldkeypub. """ @@ -612,7 +613,7 @@ def regenerate_coldkey( overwrite (bool, optional): Will this operation overwrite the coldkey under the same path //coldkey Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created coldkey. Note: uses priority order: mnemonic > seed > json @@ -703,7 +704,7 @@ def regenerate_hotkey( overwrite (bool, optional): Will this operation overwrite the hotkey under the same path //hotkeys/ Returns: - wallet (cybertensor.wallet): + wallet (Wallet): this object with newly created hotkey. """ if len(kwargs) == 0: From fadbb09adf76ea4a4003ea1f7673986c20dcdb3a Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 3 Feb 2024 16:31:09 +0800 Subject: [PATCH 02/23] - use global console - optimize imports --- cybertensor/__init__.py | 2 +- cybertensor/cli.py | 4 +-- cybertensor/commands/delegates.py | 34 +++++++++---------- cybertensor/commands/inspect.py | 7 ++-- cybertensor/commands/list.py | 2 -- cybertensor/commands/metagraph.py | 3 +- cybertensor/commands/network.py | 15 ++++----- cybertensor/commands/overview.py | 4 +-- cybertensor/commands/register.py | 9 +++-- cybertensor/commands/root.py | 7 ++-- cybertensor/commands/stake.py | 14 ++++---- cybertensor/commands/transfer.py | 11 +++--- cybertensor/commands/unstake.py | 5 ++- cybertensor/commands/utils.py | 3 +- cybertensor/commands/wallets.py | 3 +- cybertensor/keyfile.py | 50 ++++++++++++++-------------- cybertensor/messages/delegation.py | 45 +++++++++++++------------ cybertensor/messages/network.py | 33 +++++++++--------- cybertensor/messages/prometheus.py | 15 +++++---- cybertensor/messages/registration.py | 47 +++++++++++++------------- cybertensor/messages/root.py | 25 +++++++------- cybertensor/messages/serving.py | 3 +- cybertensor/messages/set_weights.py | 11 +++--- cybertensor/messages/staking.py | 41 ++++++++++++----------- cybertensor/messages/transfer.py | 23 +++++++------ cybertensor/messages/unstaking.py | 45 +++++++++++++------------ cybertensor/utils/registration.py | 3 +- 27 files changed, 228 insertions(+), 236 deletions(-) diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index b6e7f4c..d3b8d90 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -64,7 +64,7 @@ def turn_console_on(): __console__ = Console() -turn_console_off() +turn_console_on() # Logging helpers. diff --git a/cybertensor/cli.py b/cybertensor/cli.py index a5f79b9..d458b10 100644 --- a/cybertensor/cli.py +++ b/cybertensor/cli.py @@ -21,13 +21,11 @@ from typing import List, Optional import cybertensor +from . import __console__ as console from .commands import * from .commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand from .config import Config -# Create a console instance for CLI display. -console = cybertensor.__console__ - ALIAS_TO_COMMAND = { "subnets": "subnets", "root": "root", diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py index 3d70a2b..dd204e4 100644 --- a/cybertensor/commands/delegates.py +++ b/cybertensor/commands/delegates.py @@ -31,6 +31,7 @@ from . import defaults from ..wallet import Wallet from .utils import DelegatesDetails +from .. import __console__ as console def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: @@ -43,9 +44,6 @@ def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: return wallets -console = cybertensor.__console__ - - # Uses rich console to pretty print a table of delegates. def show_delegates( # TODO revisit @@ -116,7 +114,7 @@ def show_delegates( ] = cwtensor.get_delegates() if registered_delegate_info is None: - cybertensor.__console__.print( + console.print( ":warning:[yellow]Could not get delegate info from chain.[/yellow]" ) registered_delegate_info = {} @@ -220,7 +218,7 @@ def show_delegates( str(delegate_description), end_section=True, ) - cybertensor.__console__.print(table) + console.print(table) class DelegateStakeCommand: @@ -294,7 +292,7 @@ def add_args(parser: argparse.ArgumentParser): def check_config(config: "Config"): if not config.get("delegatekey"): # Check for delegates. - with cybertensor.__console__.status(":satellite: Loading delegates..."): + with console.status(":satellite: Loading delegates..."): cwtensor = cybertensor.cwtensor(config=config) delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates() try: @@ -305,7 +303,7 @@ def check_config(config: "Config"): prev_delegates = None if prev_delegates is None: - cybertensor.__console__.print( + console.print( ":warning: [yellow]Could not fetch delegates history[/yellow]" ) @@ -422,7 +420,7 @@ def check_config(config: "Config"): if not config.get("delegatekey"): # Check for delegates. - with cybertensor.__console__.status(":satellite: Loading delegates..."): + with console.status(":satellite: Loading delegates..."): cwtensor = cybertensor.cwtensor(config=config) delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates() try: @@ -433,7 +431,7 @@ def check_config(config: "Config"): prev_delegates = None if prev_delegates is None: - cybertensor.__console__.print( + console.print( ":warning: [yellow]Could not fetch delegates history[/yellow]" ) @@ -515,7 +513,7 @@ def run(cli): # cli.config.cwtensor.network = "archive" # cli.config.cwtensor.chain_endpoint = "wss://archive.chain.opentensor.ai:443" cwtensor = cybertensor.cwtensor(config=cli.config) - with cybertensor.__console__.status(":satellite: Loading delegates..."): + with console.status(":satellite: Loading delegates..."): # TODO added list, check get_deletates delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates() try: @@ -524,7 +522,7 @@ def run(cli): prev_delegates = None if prev_delegates is None: - cybertensor.__console__.print( + console.print( ":warning: [yellow]Could not fetch delegates history[/yellow]" ) @@ -590,7 +588,7 @@ def run(cli): # Check if the hotkey is already a delegate. if cwtensor.is_hotkey_delegate(wallet.hotkey.address): - cybertensor.__console__.print( + console.print( "Aborting: Hotkey {} is already a delegate.".format( wallet.hotkey.address ) @@ -599,7 +597,7 @@ def run(cli): result: bool = cwtensor.nominate(wallet) if not result: - cybertensor.__console__.print( + console.print( "Could not became a delegate on [white]{}[/white]".format( cwtensor.network ) @@ -608,13 +606,13 @@ def run(cli): # Check if we are a delegate. is_delegate: bool = cwtensor.is_hotkey_delegate(wallet.hotkey.address) if not is_delegate: - cybertensor.__console__.print( + console.print( "Could not became a delegate on [white]{}[/white]".format( cwtensor.network ) ) return - cybertensor.__console__.print( + console.print( "Successfully became a delegate on [white]{}[/white]".format( cwtensor.network ) @@ -763,7 +761,7 @@ def run(cli): ] = cwtensor.get_delegates() if registered_delegate_info is None: - cybertensor.__console__.print( + console.print( ":warning:[yellow]Could not get delegate info from chain.[/yellow]" ) registered_delegate_info = {} @@ -815,8 +813,8 @@ def run(cli): # f'{delegate_profile.description:140.140}', ) - cybertensor.__console__.print(table) - cybertensor.__console__.print(f"Total delegated {cwtensor.giga_token_symbol}: {total_delegated}") + console.print(table) + console.print(f"Total delegated {cwtensor.giga_token_symbol}: {total_delegated}") @staticmethod def add_args(parser: argparse.ArgumentParser): diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py index 0798222..1ae74ea 100644 --- a/cybertensor/commands/inspect.py +++ b/cybertensor/commands/inspect.py @@ -28,8 +28,7 @@ from . import defaults from .utils import get_delegates_details, DelegatesDetails from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: @@ -120,7 +119,7 @@ def run(cli) -> None: Dict[str, DelegatesDetails] ] = get_delegates_details(url=cybertensor.__delegates_details_url__) if registered_delegate_info is None: - cybertensor.__console__.print( + console.print( ":warning:[yellow]Could not get delegate info from chain.[/yellow]" ) registered_delegate_info = {} @@ -215,7 +214,7 @@ def run(cli) -> None: str(cybertensor.Balance.from_boot(neuron.emission)), ) - cybertensor.__console__.print(table) + console.print(table) @staticmethod def check_config(config: "Config") -> None: diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py index 2a2a13b..5a6d7f4 100644 --- a/cybertensor/commands/list.py +++ b/cybertensor/commands/list.py @@ -25,8 +25,6 @@ import cybertensor from ..wallet import Wallet -console = cybertensor.__console__ - class ListCommand: """ diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py index 10c2b13..17c6e2b 100644 --- a/cybertensor/commands/metagraph.py +++ b/cybertensor/commands/metagraph.py @@ -22,8 +22,8 @@ import cybertensor from .utils import check_netuid_set +from .. import __console__ as console -console = cybertensor.__console__ # TODO change tokens in table to boot and gigaboot class MetagraphCommand: @@ -74,7 +74,6 @@ class MetagraphCommand: @staticmethod def run(cli): r"""Prints an entire metagraph.""" - console = cybertensor.__console__ cwtensor = cybertensor.cwtensor(config=cli.config) console.print( ":satellite: Syncing with chain: [white]{}[/white] ...".format( diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py index e6407a5..ea45309 100644 --- a/cybertensor/commands/network.py +++ b/cybertensor/commands/network.py @@ -29,8 +29,7 @@ from . import defaults from ..wallet import Wallet from .utils import DelegatesDetails, check_netuid_set - -console = cybertensor.__console__ +from .. import __console__ as console class RegisterSubnetworkCommand: @@ -128,11 +127,11 @@ def run(cli): config = cli.config.copy() cwtensor = cybertensor.cwtensor(config=config) try: - cybertensor.__console__.print( + console.print( f"Subnet lock cost: [green]{cybertensor.utils.balance.Balance( cwtensor.get_subnet_burn_cost() )}[/green]" ) except Exception as e: - cybertensor.__console__.print( + console.print( f"Subnet lock cost: [red]Failed to get subnet lock cost[/red]" f"Error: {e}" ) @@ -245,7 +244,7 @@ def run(cli): table.add_column("[overline white]SUDO", style="white") for row in rows: table.add_row(*row) - cybertensor.__console__.print(table) + console.print(table) @staticmethod def check_config(config: "Config"): @@ -400,7 +399,7 @@ def run(cli): for param in subnet.__dict__: table.add_row(" " + param, str(subnet.__dict__[param])) - cybertensor.__console__.print(table) + console.print(table) @staticmethod def check_config(config: "Config"): @@ -481,7 +480,7 @@ def run(cli): for param in subnet.__dict__: table.add_row(param, str(subnet.__dict__[param])) - cybertensor.__console__.print(table) + console.print(table) @staticmethod def check_config(config: "Config"): @@ -673,7 +672,7 @@ def run(cli): table.box = None table.pad_edge = False table.width = None - cybertensor.__console__.print(table) + console.print(table) @staticmethod def add_args(parser: argparse.ArgumentParser): diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index ce0ab54..a4d292a 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -35,8 +35,7 @@ get_all_wallets_for_path, ) from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class OverviewCommand: @@ -80,7 +79,6 @@ class OverviewCommand: @staticmethod def run(cli: "cybertensor.cli"): r"""Prints an overview for the wallet's colkey.""" - console = cybertensor.__console__ wallet = Wallet(config=cli.config) cwtensor: "cybertensor.cwtensor" = cybertensor.cwtensor(config=cli.config) diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py index 8a93d70..3454517 100644 --- a/cybertensor/commands/register.py +++ b/cybertensor/commands/register.py @@ -27,8 +27,7 @@ from ..config import Config from .utils import check_netuid_set, check_for_cuda_reg_config from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class RegisterCommand: @@ -70,7 +69,7 @@ def run(cli): # Verify subnet exists if not cwtensor.subnet_exists(netuid=cli.config.netuid): - cybertensor.__console__.print( + console.print( f"[red]Subnet {cli.config.netuid} does not exist[/red]" ) sys.exit(1) @@ -81,7 +80,7 @@ def run(cli): # Check balance is sufficient if balance < current_recycle: - cybertensor.__console__.print( + console.print( f"[red]Insufficient balance {balance} to register neuron. Current recycle is {current_recycle}[/red]" ) sys.exit(1) @@ -172,7 +171,7 @@ def run(cli): # Verify subnet exists if not cwtensor.subnet_exists(netuid=cli.config.netuid): - cybertensor.__console__.print( + console.print( f"[red]Subnet {cli.config.netuid} does not exist[/red]" ) sys.exit(1) diff --git a/cybertensor/commands/root.py b/cybertensor/commands/root.py index 649f0f9..f3a58f2 100644 --- a/cybertensor/commands/root.py +++ b/cybertensor/commands/root.py @@ -30,8 +30,7 @@ from . import defaults from .utils import DelegatesDetails from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class RootRegisterCommand: @@ -190,7 +189,7 @@ def run(cli): table.box = None table.pad_edge = False table.width = None - cybertensor.__console__.print(table) + console.print(table) @staticmethod def add_args(parser: argparse.ArgumentParser): @@ -388,7 +387,7 @@ def run(cli): table.box = None table.pad_edge = False table.width = None - cybertensor.__console__.print(table) + console.print(table) @staticmethod def add_args(parser: argparse.ArgumentParser): diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index 60e436f..4a82b70 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -25,8 +25,7 @@ from ..utils.balance import Balance from .utils import get_hotkey_wallets_for_wallet from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class StakeCommand: @@ -125,13 +124,13 @@ def run(cli): # Hotkey is not registered. if len(hotkeys_to_stake_to) == 1: # Only one hotkey, error - cybertensor.__console__.print( + console.print( f"[red]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Aborting.[/red]" ) return None else: # Otherwise, print warning and skip - cybertensor.__console__.print( + console.print( f"[yellow]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Skipping.[/yellow]" ) continue @@ -162,7 +161,7 @@ def run(cli): if len(final_hotkeys) == 0: # No hotkeys to stake to. - cybertensor.__console__.print( + console.print( "Not enough balance to stake to any hotkeys or max_stake is less than current stake." ) return None @@ -288,8 +287,7 @@ def add_args(cls, parser: argparse.ArgumentParser): from concurrent.futures import ThreadPoolExecutor from .utils import DelegatesDetails from . import defaults - -console = cybertensor.__console__ +from .. import __console__ as console import os from typing import List, Tuple, Optional, Dict @@ -528,7 +526,7 @@ def get_all_wallet_accounts( table.add_row( "", "", value["name"], value["stake"], str(value["rate"]) + "/d" ) - cybertensor.__console__.print(table) + console.print(table) @staticmethod def check_config(config: "Config"): diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py index 4ea4445..4bcd971 100644 --- a/cybertensor/commands/transfer.py +++ b/cybertensor/commands/transfer.py @@ -25,8 +25,7 @@ import cybertensor from . import defaults from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class TransferCommand: @@ -85,9 +84,9 @@ def check_config(config: "Config"): if not config.no_prompt: wallet = Wallet(config=config) cwtensor = cybertensor.cwtensor(config=config) - with cybertensor.__console__.status(":satellite: Checking Balance..."): + with console.status(":satellite: Checking Balance..."): account_balance = cwtensor.get_balance(wallet.coldkeypub.address) - cybertensor.__console__.print( + console.print( "Balance: [green]{}[/green]".format(account_balance) ) @@ -100,12 +99,12 @@ def check_config(config: "Config"): if config.amount <= 0: raise ValueError("Zero or negative amount") except ValueError: - cybertensor.__console__.print( + console.print( f":cross_mark:[red] Invalid GBOOT amount[/red] [bold white]{amount}[/bold white]" ) sys.exit() else: - cybertensor.__console__.print( + console.print( ":cross_mark:[red] Invalid GBOOT amount[/red] [bold white]{}[/bold white]".format( None ) diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py index c44a19d..8e263b0 100644 --- a/cybertensor/commands/unstake.py +++ b/cybertensor/commands/unstake.py @@ -27,8 +27,7 @@ from . import defaults from .utils import get_hotkey_wallets_for_wallet from ..wallet import Wallet - -console = cybertensor.__console__ +from .. import __console__ as console class UnStakeCommand: @@ -248,7 +247,7 @@ def run(cli): if len(final_hotkeys) == 0: # No hotkeys to unstake from. - cybertensor.__console__.print( + console.print( "Not enough stake to unstake from any hotkeys or max_stake is more than current stake." ) return None diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py index 7afc11d..25fc5f6 100644 --- a/cybertensor/commands/utils.py +++ b/cybertensor/commands/utils.py @@ -28,8 +28,7 @@ import cybertensor from .wallets import Wallet from . import defaults - -console = cybertensor.__console__ +from .. import __console__ as console class IntListPrompt(PromptBase): diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index 9dca48d..e0842b4 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -27,6 +27,7 @@ import cybertensor from . import defaults from ..wallet import Wallet +from .. import __console__ as console # TODO rewrite to use raw pubkey against hex or rewrite keypair/keyfile to use hex @@ -805,7 +806,7 @@ def run(cli): table.box = None table.pad_edge = False table.width = None - cybertensor.__console__.print(table) + console.print(table) @staticmethod def add_args(parser: argparse.ArgumentParser): diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index 91a10b1..f9da5c7 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -37,16 +37,18 @@ from termcolor import colored import cybertensor +from .keypair import Keypair +from . import __console__ as console from . import __chain_address_prefix__ from .errors import KeyFileError NACL_SALT = b"\x13q\x83\xdf\xf1Z\t\xbc\x9c\x90\xb5Q\x879\xe9\xb1" -def serialized_keypair_to_keyfile_data(keypair: "cybertensor.Keypair") -> bytes: +def serialized_keypair_to_keyfile_data(keypair: "Keypair") -> bytes: """Serializes keypair object into keyfile data. Args: - keypair (cybertensor.Keypair): The keypair object to be serialized. + keypair (Keypair): The keypair object to be serialized. Returns: data (bytes): Serialized keypair data. """ @@ -59,12 +61,12 @@ def serialized_keypair_to_keyfile_data(keypair: "cybertensor.Keypair") -> bytes: return data -def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "cybertensor.Keypair": +def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "Keypair": """Deserializes Keypair object from passed keyfile data. Args: keyfile_data (bytes): The keyfile data as bytes to be loaded. Returns: - keypair (cybertensor.Keypair): The Keypair loaded from bytes. + keypair (Keypair): The Keypair loaded from bytes. Raises: KeyFileError: Raised if the passed bytes cannot construct a keypair object. """ @@ -78,13 +80,13 @@ def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "cybertensor.K ) if "secretPhrase" in keyfile_dict and keyfile_dict["secretPhrase"] is not None: - return cybertensor.Keypair.create_from_mnemonic( + return Keypair.create_from_mnemonic( mnemonic=keyfile_dict["secretPhrase"], prefix=__chain_address_prefix__, ) if "address" in keyfile_dict and keyfile_dict["address"] is not None: - return cybertensor.Keypair( + return Keypair( address=keyfile_dict["address"], public_key=keyfile_dict["publicKey"] ) @@ -198,7 +200,6 @@ def keyfile_data_encryption_method(keyfile_data: bytes) -> bool: def legacy_encrypt_keyfile_data(keyfile_data: bytes, password: str = None) -> bytes: password = ask_password_to_encrypt() if password is None else password - console = cybertensor.__console__ with console.status( ":exclamation_mark: Encrypting key with legacy encrpytion method..." ): @@ -267,7 +268,6 @@ def decrypt_keyfile_data( if password is None else password ) - console = cybertensor.__console__ with console.status(":key: Decrypting key..."): # NaCl SecretBox decrypt. if keyfile_data_is_encrypted_nacl(keyfile_data): @@ -340,10 +340,10 @@ def __repr__(self): return self.__str__() @property - def keypair(self) -> "cybertensor.Keypair": + def keypair(self) -> "Keypair": """Returns the keypair from path, decrypts data if the file is encrypted. Returns: - keypair (cybertensor.Keypair): The keypair stored under the path. + keypair (Keypair): The keypair stored under the path. Raises: KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect. """ @@ -371,14 +371,14 @@ def keyfile_data(self) -> bytes: def set_keypair( self, - keypair: "cybertensor.Keypair", + keypair: "Keypair", encrypt: bool = True, overwrite: bool = False, password: str = None, ): """Writes the keypair to the file and optionally encrypts data. Args: - keypair (cybertensor.Keypair): The keypair to store under the path. + keypair (Keypair): The keypair to store under the path. encrypt (bool, optional): If True, encrypts the file under the path. Default is True. overwrite (bool, optional): If True, forces overwrite of the current file. Default is False. password (str, optional): The password used to encrypt the file. If None, asks for user input. @@ -391,12 +391,12 @@ def set_keypair( keyfile_data = cybertensor.encrypt_keyfile_data(keyfile_data, password) self._write_keyfile_data_to_file(keyfile_data, overwrite=overwrite) - def get_keypair(self, password: str = None) -> "cybertensor.Keypair": + def get_keypair(self, password: str = None) -> "Keypair": """Returns the keypair from the path, decrypts data if the file is encrypted. Args: password (str, optional): The password used to decrypt the file. If None, asks for user input. Returns: - keypair (cybertensor.Keypair): The keypair stored under the path. + keypair (Keypair): The keypair stored under the path. Raises: KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect. """ @@ -481,15 +481,15 @@ def check_and_update_encryption( """ if not self.exists_on_device(): if print_result: - cybertensor.__console__.print(f"Keyfile does not exist. {self.path}") + console.print(f"Keyfile does not exist. {self.path}") return False if not self.is_readable(): if print_result: - cybertensor.__console__.print(f"Keyfile is not redable. {self.path}") + console.print(f"Keyfile is not redable. {self.path}") return False if not self.is_writable(): if print_result: - cybertensor.__console__.print(f"Keyfile is not writable. {self.path}") + console.print(f"Keyfile is not writable. {self.path}") return False update_keyfile = False @@ -501,14 +501,14 @@ def check_and_update_encryption( keyfile_data ) and not keyfile_data_is_encrypted_nacl(keyfile_data): terminate = False - cybertensor.__console__.print( + console.print( f"You may update the keyfile to improve the security for storing your keys.\nWhile the key and the password stays the same, it would require providing your password once.\n:key:{self}\n" ) update_keyfile = Confirm.ask("Update keyfile?") if update_keyfile: stored_mnemonic = False while not stored_mnemonic: - cybertensor.__console__.print( + console.print( f"\nPlease make sure you have the mnemonic stored in case an error occurs during the transfer.", style="white on red", ) @@ -547,19 +547,19 @@ def check_and_update_encryption( keyfile_data = self._read_keyfile_data_from_file() if not keyfile_data_is_encrypted(keyfile_data): if print_result: - cybertensor.__console__.print( + console.print( f"\nKeyfile is not encrypted. \n:key: {self}" ) return False elif keyfile_data_is_encrypted_nacl(keyfile_data): if print_result: - cybertensor.__console__.print( + console.print( f"\n:white_heavy_check_mark: Keyfile is updated. \n:key: {self}" ) return True else: if print_result: - cybertensor.__console__.print( + console.print( f'\n:cross_mark: Keyfile is outdated, please update with "ctcli wallet update" \n:key: {self}' ) return False @@ -701,7 +701,7 @@ def keypair(self): Returns the mock keypair stored in the keyfile. Returns: - cybertensor.Keypair: The mock keypair. + Keypair: The mock keypair. """ return self._mock_keypair @@ -720,7 +720,7 @@ def set_keypair(self, keypair, encrypt=True, overwrite=False, password=None): Sets the mock keypair in the keyfile. The `encrypt` and `overwrite` parameters are ignored. Args: - keypair (cybertensor.Keypair): The mock keypair to be set. + keypair (Keypair): The mock keypair to be set. encrypt (bool, optional): Ignored in this context. Defaults to True. overwrite (bool, optional): Ignored in this context. Defaults to False. password (str, optional): Ignored in this context. Defaults to None. @@ -736,7 +736,7 @@ def get_keypair(self, password=None): password (str, optional): Ignored in this context. Defaults to None. Returns: - cybertensor.Keypair: The mock keypair stored in the keyfile. + Keypair: The mock keypair stored in the keyfile. """ return self._mock_keypair diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py index 3b7962e..a785541 100644 --- a/cybertensor/messages/delegation.py +++ b/cybertensor/messages/delegation.py @@ -26,6 +26,7 @@ import cybertensor from ..utils.balance import Balance from ..errors import * +from .. import __console__ as console logger = logger.opt(colors=True) @@ -54,7 +55,7 @@ def nominate_message( ) return False - with cybertensor.__console__.status( + with console.status( f":satellite: Sending nominate call on [white]{cwtensor.network}[/white] ..." ): try: @@ -64,7 +65,7 @@ def nominate_message( ) if success is True: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) cybertensor.logging.success( @@ -76,14 +77,14 @@ def nominate_message( return success except Exception as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{e}" ) # cybertensor.logging.warning( # prefix="Set weights", sufix=f"Failed: {e}" # ) except NominationError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{e}" ) # cybertensor.logging.warning( @@ -155,7 +156,7 @@ def delegate_message( # Check enough balance to stake. if staking_balance > my_prev_coldkey_balance: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough balance[/red]:[bold white]\n" f" balance:{my_prev_coldkey_balance}\n" f" amount: {staking_balance}\n" @@ -174,7 +175,7 @@ def delegate_message( return False try: - with cybertensor.__console__.status( + with console.status( f":satellite: Staking to: [bold white]{cwtensor.network}[/bold white] ..." ): staking_response: bool = cwtensor._do_delegation( @@ -189,10 +190,10 @@ def delegate_message( if not wait_for_finalization: return True - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(address=wallet.coldkey.address) @@ -203,27 +204,27 @@ def delegate_message( block=block, ) # Get current stake - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{my_prev_coldkey_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) - cybertensor.__console__.print( + console.print( f"Stake:\n [blue]{my_prev_delegated_stake}[/blue] :arrow_right: [green]{new_delegate_stake}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) return False except NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]" ) return False except StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") return False @@ -285,7 +286,7 @@ def undelegate_message( # Check enough stake to unstake. if unstaking_balance > my_prev_delegated_stake: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough delegated stake[/red]:[bold white]\n" f" stake:{my_prev_delegated_stake}\n" f" amount: {unstaking_balance}\n" @@ -304,7 +305,7 @@ def undelegate_message( return False try: - with cybertensor.__console__.status( + with console.status( f":satellite: Unstaking from: [bold white]{cwtensor.network}[/bold white] ..." ): staking_response: bool = cwtensor._do_undelegation( @@ -319,10 +320,10 @@ def undelegate_message( if not wait_for_finalization: return True - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(address=wallet.coldkey.address) @@ -333,26 +334,26 @@ def undelegate_message( block=block, ) # Get current stake - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{my_prev_coldkey_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) - cybertensor.__console__.print( + console.print( f"Stake:\n" f" [blue]{my_prev_delegated_stake}[/blue] :arrow_right: [green]{new_delegate_stake}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) return False except NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]" ) return False except StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") return False diff --git a/cybertensor/messages/network.py b/cybertensor/messages/network.py index 39b26a4..a7f2524 100644 --- a/cybertensor/messages/network.py +++ b/cybertensor/messages/network.py @@ -24,6 +24,7 @@ import cybertensor from ..utils.balance import Balance from ..wallet import Wallet +from .. import __console__ as console def register_subnetwork_message( @@ -51,14 +52,14 @@ def register_subnetwork_message( your_balance = cwtensor.get_balance(wallet.coldkeypub.address) burn_cost = Balance(cwtensor.get_subnet_burn_cost()) if burn_cost > your_balance: - cybertensor.__console__.print( + console.print( f"Your balance of: [green]{your_balance}[/green] is not enough to pay the subnet lock cost of: " f"[green]{burn_cost}[/green]" ) return False if prompt: - cybertensor.__console__.print(f"Your balance is: [green]{your_balance}[/green]") + console.print(f"Your balance is: [green]{your_balance}[/green]") if not Confirm.ask( f"Do you want to register a subnet for [green]{burn_cost}[/green]?" ): @@ -66,7 +67,7 @@ def register_subnetwork_message( wallet.coldkey # unlock coldkey - with cybertensor.__console__.status(":satellite: Registering subnet..."): + with console.status(":satellite: Registering subnet..."): create_register_network_msg = {"register_network": {}} signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), cwtensor.address_prefix @@ -78,7 +79,7 @@ def register_subnetwork_message( tx = cwtensor.contract.execute( create_register_network_msg, signer_wallet, gas, funds ) - cybertensor.__console__.print( + console.print( f":exclamation_mark: [yellow]Warning[/yellow]: TX {tx.tx_hash} broadcasted without finalization " f"confirmation..." ) @@ -86,25 +87,25 @@ def register_subnetwork_message( tx = cwtensor.contract.execute( create_register_network_msg, signer_wallet, gas, funds ) - cybertensor.__console__.print( + console.print( f":satellite: [green]Processing..[/green]: TX {tx.tx_hash} waiting to complete..." ) try: tx.wait_to_complete() if tx.response.is_successful(): - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Registered subnetwork with netuid: " f"{tx.response.events.get('wasm').get('netuid_to_register')}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{tx.response.raw_log}" ) time.sleep(0.5) return False except Exception as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{e}" ) return False @@ -146,7 +147,7 @@ def set_hyperparameter_message( """ if cwtensor.get_subnet_owner(netuid) != wallet.coldkeypub.address: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]This wallet doesn't own the specified subnet.[/red]" ) return False @@ -155,12 +156,12 @@ def set_hyperparameter_message( message = HYPERPARAMS.get(parameter) if message is None: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Invalid hyperparameter specified.[/red]" ) return False - with cybertensor.__console__.status( + with console.status( f":satellite: Setting hyperparameter {parameter} to {value} on subnet: {netuid} ..." ): sudo_msg = { @@ -173,29 +174,29 @@ def set_hyperparameter_message( if not wait_for_finalization: tx = cwtensor.contract.execute(sudo_msg, signer_wallet, gas) - cybertensor.__console__.print( + console.print( f":exclamation_mark: [yellow]Warning[/yellow]: TX {tx.tx_hash} broadcasted without confirmation..." ) else: tx = cwtensor.contract.execute(sudo_msg, signer_wallet, gas) - cybertensor.__console__.print( + console.print( f":satellite: [green]Processing..[/green]: TX {tx.tx_hash} waiting to complete..." ) try: tx.wait_to_complete() if tx.response.is_successful(): - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Hyper parameter {parameter} changed to {value}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{tx.response.raw_log}" ) time.sleep(0.5) return False except Exception as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{e}" ) return False diff --git a/cybertensor/messages/prometheus.py b/cybertensor/messages/prometheus.py index ec667fe..8737d7b 100644 --- a/cybertensor/messages/prometheus.py +++ b/cybertensor/messages/prometheus.py @@ -24,6 +24,7 @@ from ..wallet import Wallet from ..utils import networking as net from ..types import PrometheusServeCallParams +from .. import __console__ as console def prometheus_message( @@ -59,7 +60,7 @@ def prometheus_message( if ip is None: try: external_ip = net.get_external_ip() - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]" ) cybertensor.logging.success( @@ -79,7 +80,7 @@ def prometheus_message( "ip_type": net.ip_version(external_ip), } - with cybertensor.__console__.status(":satellite: Checking Prometheus..."): + with console.status(":satellite: Checking Prometheus..."): neuron = cwtensor.get_neuron_for_pubkey_and_subnet( wallet.hotkey.address, netuid=netuid ) @@ -91,7 +92,7 @@ def prometheus_message( } if neuron_up_to_date: - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Prometheus already Served[/green]\n" f"[green not bold]- Status: [/green not bold] |" f"[green not bold] ip: [/green not bold][white not bold]{net.int_to_ip(neuron.prometheus_info.ip)}[/white not bold] |" @@ -100,7 +101,7 @@ def prometheus_message( f"[green not bold] version: [/green not bold][white not bold]{neuron.prometheus_info.version}[/white not bold] |" ) - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [white]Prometheus already served.[/white] {external_ip}" ) return True @@ -108,7 +109,7 @@ def prometheus_message( # Add netuid, not in prometheus_info call_params["netuid"] = netuid - with cybertensor.__console__.status( + with console.status( f":satellite: Serving prometheus on: [white]{cwtensor.network}:{netuid}[/white] ..." ): success, err = cwtensor._do_serve_prometheus( @@ -119,13 +120,13 @@ def prometheus_message( if wait_for_finalization: if success is True: - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Served prometheus[/green]\n" f" [bold white]{json.dumps(call_params, indent=4, sort_keys=True)}[/bold white]" ) return True else: - cybertensor.__console__.print( + console.print( f":cross_mark: [green]Failed to serve prometheus[/green] error: {err}" ) return False diff --git a/cybertensor/messages/registration.py b/cybertensor/messages/registration.py index 72ed393..201bfa7 100644 --- a/cybertensor/messages/registration.py +++ b/cybertensor/messages/registration.py @@ -27,6 +27,7 @@ from ..utils.balance import Balance from ..utils.registration import POWSolution, create_pow from ..wallet import Wallet +from .. import __console__ as console def register_message( @@ -75,12 +76,12 @@ def register_message( If we did not wait for finalization / inclusion, the response is true. """ if not cwtensor.subnet_exists(netuid): - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist." ) return False - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..." ): neuron = cwtensor.get_neuron_for_pubkey_and_subnet( @@ -104,14 +105,14 @@ def register_message( # Attempt rolling registration. attempts = 1 while True: - cybertensor.__console__.print( + console.print( f":satellite: Registering...({attempts}/{max_allowed_attempts})" ) # Solve latest POW. if cuda: if not torch.cuda.is_available(): if prompt: - cybertensor.__console__.error("CUDA is not available.") + console.error("CUDA is not available.") return False pow_result: Optional[POWSolution] = create_pow( cwtensor, @@ -144,14 +145,14 @@ def register_message( netuid=netuid, hotkey=wallet.hotkey.address ) if is_registered: - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Already registered on netuid:{netuid}[/green]" ) return True # pow successful, proceed to submit pow to chain for registration else: - with cybertensor.__console__.status(":satellite: Submitting POW..."): + with console.status(":satellite: Submitting POW..."): # check if pow result is still valid while not pow_result.is_stale(cwtensor=cwtensor): result: Tuple[bool, Optional[str]] = cwtensor._do_pow_register( @@ -165,48 +166,48 @@ def register_message( if success != True or success is False: if "key is already registered" in err_msg: # Error meant that the key is already registered. - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Already Registered on [bold]subnet:{netuid}[/bold][/green]" ) return True - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{err_msg}" ) time.sleep(0.5) # Successful registration, final check for neuron and pubkey else: - cybertensor.__console__.print(":satellite: Checking Balance...") + console.print(":satellite: Checking Balance...") is_registered = cwtensor.is_hotkey_registered( netuid=netuid, hotkey=wallet.hotkey.address ) if is_registered: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Registered[/green]" ) return True else: # neuron not found, try again - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Unknown error. Neuron not found.[/red]" ) continue else: # Exited loop because pow is no longer valid. - cybertensor.__console__.print("[red]POW is stale.[/red]") + console.print("[red]POW is stale.[/red]") # Try again. continue if attempts < max_allowed_attempts: # Failed registration, retry pow attempts += 1 - cybertensor.__console__.print( + console.print( f":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})" ) else: # Failed to register after max attempts. - cybertensor.__console__.print("[red]No more attempts.[/red]") + console.print("[red]No more attempts.[/red]") return False @@ -234,13 +235,13 @@ def burned_register_message( If we did not wait for finalization / inclusion, the response is true. """ if not cwtensor.subnet_exists(netuid): - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist." ) return False wallet.coldkey # unlock coldkey - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..." ): neuron = cwtensor.get_neuron_for_pubkey_and_subnet( @@ -251,7 +252,7 @@ def burned_register_message( burn_amount = Balance(cwtensor.burn(netuid=netuid)) if not neuron.is_null: - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Already Registered[/green]:\n" f"uid: [bold white]{neuron.uid}[/bold white]\n" f"netuid: [bold white]{neuron.netuid}[/bold white]\n" @@ -265,7 +266,7 @@ def burned_register_message( if not Confirm.ask(f"Recycle {burn_amount} to register on subnet:{netuid}?"): return False - with cybertensor.__console__.status(":satellite: Recycling BOOT for Registration..."): + with console.status(":satellite: Recycling BOOT for Registration..."): success, err_msg = cwtensor._do_burned_register( netuid=netuid, burn=burn_amount.__int__(), @@ -274,19 +275,19 @@ def burned_register_message( ) if success is not True: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{err_msg}" ) time.sleep(0.5) # Successful registration, final check for neuron and pubkey else: - cybertensor.__console__.print(":satellite: Checking Balance...") + console.print(":satellite: Checking Balance...") new_balance = cwtensor.get_balance( wallet.coldkeypub.address ) - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) @@ -294,13 +295,13 @@ def burned_register_message( netuid=netuid, hotkey=wallet.hotkey.address ) if is_registered: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Registered[/green]" ) return True else: # neuron not found, try again - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Unknown error. Neuron not found.[/red]" ) diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index 32155ce..2d84b93 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -25,7 +25,8 @@ from rich.prompt import Confirm import cybertensor -import cybertensor.utils.weight_utils as weight_utils +from ..utils import weight_utils +from .. import __console__ as console logger = logger.opt(colors=True) @@ -57,7 +58,7 @@ def root_register_message( netuid=0, hotkey=wallet.hotkey.address ) if is_registered: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Already registered on root network.[/green]" ) return True @@ -67,14 +68,14 @@ def root_register_message( if not Confirm.ask("Register to root network?"): return False - with cybertensor.__console__.status(":satellite: Registering to root network..."): + with console.status(":satellite: Registering to root network..."): success, err_msg = cwtensor._do_root_register( wallet=wallet, wait_for_finalization=wait_for_finalization, ) if success != True or success is False: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{err_msg}" ) time.sleep(0.5) @@ -85,13 +86,13 @@ def root_register_message( netuid=0, hotkey=wallet.hotkey.address ) if is_registered: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Registered[/green]" ) return True else: # neuron not found, try again - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Unknown error. Neuron not found.[/red]" ) @@ -149,7 +150,7 @@ def set_root_weights_message( formatted_weights = cybertensor.utils.weight_utils.normalize_max_weight( x=weights, limit=max_weight_limit ) - cybertensor.__console__.print( + console.print( f"\nNormalized weights: \n\t{weights} -> {formatted_weights}\n" ) @@ -162,7 +163,7 @@ def set_root_weights_message( ): return False - with cybertensor.__console__.status( + with console.status( f":satellite: Setting root weights on [white]{cwtensor.network}[/white] ..." ): try: @@ -178,13 +179,13 @@ def set_root_weights_message( wait_for_finalization=wait_for_finalization, ) - cybertensor.__console__.print(success, error_message) + console.print(success, error_message) if not wait_for_finalization: return True if success is True: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) cybertensor.logging.success( @@ -193,7 +194,7 @@ def set_root_weights_message( ) return True else: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{error_message}" ) cybertensor.logging.warning( @@ -204,7 +205,7 @@ def set_root_weights_message( except Exception as e: # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru. - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{e}" ) cybertensor.logging.warning( diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py index b95434d..56cfcf0 100644 --- a/cybertensor/messages/serving.py +++ b/cybertensor/messages/serving.py @@ -23,6 +23,7 @@ import cybertensor from ..utils import networking as net from ..types import AxonServeCallParams +from .. import __console__ as console def serve_message( @@ -167,7 +168,7 @@ def serve_axon_message( if axon.external_ip is None: try: external_ip = net.get_external_ip() - cybertensor.__console__.print( + console.print( f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]" ) cybertensor.logging.success( diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index 8acf8d4..72da9cb 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -24,7 +24,8 @@ from rich.prompt import Confirm import cybertensor -import cybertensor.utils.weight_utils as weight_utils +from ..utils import weight_utils +from .. import __console__ as console logger = logger.opt(colors=True) @@ -81,7 +82,7 @@ def set_weights_message( ): return False - with cybertensor.__console__.status( + with console.status( f":satellite: Setting weights on [white]{cwtensor.network}[/white] ..." ): try: @@ -98,7 +99,7 @@ def set_weights_message( return True if success is True: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) cybertensor.logging.success( @@ -107,7 +108,7 @@ def set_weights_message( ) return True else: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{error_message}", ) cybertensor.logging.warning( @@ -118,7 +119,7 @@ def set_weights_message( except Exception as e: # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru. - cybertensor.__console__.print(f":cross_mark: [red]Failed[/red]: error:{e}") + console.print(f":cross_mark: [red]Failed[/red]: error:{e}") cybertensor.logging.warning( prefix="Set weights", sufix=f"Failed: {e}" ) diff --git a/cybertensor/messages/staking.py b/cybertensor/messages/staking.py index 7020cee..ed0d644 100644 --- a/cybertensor/messages/staking.py +++ b/cybertensor/messages/staking.py @@ -25,6 +25,7 @@ import cybertensor from ..utils.balance import Balance from ..wallet import Wallet +from .. import __console__ as console def add_stake_message( @@ -70,7 +71,7 @@ def add_stake_message( # Flag to indicate if we are using the wallet's own hotkey. own_hotkey: bool - with cybertensor.__console__.status( + with console.status( f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..." ): old_balance = cwtensor.get_balance(wallet.coldkeypub.address) @@ -109,7 +110,7 @@ def add_stake_message( # Check enough to stake. if staking_balance > old_balance: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough stake[/red]:[bold white]\n" f" balance:{old_balance}\n" f" amount: {staking_balance}\n" @@ -138,7 +139,7 @@ def add_stake_message( return False try: - with cybertensor.__console__.status( + with console.status( f":satellite: Staking to: [bold white]{cwtensor.network}[/bold white] ..." ): staking_response: bool = __do_add_stake_single( @@ -154,10 +155,10 @@ def add_stake_message( if not wait_for_finalization: return True - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(address=wallet.coldkeypub.address) @@ -168,28 +169,28 @@ def add_stake_message( block=block, ) # Get current stake - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) - cybertensor.__console__.print( + console.print( f"Stake:\n" f" [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) return False except cybertensor.errors.NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]" ) return False except cybertensor.errors.StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") return False @@ -257,7 +258,7 @@ def add_stake_multiple_message( wallet.coldkey old_stakes = [] - with cybertensor.__console__.status( + with console.status( f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..." ): old_balance = cwtensor.get_balance(wallet.coldkeypub.address) @@ -308,7 +309,7 @@ def add_stake_multiple_message( # Check enough to stake if staking_balance > old_balance: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough balance[/red]: [green]{old_balance}[/green] " f"to stake: [blue]{staking_balance}[/blue] from coldkey: [white]{wallet.name}[/white]" ) @@ -339,7 +340,7 @@ def add_stake_multiple_message( # Wait for tx rate limit. tx_rate_limit_blocks = cwtensor.tx_rate_limit() if tx_rate_limit_blocks > 0: - cybertensor.__console__.print( + console.print( f":hourglass: [yellow]Waiting for tx rate limit: [white]{tx_rate_limit_blocks}[/white] " f"blocks[/yellow]" ) @@ -354,7 +355,7 @@ def add_stake_multiple_message( continue - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) @@ -367,7 +368,7 @@ def add_stake_multiple_message( new_balance = cwtensor.get_balance( wallet.coldkeypub.address, block=block ) - cybertensor.__console__.print( + console.print( f"Stake ({hotkey}): [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]" ) old_balance = new_balance @@ -377,26 +378,26 @@ def add_stake_multiple_message( break else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) continue except cybertensor.errors.NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Hotkey: {hotkey} is not registered.[/red]" ) continue except cybertensor.errors.StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") continue if successful_stakes != 0: - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: ([white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(wallet.coldkeypub.address) - cybertensor.__console__.print( + console.print( f"Balance: [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) return True diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py index 63f177a..4e264db 100644 --- a/cybertensor/messages/transfer.py +++ b/cybertensor/messages/transfer.py @@ -27,6 +27,7 @@ from ..utils import is_valid_address from ..utils.balance import Balance from ..wallet import Wallet +from .. import __console__ as console def transfer_message( @@ -64,7 +65,7 @@ def transfer_message( """ # Validate destination address. if not is_valid_address(dest): - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {dest}[/bold white]" ) return False @@ -79,12 +80,12 @@ def transfer_message( transfer_balance = amount # Check balance. - with cybertensor.__console__.status(":satellite: Checking Balance..."): + with console.status(":satellite: Checking Balance..."): account_balance = cwtensor.get_balance(wallet.coldkey.address) # check existential deposit. existential_deposit = cwtensor.get_existential_deposit() - with cybertensor.__console__.status(":satellite: Transferring..."): + with console.status(":satellite: Transferring..."): fee = cwtensor.get_transfer_fee() if not keep_alive: @@ -93,7 +94,7 @@ def transfer_message( # Check if we have enough balance. if account_balance < (transfer_balance + fee + existential_deposit): - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough balance[/red]:[bold white]\n" f" balance: {account_balance}\n" f" amount: {transfer_balance}\n" @@ -112,7 +113,7 @@ def transfer_message( ): return False - with cybertensor.__console__.status(":satellite: Transferring..."): + with console.status(":satellite: Transferring..."): success, tx_hash, err_msg = cwtensor._do_transfer( wallet, Address(dest), @@ -122,27 +123,27 @@ def transfer_message( ) if success: - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - cybertensor.__console__.print(f"[green]Tx Hash: {tx_hash}[/green]") + console.print(f"[green]Tx Hash: {tx_hash}[/green]") explorer_url = cybertensor.utils.get_explorer_url_for_network( cwtensor.network, tx_hash, cwtensor.network_explorer ) if explorer_url is not None: - cybertensor.__console__.print( + console.print( f"[green]Explorer Link: {explorer_url}[/green]" ) else: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Failed[/red]: error:{err_msg}" ) if success: - with cybertensor.__console__.status(":satellite: Checking Balance..."): + with console.status(":satellite: Checking Balance..."): new_balance = cwtensor.get_balance(wallet.coldkey.address) - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{account_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) diff --git a/cybertensor/messages/unstaking.py b/cybertensor/messages/unstaking.py index 4560625..8494282 100644 --- a/cybertensor/messages/unstaking.py +++ b/cybertensor/messages/unstaking.py @@ -25,6 +25,7 @@ import cybertensor from ..utils.balance import Balance from ..wallet import Wallet +from .. import __console__ as console def __do_remove_stake_single( @@ -105,7 +106,7 @@ def unstake_message( if hotkey is None: hotkey = wallet.hotkey.address # Default to wallet's own hotkey. - with cybertensor.__console__.status( + with console.status( f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..." ): old_balance = cwtensor.get_balance(wallet.coldkeypub.address) @@ -125,7 +126,7 @@ def unstake_message( # Check enough to unstake. stake_on_uid = old_stake if unstaking_balance > stake_on_uid: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough stake[/red]: [green]{stake_on_uid}[/green] " f"to unstake: [blue]{unstaking_balance}[/blue] from hotkey: [white]{wallet.hotkey_str}[/white]" ) @@ -141,7 +142,7 @@ def unstake_message( return False try: - with cybertensor.__console__.status( + with console.status( f":satellite: Unstaking from chain: [white]{cwtensor.network}[/white] ..." ): staking_response: bool = __do_remove_stake_single( @@ -157,38 +158,38 @@ def unstake_message( if not wait_for_finalization: return True - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(address=wallet.coldkeypub.address) new_stake = cwtensor.get_stake_for_coldkey_and_hotkey( coldkey=wallet.coldkeypub.address, hotkey=hotkey ) # Get stake on hotkey. - cybertensor.__console__.print( + console.print( f"Balance:\n" f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) - cybertensor.__console__.print( + console.print( f"Stake:\n" f" [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]" ) return True else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) return False except cybertensor.errors.NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]" ) return False except cybertensor.errors.StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") return False @@ -256,7 +257,7 @@ def unstake_multiple_message( wallet.coldkey old_stakes = [] - with cybertensor.__console__.status( + with console.status( f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..." ): old_balance = cwtensor.get_balance(wallet.coldkeypub.address) @@ -281,7 +282,7 @@ def unstake_multiple_message( # Check enough to unstake. stake_on_uid = old_stake if unstaking_balance > stake_on_uid: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]Not enough stake[/red]: [green]{stake_on_uid}[/green] " f"to unstake: [blue]{unstaking_balance}[/blue] from hotkey: [white]{wallet.hotkey_str}[/white]" ) @@ -297,7 +298,7 @@ def unstake_multiple_message( continue try: - with cybertensor.__console__.status( + with console.status( f":satellite: Unstaking from chain: [white]{cwtensor.network}[/white] ..." ): staking_response: bool = __do_remove_stake_single( @@ -315,7 +316,7 @@ def unstake_multiple_message( # Wait for tx rate limit. tx_rate_limit_blocks = cwtensor.tx_rate_limit() if tx_rate_limit_blocks > 0: - cybertensor.__console__.print( + console.print( f":hourglass: [yellow]Waiting for tx rate limit: " f"[white]{tx_rate_limit_blocks}[/white] blocks[/yellow]" ) @@ -325,10 +326,10 @@ def unstake_multiple_message( successful_unstakes += 1 continue - cybertensor.__console__.print( + console.print( ":white_heavy_check_mark: [green]Finalized[/green]" ) - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..." ): block = cwtensor.get_current_block() @@ -337,31 +338,31 @@ def unstake_multiple_message( hotkey=hotkey, block=block, ) - cybertensor.__console__.print( + console.print( f"Stake ({hotkey}): [blue]{stake_on_uid}[/blue] :arrow_right: [green]{new_stake}[/green]" ) successful_unstakes += 1 else: - cybertensor.__console__.print( + console.print( ":cross_mark: [red]Failed[/red]: Error unknown." ) continue except cybertensor.errors.NotRegisteredError as e: - cybertensor.__console__.print( + console.print( f":cross_mark: [red]{hotkey} is not registered.[/red]" ) continue except cybertensor.errors.StakeError as e: - cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]") + console.print(f":cross_mark: [red]Stake Error: {e}[/red]") continue if successful_unstakes != 0: - with cybertensor.__console__.status( + with console.status( f":satellite: Checking Balance on: ([white]{cwtensor.network}[/white] ..." ): new_balance = cwtensor.get_balance(wallet.coldkeypub.address) - cybertensor.__console__.print( + console.print( f"Balance: [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" ) return True diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py index 95206d6..61e749f 100644 --- a/cybertensor/utils/registration.py +++ b/cybertensor/utils/registration.py @@ -20,6 +20,7 @@ from ..wallet import Wallet from ._register_cuda import solve_cuda from .formatting import get_human_readable, millify +from .. import __console__ as console class CUDAException(Exception): @@ -579,7 +580,6 @@ def _solve_for_difficulty_fast( start_time_perpetual = time.time() - console = cybertensor.__console__ logger = RegistrationStatisticsLogger(console, output_in_place) logger.start() @@ -927,7 +927,6 @@ def _solve_for_difficulty_fast_cuda( start_time_perpetual = time.time() - console = cybertensor.__console__ logger = RegistrationStatisticsLogger(console, output_in_place) logger.start() From 8bee2047a2fc7d6a6f790bcff686f00079bdab69 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 3 Feb 2024 17:34:19 +0800 Subject: [PATCH 03/23] - remove ProcessPoolExecutor to fix the protobuf import issue --- cybertensor/commands/overview.py | 58 ++++++++++---------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index a4d292a..e7a9034 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -18,7 +18,6 @@ import argparse from collections import defaultdict -from concurrent.futures import ProcessPoolExecutor from typing import List, Optional, Dict, Tuple from fuzzywuzzy import fuzz @@ -77,7 +76,7 @@ class OverviewCommand: """ @staticmethod - def run(cli: "cybertensor.cli"): + def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5): r"""Prints an overview for the wallet's colkey.""" wallet = Wallet(config=cli.config) cwtensor: "cybertensor.cwtensor" = cybertensor.cwtensor(config=cli.config) @@ -167,33 +166,22 @@ def run(cli: "cybertensor.cli"): ) ) ): - # Create a copy of the config without the parser and formatter_class. - ## This is needed to pass to the ProcessPoolExecutor, which cannot pickle the parser. - copy_config = cli.config.copy() - copy_config["__parser"] = None - copy_config["formatter_class"] = None # Pull neuron info for all keys. ## Max len(netuids) or 5 threads. - with ProcessPoolExecutor(max_workers=max(len(netuids), 5)) as executor: - results = executor.map( - OverviewCommand._get_neurons_for_netuid, - [(copy_config, netuid, all_hotkey_addresses) for netuid in netuids], - ) - executor.shutdown(wait=True) # wait for all complete - - for result in results: - netuid, neurons_result, err_msg = result - if err_msg is not None: - console.print(err_msg) - if len(neurons_result) == 0: - # Remove netuid from overview if no neurons are found. - netuids.remove(netuid) - del neurons[str(netuid)] - else: - # Add neurons to overview. - neurons[str(netuid)] = neurons_result + for netuid in netuids[:max_len_netuids]: + netuid, neurons_result, err_msg = \ + OverviewCommand._get_neurons_for_netuid((cli.config, netuid, all_hotkey_addresses)) + if err_msg is not None: + console.print(err_msg) + if len(neurons_result) == 0: + # Remove netuid from overview if no neurons are found. + netuids.remove(netuid) + del neurons[str(netuid)] + else: + # Add neurons to overview. + neurons[str(netuid)] = neurons_result total_coldkey_stake_from_metagraph = defaultdict( lambda: cybertensor.Balance(0.0) @@ -238,21 +226,11 @@ def run(cli: "cybertensor.cli"): if "-1" not in neurons: neurons["-1"] = [] - # Use process pool to check each coldkey wallet for de-registered stake. - with ProcessPoolExecutor( - max_workers=max(len(coldkeys_to_check), 5) - ) as executor: - results = executor.map( - OverviewCommand._get_de_registered_stake_for_coldkey_wallet, - [ - (cli.config, all_hotkey_addresses, coldkey_wallet) - for coldkey_wallet in coldkeys_to_check - ], - ) - executor.shutdown(wait=True) # wait for all complete + for coldkey_wallet in coldkeys_to_check: + coldkey_wallet, de_registered_stake, err_msg = \ + OverviewCommand._get_de_registered_stake_for_coldkey_wallet( + (cli.config, all_hotkey_addresses, coldkey_wallet)) - for result in results: - coldkey_wallet, de_registered_stake, err_msg = result if err_msg is not None: console.print(err_msg) @@ -276,7 +254,7 @@ def run(cli: "cybertensor.cli"): name=wallet, ) wallet_.hotkey = hotkey_addr - wallet.hotkey_str = hotkey_addr[:5] # Max length of 5 characters + wallet.hotkey_str = hotkey_addr[:max_len_keys] # Max length of 5 characters hotkey_coldkey_to_hotkey_wallet[hotkey_addr][ coldkey_wallet.coldkeypub.address ] = wallet_ From b1c4c119d8d86c8e3e0d48e38100158b39cf786f Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 3 Feb 2024 22:40:14 +0800 Subject: [PATCH 04/23] - update imports --- cybertensor/commands/delegates.py | 3 ++- cybertensor/commands/inspect.py | 1 + cybertensor/commands/list.py | 1 + cybertensor/commands/metagraph.py | 1 + cybertensor/commands/network.py | 3 ++- cybertensor/commands/overview.py | 1 + cybertensor/commands/register.py | 6 ++--- cybertensor/commands/root.py | 3 ++- cybertensor/commands/stake.py | 13 +++++------ cybertensor/commands/transfer.py | 3 ++- cybertensor/commands/unstake.py | 5 +++-- cybertensor/commands/utils.py | 3 ++- cybertensor/commands/wallets.py | 1 + cybertensor/config.py | 10 ++++----- cybertensor/keyfile.py | 28 +++++++++++------------ cybertensor/messages/delegation.py | 5 +++-- cybertensor/messages/log_utilities.py | 8 ++++--- cybertensor/messages/root.py | 3 ++- cybertensor/messages/serving.py | 7 +++--- cybertensor/messages/set_weights.py | 3 ++- cybertensor/utils/_register_cuda.py | 11 +++++---- cybertensor/utils/registration.py | 8 +++---- cybertensor/utils/stats.py | 6 ++--- cybertensor/wallet.py | 32 +++++++++++++-------------- 24 files changed, 90 insertions(+), 75 deletions(-) diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py index dd204e4..e8f7f26 100644 --- a/cybertensor/commands/delegates.py +++ b/cybertensor/commands/delegates.py @@ -29,9 +29,10 @@ import cybertensor from . import defaults -from ..wallet import Wallet from .utils import DelegatesDetails from .. import __console__ as console +from ..config import Config +from ..wallet import Wallet def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py index 1ae74ea..c02e60b 100644 --- a/cybertensor/commands/inspect.py +++ b/cybertensor/commands/inspect.py @@ -27,6 +27,7 @@ import cybertensor from . import defaults from .utils import get_delegates_details, DelegatesDetails +from ..config import Config from ..wallet import Wallet from .. import __console__ as console diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py index 5a6d7f4..ea322ff 100644 --- a/cybertensor/commands/list.py +++ b/cybertensor/commands/list.py @@ -24,6 +24,7 @@ import cybertensor from ..wallet import Wallet +from ..config import Config class ListCommand: diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py index 17c6e2b..4611880 100644 --- a/cybertensor/commands/metagraph.py +++ b/cybertensor/commands/metagraph.py @@ -23,6 +23,7 @@ import cybertensor from .utils import check_netuid_set from .. import __console__ as console +from ..config import Config # TODO change tokens in table to boot and gigaboot diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py index ea45309..e343045 100644 --- a/cybertensor/commands/network.py +++ b/cybertensor/commands/network.py @@ -27,9 +27,10 @@ import cybertensor from . import defaults -from ..wallet import Wallet from .utils import DelegatesDetails, check_netuid_set from .. import __console__ as console +from ..config import Config +from ..wallet import Wallet class RegisterSubnetworkCommand: diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index e7a9034..a813136 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -33,6 +33,7 @@ get_coldkey_wallets_for_path, get_all_wallets_for_path, ) +from ..config import Config from ..wallet import Wallet from .. import __console__ as console diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py index 3454517..fa58e50 100644 --- a/cybertensor/commands/register.py +++ b/cybertensor/commands/register.py @@ -22,12 +22,12 @@ from rich.prompt import Prompt, Confirm import cybertensor -from ..utils.balance import Balance from . import defaults -from ..config import Config from .utils import check_netuid_set, check_for_cuda_reg_config -from ..wallet import Wallet from .. import __console__ as console +from ..config import Config +from ..utils.balance import Balance +from ..wallet import Wallet class RegisterCommand: diff --git a/cybertensor/commands/root.py b/cybertensor/commands/root.py index f3a58f2..b46f17c 100644 --- a/cybertensor/commands/root.py +++ b/cybertensor/commands/root.py @@ -29,8 +29,9 @@ import cybertensor from . import defaults from .utils import DelegatesDetails -from ..wallet import Wallet from .. import __console__ as console +from ..config import Config +from ..wallet import Wallet class RootRegisterCommand: diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index 4a82b70..c531ee4 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -21,11 +21,9 @@ from rich.prompt import Confirm -import cybertensor -from ..utils.balance import Balance from .utils import get_hotkey_wallets_for_wallet -from ..wallet import Wallet -from .. import __console__ as console +from ..config import Config +from ..utils.balance import Balance class StakeCommand: @@ -278,6 +276,8 @@ def add_args(cls, parser: argparse.ArgumentParser): ### Stake list. +import os +from typing import List, Tuple, Optional, Dict import argparse import cybertensor from tqdm import tqdm @@ -285,13 +285,12 @@ def add_args(cls, parser: argparse.ArgumentParser): from rich.prompt import Prompt from typing import Union from concurrent.futures import ThreadPoolExecutor + from .utils import DelegatesDetails from . import defaults +from ..wallet import Wallet from .. import __console__ as console -import os -from typing import List, Tuple, Optional, Dict - def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: try: diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py index 4bcd971..7cebeda 100644 --- a/cybertensor/commands/transfer.py +++ b/cybertensor/commands/transfer.py @@ -24,8 +24,9 @@ import cybertensor from . import defaults -from ..wallet import Wallet from .. import __console__ as console +from ..config import Config +from ..wallet import Wallet class TransferCommand: diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py index 8e263b0..413ecef 100644 --- a/cybertensor/commands/unstake.py +++ b/cybertensor/commands/unstake.py @@ -23,11 +23,12 @@ from tqdm import tqdm import cybertensor -from ..utils.balance import Balance from . import defaults from .utils import get_hotkey_wallets_for_wallet -from ..wallet import Wallet from .. import __console__ as console +from ..config import Config +from ..utils.balance import Balance +from ..wallet import Wallet class UnStakeCommand: diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py index 25fc5f6..f8699e2 100644 --- a/cybertensor/commands/utils.py +++ b/cybertensor/commands/utils.py @@ -26,9 +26,10 @@ from rich.prompt import Confirm, PromptBase import cybertensor -from .wallets import Wallet from . import defaults +from .wallets import Wallet from .. import __console__ as console +from ..config import Config class IntListPrompt(PromptBase): diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index e0842b4..b69f83e 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -27,6 +27,7 @@ import cybertensor from . import defaults from ..wallet import Wallet +from ..config import Config from .. import __console__ as console diff --git a/cybertensor/config.py b/cybertensor/config.py index c561c75..8314f87 100644 --- a/cybertensor/config.py +++ b/cybertensor/config.py @@ -220,8 +220,8 @@ def __init__( } @staticmethod - def __split_params__(params: argparse.Namespace, _config: "config"): - # Splits params on dot syntax i.e neuron.axon_port and adds to _config + def __split_params__(params: argparse.Namespace, _config: "Config"): + # Splits params on dot syntax i.e. neuron.axon_port and adds to _config for arg_key, arg_val in params.__dict__.items(): split_keys = arg_key.split(".") head = _config @@ -268,7 +268,7 @@ def __parse_args__( return params - def __deepcopy__(self, memo) -> "config": + def __deepcopy__(self, memo) -> "Config": _default = self.__default__ config_state = self.__getstate__() @@ -304,7 +304,7 @@ def __str__(self) -> str: cleaned = Config._remove_private_keys(visible) return "\n" + yaml.dump(cleaned, sort_keys=False) - def copy(self) -> "config": + def copy(self) -> "Config": return copy.deepcopy(self) def to_string(self, items) -> str: @@ -341,7 +341,7 @@ def merge(self, b): self = self._merge(self, b) @classmethod - def merge_all(cls, configs: List["config"]) -> "config": + def merge_all(cls, configs: List["Config"]) -> "Config": """ Merge all configs in the list into one config. If there is a conflict, the value from the last configuration in the list will take precedence. diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index f9da5c7..14dc438 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -75,7 +75,7 @@ def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "Keypair": keyfile_dict = dict(json.loads(keyfile_data)) except: string_value = str(keyfile_data) - raise cybertensor.KeyFileError( + raise KeyFileError( "Keypair could not be created from keyfile data: {}".format(string_value) ) @@ -91,7 +91,7 @@ def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "Keypair": ) else: - raise cybertensor.KeyFileError( + raise KeyFileError( "Keypair could not be created from keyfile data: {}".format(keyfile_dict) ) @@ -288,7 +288,7 @@ def decrypt_keyfile_data( try: decrypted_keyfile_data = vault.load(keyfile_data) except AnsibleVaultError: - raise cybertensor.KeyFileError("Invalid password") + raise KeyFileError("Invalid password") # Legacy decrypt. elif keyfile_data_is_encrypted_legacy(keyfile_data): __SALT = ( @@ -306,12 +306,12 @@ def decrypt_keyfile_data( decrypted_keyfile_data = cipher_suite.decrypt(keyfile_data) # Unknown. else: - raise cybertensor.KeyFileError( + raise KeyFileError( "keyfile data: {} is corrupt".format(keyfile_data) ) except (InvalidSignature, InvalidKey, InvalidToken): - raise cybertensor.KeyFileError("Invalid password") + raise KeyFileError("Invalid password") if not isinstance(decrypted_keyfile_data, bytes): decrypted_keyfile_data = json.dumps(decrypted_keyfile_data).encode() @@ -573,15 +573,15 @@ def encrypt(self, password: str = None): KeyFileError: Raised if the file does not exist, is not readable, or writable. """ if not self.exists_on_device(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} does not exist".format(self.path) ) if not self.is_readable(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not readable".format(self.path) ) if not self.is_writable(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not writable".format(self.path) ) keyfile_data = self._read_keyfile_data_from_file() @@ -599,15 +599,15 @@ def decrypt(self, password: str = None): KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect. """ if not self.exists_on_device(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} does not exist".format(self.path) ) if not self.is_readable(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not readable".format(self.path) ) if not self.is_writable(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not writable".format(self.path) ) keyfile_data = self._read_keyfile_data_from_file() @@ -627,11 +627,11 @@ def _read_keyfile_data_from_file(self) -> bytes: KeyFileError: Raised if the file does not exist or is not readable. """ if not self.exists_on_device(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} does not exist".format(self.path) ) if not self.is_readable(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not readable".format(self.path) ) with open(self.path, "rb") as file: @@ -649,7 +649,7 @@ def _write_keyfile_data_to_file(self, keyfile_data: bytes, overwrite: bool = Fal # Check overwrite. if self.exists_on_device() and not overwrite: if not self._may_overwrite(): - raise cybertensor.KeyFileError( + raise KeyFileError( "Keyfile at: {} is not writable".format(self.path) ) with open(self.path, "wb") as keyfile: diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py index a785541..91c44f5 100644 --- a/cybertensor/messages/delegation.py +++ b/cybertensor/messages/delegation.py @@ -24,9 +24,10 @@ from rich.prompt import Confirm import cybertensor -from ..utils.balance import Balance -from ..errors import * from .. import __console__ as console +from ..errors import * +from ..utils.balance import Balance +from ..wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/messages/log_utilities.py b/cybertensor/messages/log_utilities.py index 7ee7bde..625f108 100644 --- a/cybertensor/messages/log_utilities.py +++ b/cybertensor/messages/log_utilities.py @@ -1,7 +1,7 @@ import datetime import math import time -from typing import List, Dict, Set +from typing import List, Dict, Set, Optional from prometheus_client import Counter, Info, Histogram, Gauge import torch @@ -11,6 +11,8 @@ from rich.table import Table import cybertensor +from ..wallet import Wallet +from ..config import Config class ValidatorLogger: @@ -23,7 +25,7 @@ class ValidatorLogger: cybertensor.server.config() """ - def __init__(self, config=None): + def __init__(self, config: Optional[Config] = None): # Neuron stats recorded by validator neuron/nucleus # [Column_name, key_name, format_string, rich_style] # description self.config = config @@ -674,7 +676,7 @@ class ValidatorPrometheus: cybertensor.server.config() """ - def __init__(self, config): + def __init__(self, config: Config): self.config = config self.info = Info("neuron_info", "Info summaries for the running server-miner.") self.gauges = Gauge( diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index 2d84b93..d9f0c21 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -25,8 +25,9 @@ from rich.prompt import Confirm import cybertensor -from ..utils import weight_utils from .. import __console__ as console +from ..utils import weight_utils +from ..wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py index 56cfcf0..efab35f 100644 --- a/cybertensor/messages/serving.py +++ b/cybertensor/messages/serving.py @@ -21,9 +21,10 @@ from rich.prompt import Confirm import cybertensor -from ..utils import networking as net -from ..types import AxonServeCallParams from .. import __console__ as console +from ..types import AxonServeCallParams +from ..utils import networking as net +from ..wallet import Wallet def serve_message( @@ -38,7 +39,7 @@ def serve_message( wait_for_finalization=True, prompt: bool = False, ) -> bool: - r"""Subscribes an cybertensor endpoint to the substensor chain. + r"""Subscribes a cybertensor endpoint to the substensor chain. Args: wallet (Wallet): cybertensor wallet object. diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index 72da9cb..d67fddb 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -24,8 +24,9 @@ from rich.prompt import Confirm import cybertensor -from ..utils import weight_utils from .. import __console__ as console +from ..utils import weight_utils +from ..wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/utils/_register_cuda.py b/cybertensor/utils/_register_cuda.py index 52313e9..237f060 100644 --- a/cybertensor/utils/_register_cuda.py +++ b/cybertensor/utils/_register_cuda.py @@ -1,14 +1,13 @@ import binascii import hashlib +import io import math +from contextlib import redirect_stdout from typing import Tuple import numpy as np from Crypto.Hash import keccak -from contextlib import redirect_stdout -import io - def solve_cuda( nonce_start: np.int64, @@ -51,7 +50,7 @@ def solve_cuda( upper_bytes = upper.to_bytes(32, byteorder="little", signed=False) - def _hex_bytes_to_u8_list(hex_bytes: bytes): + def _hex_bytes_to_u8_list(hex_bytes: bytes) -> list[int]: hex_chunks = [ int(hex_bytes[i : i + 2], 16) for i in range(0, len(hex_bytes), 2) ] @@ -65,7 +64,7 @@ def _create_seal_hash(block_and_hotkey_hash_hex: bytes, nonce: int) -> bytes: seal = kec.update(seal_sh256).digest() return seal - def _seal_meets_difficulty(seal: bytes, difficulty: int): + def _seal_meets_difficulty(seal: bytes, difficulty: int) -> bool: seal_number = int.from_bytes(seal, "big") product = seal_number * difficulty limit = int(math.pow(2, 256)) - 1 @@ -96,7 +95,7 @@ def _seal_meets_difficulty(seal: bytes, difficulty: int): return solution, seal -def reset_cuda(): +def reset_cuda() -> None: """ Resets the CUDA environment. """ diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py index 61e749f..671e9ee 100644 --- a/cybertensor/utils/registration.py +++ b/cybertensor/utils/registration.py @@ -17,10 +17,10 @@ from rich import status as rich_status import cybertensor -from ..wallet import Wallet from ._register_cuda import solve_cuda from .formatting import get_human_readable, millify from .. import __console__ as console +from ..wallet import Wallet class CUDAException(Exception): @@ -30,7 +30,7 @@ class CUDAException(Exception): def _hex_bytes_to_u8_list(hex_bytes: bytes): - hex_chunks = [int(hex_bytes[i : i + 2], 16) for i in range(0, len(hex_bytes), 2)] + hex_chunks = [int(hex_bytes[i: i + 2], 16) for i in range(0, len(hex_bytes), 2)] return hex_chunks @@ -454,7 +454,7 @@ def update(self, stats: RegistrationStatistics, verbose: bool = False) -> None: def _solve_for_difficulty_fast( - cwtensor, + cwtensor: cybertensor.cwtensor, wallet: "Wallet", netuid: int, output_in_place: bool = True, @@ -467,7 +467,7 @@ def _solve_for_difficulty_fast( """ Solves the POW for registration using multiprocessing. Args: - cwtensor + cwtensor: cybertensor.cwtensor cwtensor to connect to for block information and to submit. wallet: wallet to use for registration. diff --git a/cybertensor/utils/stats.py b/cybertensor/utils/stats.py index f114af2..8a46bc0 100644 --- a/cybertensor/utils/stats.py +++ b/cybertensor/utils/stats.py @@ -20,7 +20,7 @@ class timed_rolling_avg: - """A exponential moving average that updates values based on time since last update.""" + """An exponential moving average that updates values based on time since last update.""" def __init__(self, initial_value, alpha): self.value = initial_value @@ -37,7 +37,7 @@ def update(self, new_value): class AmountPerSecondRollingAverage: - """A exponential moving average that counts quantity per second.""" + """An exponential moving average that counts quantity per second.""" def __init__(self, initial_value=0, alpha=0.1): self.value = initial_value @@ -60,7 +60,7 @@ def get(self) -> float: class EventsPerSecondRollingAverage: - """A exponential moving average that counts the number of events per second.""" + """An exponential moving average that counts the number of events per second.""" def __init__(self, initial_value, alpha): self.value = initial_value diff --git a/cybertensor/wallet.py b/cybertensor/wallet.py index 36e4bc7..907071c 100644 --- a/cybertensor/wallet.py +++ b/cybertensor/wallet.py @@ -181,7 +181,7 @@ def __repr__(self): def create_if_non_existent( self, coldkey_use_password: bool = True, hotkey_use_password: bool = False - ) -> "wallet": + ) -> "Wallet": """ Checks for existing coldkeypub and hotkeys and creates them if non-existent. @@ -196,7 +196,7 @@ def create_if_non_existent( def create( self, coldkey_use_password: bool = True, hotkey_use_password: bool = False - ) -> "wallet": + ) -> "Wallet": """ Checks for existing coldkeypub and hotkeys and creates them if non-existent. @@ -219,7 +219,7 @@ def create( def recreate( self, coldkey_use_password: bool = True, hotkey_use_password: bool = False - ) -> "wallet": + ) -> "Wallet": """ Checks for existing coldkeypub and hotkeys and creates them if non-existent. @@ -421,7 +421,7 @@ def new_coldkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": """Creates a new coldkey, optionally encrypts it with the user's inputed password and saves to disk. Args: n_words: (int, optional): @@ -442,7 +442,7 @@ def create_new_coldkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": """Creates a new coldkey, optionally encrypts it with the user's inputed password and saves to disk. Args: n_words: (int, optional): @@ -469,7 +469,7 @@ def new_hotkey( use_password: bool = False, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": """Creates a new hotkey, optionally encrypts it with the user's inputed password and saves to disk. Args: n_words: (int, optional): @@ -490,7 +490,7 @@ def create_new_hotkey( use_password: bool = False, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": """Creates a new hotkey, optionally encrypts it with the user's inputed password and saves to disk. Args: n_words: (int, optional): @@ -516,7 +516,7 @@ def regenerate_coldkeypub( public_key: Optional[Union[str, bytes]] = None, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": """Regenerates the coldkeypub from passed address or public_key and saves the file Requires either address or public_key to be passed. Args: @@ -570,7 +570,7 @@ def regenerate_coldkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... @overload @@ -580,7 +580,7 @@ def regenerate_coldkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... @overload @@ -590,7 +590,7 @@ def regenerate_coldkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... def regenerate_coldkey( @@ -599,7 +599,7 @@ def regenerate_coldkey( overwrite: bool = False, suppress: bool = False, **kwargs, - ) -> "wallet": + ) -> "Wallet": """Regenerates the coldkey from passed mnemonic, seed, or json encrypts it with the user's password and saves the file Args: mnemonic: (Union[list, str], optional): @@ -661,7 +661,7 @@ def regenerate_hotkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... @overload @@ -671,7 +671,7 @@ def regenerate_hotkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... @overload @@ -681,7 +681,7 @@ def regenerate_hotkey( use_password: bool = True, overwrite: bool = False, suppress: bool = False, - ) -> "wallet": + ) -> "Wallet": ... def regenerate_hotkey( @@ -690,7 +690,7 @@ def regenerate_hotkey( overwrite: bool = False, suppress: bool = False, **kwargs, - ) -> "wallet": + ) -> "Wallet": """Regenerates the hotkey from passed mnemonic, encrypts it with the user's password and save the file Args: mnemonic: (Union[list, str], optional): From 8770c48fbf903f747c641187fc28255d196a5a8e Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sat, 3 Feb 2024 22:51:12 +0800 Subject: [PATCH 05/23] - update types in functions --- cybertensor/utils/registration.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py index 671e9ee..33a8e48 100644 --- a/cybertensor/utils/registration.py +++ b/cybertensor/utils/registration.py @@ -454,7 +454,7 @@ def update(self, stats: RegistrationStatistics, verbose: bool = False) -> None: def _solve_for_difficulty_fast( - cwtensor: cybertensor.cwtensor, + cwtensor: "cybertensor.cwtensor", wallet: "Wallet", netuid: int, output_in_place: bool = True, @@ -469,7 +469,7 @@ def _solve_for_difficulty_fast( Args: cwtensor: cybertensor.cwtensor cwtensor to connect to for block information and to submit. - wallet: + wallet: Wallet wallet to use for registration. netuid: int The netuid of the subnet to register to. @@ -1023,8 +1023,8 @@ def _terminate_workers_and_wait_for_exit( def create_pow( - cwtensor, - wallet, + cwtensor: "cybertensor.cwtensor", + wallet: Wallet, netuid: int, output_in_place: bool = True, cuda: bool = False, @@ -1037,7 +1037,7 @@ def create_pow( """ Creates a proof of work for the given cwtensor and wallet. Args: - cwtensor (:obj:`cybertensor.cwtensor.cwtensor`, `required`): + cwtensor (:obj:`cybertensor.cwtensor`, `required`): The cwtensor to create a proof of work for. wallet (:obj:`Wallet.wallet`, `required`): The wallet to create a proof of work for. From 5c58e3979c232cdafdbe3e4bc85ce90601bca2f6 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Fri, 9 Feb 2024 12:46:27 +0800 Subject: [PATCH 06/23] - update imports - update address validation --- cybertensor/cwtensor.py | 2 +- cybertensor/utils/balance.py | 6 +++--- cybertensor/utils/wallet_utils.py | 15 +++++++++------ cybertensor/utils/weight_utils.py | 4 ++-- requirements/prod.txt | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index 28233ae..aa08a99 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -20,7 +20,7 @@ import argparse import copy import os -from typing import List, Dict, Union, Optional, Tuple, TypedDict +from typing import List, Dict, Union, Optional, Tuple import torch from cosmpy.aerial.client import LedgerClient diff --git a/cybertensor/utils/balance.py b/cybertensor/utils/balance.py index d14208d..0995c6b 100644 --- a/cybertensor/utils/balance.py +++ b/cybertensor/utils/balance.py @@ -22,7 +22,7 @@ from cosmpy.aerial.client import Coin -import cybertensor +from cybertensor import __giga_boot_symbol__, __boot_symbol__ class Balance: @@ -38,8 +38,8 @@ class Balance: gboot: A float property that gives the balance in gboot units. """ - unit: str = cybertensor.__giga_boot_symbol__ # This is the gboot unit - boot_unit: str = cybertensor.__boot_symbol__ # This is the boot unit + unit: str = __giga_boot_symbol__ # This is the gboot unit + boot_unit: str = __boot_symbol__ # This is the boot unit boot: int gboot: float diff --git a/cybertensor/utils/wallet_utils.py b/cybertensor/utils/wallet_utils.py index 64e4e8d..10bfefb 100644 --- a/cybertensor/utils/wallet_utils.py +++ b/cybertensor/utils/wallet_utils.py @@ -24,10 +24,12 @@ from cosmpy.aerial.client import Coin from cosmpy.crypto.address import Address -import cybertensor +from cybertensor import __chain_address_prefix__ -def is_valid_cybertensor_address_or_public_key(address: Union[str, bytes, Address]) -> bool: +def is_valid_cybertensor_address_or_public_key( + address: Union[str, bytes, Address] +) -> bool: """ Checks if the given address is a valid destination address. @@ -37,9 +39,10 @@ def is_valid_cybertensor_address_or_public_key(address: Union[str, bytes, Addres Returns: True if the address is a valid destination address, False otherwise. """ - - # TODO - return True + if address is not None: + return is_valid_address(address) + # TODO add public key validation + return False def is_valid_address(address: Union[str, Address]) -> bool: @@ -54,7 +57,7 @@ def is_valid_address(address: Union[str, Address]) -> bool: """ try: Address(address) - if address.startswith(cybertensor.__chain_address_prefix__): + if address.startswith(__chain_address_prefix__): return True except RuntimeError: pass diff --git a/cybertensor/utils/weight_utils.py b/cybertensor/utils/weight_utils.py index 9a42b66..ce21571 100644 --- a/cybertensor/utils/weight_utils.py +++ b/cybertensor/utils/weight_utils.py @@ -259,7 +259,7 @@ def process_weights_for_netuid( ) # creating minimum even non-zero weights weights[non_zero_weight_idx] += non_zero_weights cybertensor.logging.debug("final_weights", weights) - normalized_weights = cybertensor.utils.weight_utils.normalize_max_weight( + normalized_weights = normalize_max_weight( x=weights, limit=max_weight_limit ) return torch.tensor(list(range(len(normalized_weights)))), normalized_weights @@ -283,7 +283,7 @@ def process_weights_for_netuid( cybertensor.logging.debug("non_zero_weights", non_zero_weights) # Normalize weights and return. - normalized_weights = cybertensor.utils.weight_utils.normalize_max_weight( + normalized_weights = normalize_max_weight( x=non_zero_weights, limit=max_weight_limit ) cybertensor.logging.debug("final_weights", normalized_weights) diff --git a/requirements/prod.txt b/requirements/prod.txt index cdea4dc..7e2b97b 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -5,7 +5,7 @@ backoff black==23.7.0 cryptography==41.0.3 ddt==1.6.0 -grpcio==1.60.0 +grpcio fuzzywuzzy>=0.18.0 fastapi==0.99.1 loguru==0.7.0 From c7f65d83a5fe690fe3c62e3b166db19943b921df Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Fri, 9 Feb 2024 16:34:10 +0800 Subject: [PATCH 07/23] - refactor cwtensor - update imports --- cybertensor/__init__.py | 2 +- cybertensor/cwtensor.py | 296 +++++++++++----------------------- cybertensor/utils/__init__.py | 1 + 3 files changed, 96 insertions(+), 203 deletions(-) diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index d3b8d90..ef0355b 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -173,7 +173,7 @@ def __init__( __contract_path__ = Path(__file__).home() / ".cybertensor/contract/cybernet.wasm" __contract_schema_path__ = Path(__file__).home() / ".cybertensor/contract/schema" -__default_gas__ = 1_000_000 +__default_gas__ = None __default_transfer_gas__ = 100_000 from .errors import * diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index aa08a99..89b62c6 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -43,6 +43,7 @@ AxonInfo, ) from .commands.utils import DelegatesDetails +from .config import Config from .errors import * from .messages.delegation import ( delegate_message, @@ -69,7 +70,6 @@ from .utils.balance import Balance from .utils.registration import POWSolution from .wallet import Wallet -from .config import Config logger = logger.opt(colors=True) @@ -252,6 +252,47 @@ def __str__(self) -> str: def __repr__(self) -> str: return self.__str__() + # TODO check decorator and improve error handling + @retry(delay=2, tries=3, backoff=2, max_delay=4) + def make_call_with_retry(self, wait_for_finalization: bool, + msg: dict, + signer_wallet: LocalWallet, error, + gas: Optional[int] = cybertensor.__default_gas__, + funds: Optional[str] = None) -> Optional[bool]: + if not wait_for_finalization: + self.contract.execute(msg, signer_wallet, gas, funds=funds) + return True + else: + tx = self.contract.execute(msg, signer_wallet, gas, funds=funds) + try: + tx.wait_to_complete() + if tx.response.is_successful(): + print(f'Gas used: {tx.response.gas_used}') + return True + else: + raise error(tx.response.logs) + except Exception as e: + raise error(e.__str__()) + + @retry(delay=2, tries=3, backoff=2, max_delay=4) + def make_call_with_retry_2(self, wait_for_finalization: bool, + msg: dict, signer_wallet: LocalWallet, gas: Optional[int] = cybertensor.__default_gas__, + funds: Optional[str] = None) -> [bool, Optional[str]]: + if not wait_for_finalization: + self.contract.execute(msg, signer_wallet, gas, funds=funds) + return True, None + else: + tx = self.contract.execute(msg, signer_wallet, gas, funds=funds) + try: + tx.wait_to_complete() + if tx.response.is_successful(): + print(f'Gas used: {tx.response.gas_used}') + return True, None + else: + return False, tx.response.code + except Exception as e: + return False, e.__str__() + ##################### #### Delegation ##### ##################### @@ -276,25 +317,12 @@ def _do_nominate( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(nominate_msg, signer_wallet, gas) - return True - else: - tx = self.contract.execute(nominate_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True - else: - raise NominationError(tx.response.logs) - except Exception as e: - raise NominationError(e.__str__()) - - return make_call_with_retry() + return self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=nominate_msg, + signer_wallet=signer_wallet, + error=NominationError) def delegate( self, @@ -325,26 +353,14 @@ def _do_delegation( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ funds = amount.boot.__str__().__add__(self.token) - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(delegation_msg, signer_wallet, gas, funds) - return True - else: - tx = self.contract.execute(delegation_msg, signer_wallet, gas, funds) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True - else: - raise StakeError(tx.response.code) - except Exception as e: - raise StakeError(e.__str__()) - - return make_call_with_retry() + return self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=delegation_msg, + funds=funds, + signer_wallet=signer_wallet, + error=StakeError) def undelegate( self, @@ -375,25 +391,12 @@ def _do_undelegation( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(undelegation_msg, signer_wallet, gas) - return True - else: - tx = self.contract.execute(undelegation_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True - else: - raise StakeError(tx.response.code) - except Exception as e: - raise StakeError(e.__str__()) - - return make_call_with_retry() + return self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=undelegation_msg, + signer_wallet=signer_wallet, + error=StakeError) ##################### #### Set Weights #### @@ -440,25 +443,11 @@ def _do_set_weights( signer_wallet = LocalWallet( PrivateKey(wallet.hotkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(set_weights_msg, signer_wallet, gas) - return True, None - else: - tx = self.contract.execute(set_weights_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=set_weights_msg, + signer_wallet=signer_wallet) ###################### #### Registration #### @@ -526,26 +515,11 @@ def _do_pow_register( signer_wallet = LocalWallet( PrivateKey(wallet.hotkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - # TODO check decorator and improve error handling - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(register_msg, signer_wallet, gas) - return True, None - else: - tx = self.contract.execute(register_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=register_msg, + signer_wallet=signer_wallet) def burned_register( self, @@ -576,28 +550,13 @@ def _do_burned_register( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ funds = burn.__str__().__add__(self.token) - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(burned_register_msg, signer_wallet, gas, funds) - return True, None - else: - tx = self.contract.execute( - burned_register_msg, signer_wallet, gas, funds - ) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=burned_register_msg, + funds=funds, + signer_wallet=signer_wallet) ################## #### Transfer #### @@ -758,25 +717,11 @@ def _do_serve_axon( signer_wallet = LocalWallet( PrivateKey(wallet.hotkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(call_params, signer_wallet, gas) - return True, None - else: - tx = self.contract.execute(call_params, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=call_params, + signer_wallet=signer_wallet) def serve_prometheus( self, @@ -813,25 +758,11 @@ def _do_serve_prometheus( signer_wallet = LocalWallet( PrivateKey(wallet.hotkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(call_params, signer_wallet, gas) - return True, None - else: - tx = self.contract.execute(call_params, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=call_params, + signer_wallet=signer_wallet) ################# #### Staking #### @@ -895,26 +826,14 @@ def _do_stake( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ funds = amount.boot.__str__().__add__(self.token) - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(add_stake_msg, signer_wallet, gas, funds) - return True - else: - tx = self.contract.execute(add_stake_msg, signer_wallet, gas, funds) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True - else: - raise StakeError(tx.response.code) - except Exception as e: - raise StakeError(e.__str__()) - - return make_call_with_retry() + return self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=add_stake_msg, + signer_wallet=signer_wallet, + funds=funds, + error=StakeError) ################### #### Unstaking #### @@ -978,25 +897,12 @@ def _do_unstake( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(remove_stake_msg, signer_wallet, gas) - return True - else: - tx = self.contract.execute(remove_stake_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True - else: - raise StakeError(tx.response.code) - except Exception as e: - raise StakeError(e.__str__()) - - return make_call_with_retry() + return self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=remove_stake_msg, + signer_wallet=signer_wallet, + error=StakeError) ############## #### Root #### @@ -1025,25 +931,11 @@ def _do_root_register( signer_wallet = LocalWallet( PrivateKey(wallet.coldkey.private_key), self.address_prefix ) - gas = cybertensor.__default_gas__ - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_call_with_retry(): - if not wait_for_finalization: - self.contract.execute(root_register_msg, signer_wallet, gas) - return True, None - else: - tx = self.contract.execute(root_register_msg, signer_wallet, gas) - try: - tx.wait_to_complete() - if tx.response.is_successful(): - return True, None - else: - return False, tx.response.code - except Exception as e: - return False, e.__str__() - - return make_call_with_retry() + return self.make_call_with_retry_2( + wait_for_finalization=wait_for_finalization, + msg=root_register_msg, + signer_wallet=signer_wallet) def root_set_weights( self, diff --git a/cybertensor/utils/__init__.py b/cybertensor/utils/__init__.py index 0a466cb..f9212a6 100644 --- a/cybertensor/utils/__init__.py +++ b/cybertensor/utils/__init__.py @@ -21,6 +21,7 @@ import requests +import cybertensor from .formatting import get_human_readable, millify from .wallet_utils import * From a34557ba1c2ec978ec0b36bf13c62acb7f79984b Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Sun, 11 Feb 2024 21:45:17 +0800 Subject: [PATCH 08/23] - add load testing --- load_test_main.py | 259 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 load_test_main.py diff --git a/load_test_main.py b/load_test_main.py new file mode 100644 index 0000000..7075833 --- /dev/null +++ b/load_test_main.py @@ -0,0 +1,259 @@ +from argparse import ArgumentParser +from random import sample +from time import sleep +from typing import Union, TypedDict, Optional +from torch.multiprocessing import Pool + +from cyber_sdk.client.lcd import LCDClient +from cyber_sdk.client.lcd.api.tx import CreateTxOptions, BlockTxBroadcastResult +from cyber_sdk.core import Coin, Coins, AccAddress +from cyber_sdk.core.bank import MsgSend +from cyber_sdk.core.fee import Fee +from cyber_sdk.exceptions import LCDResponseError +from cyber_sdk.key.mnemonic import MnemonicKey +from cyberutils.bash import execute_bash +from cyberutils.contract import execute_contract +from tqdm import tqdm + +from cybertensor import cwtensor, Wallet + + +class Account(TypedDict): + wallet: Wallet + wallet_address: str + wallet_hotkey_address: str + start_amount: int + + +BASE_WALLET_SEED = "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" + +parser = ArgumentParser() +parser.add_argument("--addresses", default=10) +parser.add_argument("--send-to-contract", default="false") +parser.add_argument("--activate-contract", default="false") +parser.add_argument("--send-to-wallets", default="true") +parser.add_argument("--threads", default=5) +parser.add_argument("--lcd", default="http://localhost:1317") +args = parser.parse_args() + +ADDRESSES_NUMBER = int(args.addresses) +SEND_TOKEN_TO_CONTRACT = args.send_to_contract.lower() in ["true", "1", "t", "y", "yes"] +ACTIVATE_CONTRACT = args.activate_contract.lower() in ["true", "1", "t", "y", "yes"] +SEND_TOKEN_TO_WALLETS = args.send_to_wallets.lower() in ["true", "1", "t", "y", "yes"] +NUMBER_OF_THREADS = int(args.threads) +LCD_URL = args.lcd + + +def send_coins( + to_address: Union[str, AccAddress], amount: int, denom: str = "boot" +) -> Optional[BlockTxBroadcastResult]: + _msgs = [ + MsgSend( + from_address=base_wallet_address, + to_address=AccAddress(to_address), + amount=Coins([Coin(amount=amount, denom=denom)]), + ) + ] + _tx_signed = base_wallet.create_and_sign_tx( + CreateTxOptions( + msgs=_msgs, + memo="cybertensor test", + fee=Fee(1000000, Coins([Coin(amount=0, denom=tensor.token)])), + gas_adjustment=1.6, + ) + ) + + try: + _tx_broadcasted = lcd_client.tx.broadcast(_tx_signed) + return _tx_broadcasted + except LCDResponseError as _e: + print(f"LCDResponseError: {_e}") + return None + + +def send_token_to_contract() -> None: + if SEND_TOKEN_TO_CONTRACT: + send_coins(to_address=tensor.contract_address, amount=10_000_000_000) + sleep(5) + + +def activate_contract() -> None: + if ACTIVATE_CONTRACT: + tx = execute_contract( + execute_msgs=[{"activate": {}}], + wallet=base_wallet, + contract_address=tensor.contract_address, + lcd_client=lcd_client, + fee_denom=tensor.token, + ) + print(tx) + print(f"contract balance: {tensor.get_balance(tensor.contract_address)}") + + +def get_accounts(addresses_number: int = ADDRESSES_NUMBER) -> list[Account]: + accounts: list[Account] = [] + for i in range(1, addresses_number + 1): + wallet_name = f"wallet{i}" + wallet = Wallet(name=wallet_name, hotkey=wallet_name, path="temp") + wallet.create_if_non_existent( + coldkey_use_password=False, hotkey_use_password=False + ) + wallet_address = wallet.get_coldkey().address + wallet_hotkey_address = wallet.get_hotkey().address + print(f"address: {wallet_address}") + amount = 20_000_000_000 + if SEND_TOKEN_TO_WALLETS: + send_coins(to_address=wallet_address, amount=amount) + send_coins(to_address=wallet_hotkey_address, amount=1_000_000) + accounts.append( + Account( + wallet=wallet, + wallet_address=wallet_address, + wallet_hotkey_address=wallet_hotkey_address, + start_amount=amount, + ) + ) + return accounts + + +def workflow( + account: Account, + netuids: Optional[list[int]] = None, + register_subnetwork: bool = True, + root_register: bool = True, + subnet_register: bool = True, + subnet_nominate: bool = True, + self_stake: bool = True, + self_stake_amount: float = 1, + self_unstake: bool = True, + self_unstake_amount: float = 0.1, + root_set_weight: bool = True, + root_weights: Optional[list[float]] = None, + subnets_set_weight: bool = True, + subnets_weights: Optional[dict[int, list[list[int], list[float]]]] = None, +) -> None: + try: + tensor = cwtensor(network="local") + if register_subnetwork: + tensor.register_subnetwork(wallet=account["wallet"]) + if root_register: + tensor.root_register(wallet=account["wallet"]) + if netuids is None: + netuids = tensor.get_all_subnet_netuids() + if subnet_register: + for _netuid in netuids: + tensor.burned_register(wallet=account["wallet"], netuid=_netuid) + if subnet_nominate: + tensor.nominate(wallet=account["wallet"]) + # you can stake only to root validators + if self_stake: + tensor.add_stake( + wallet=account["wallet"], + hotkey=account["wallet_hotkey_address"], + amount=self_stake_amount, + ) + if self_unstake: + tensor.unstake( + wallet=account["wallet"], + hotkey=account["wallet_hotkey_address"], + amount=self_unstake_amount, + ) + if root_set_weight: + if root_weights is None: + root_weights = sample(range(1, 1 + len(netuids)), len(netuids)) + print(f'netuids: {netuids}' + f'len(netuids): {len(netuids)}' + f'root_weights: {root_weights}') + tensor.root_set_weights( + wallet=account["wallet"], netuids=netuids, weights=root_weights + ) + if subnets_set_weight: + sleep(10) + if subnets_weights is None: + subnets_weights = { + netuid: [ + [ + neuron.uid + for neuron in tensor.metagraph(netuid=netuid).neurons + ], + sample( + range(1, 1 + len(tensor.metagraph(netuid=netuid).neurons)), + len(tensor.metagraph(netuid=netuid).neurons), + ), + ] + for netuid in netuids + } + for _netuid in subnets_weights.keys(): + tensor.set_weights( + wallet=account["wallet"], + netuid=_netuid, + uids=subnets_weights[_netuid][0], + weights=subnets_weights[_netuid][1], + ) + except Exception as _e: + print(f"ERROR {_e}") + + +def display_state() -> None: + tensor = cwtensor(network="local") + netuids = tensor.get_all_subnet_netuids() + print(f"contract balance: {tensor.get_balance(tensor.contract_address)}") + print(f"existing subnets: {netuids}\n") + print(f"delegates: {tensor.get_delegates()}\n") + print(f"root weights {tensor.weights(netuid=0)}\n") + for netuid in netuids[1:]: + print(f"subnet {netuid} weights {tensor.weights(netuid=netuid)}") + + for netuid in netuids: + print(f'{"subnet" + str(netuid) if netuid != 0 else "root"}:') + for i, _account in enumerate(accounts): + print( + f"\twallet {i + 1} registration: " + f'{tensor.is_hotkey_registered_on_subnet(hotkey=_account["wallet_hotkey_address"], netuid=netuid)}' + ) + + +def run_workflow(account_name: str) -> bool: + print(f"account name: {account_name}") + _output, _error = execute_bash( + f"source ./venv/bin/activate && python load_test_job.py --wallet-name={account_name}", + timeout=400, + shell=True, + ) + + if _output: + print(_output) + print(f"{account_name} done") + return True + else: + # print(f"{account_name} error: {_error}") + return False + + +if __name__ == "__main__": + tensor = cwtensor(network="local") + mk = MnemonicKey(mnemonic=BASE_WALLET_SEED) + lcd_client = LCDClient(url=LCD_URL, chain_id=tensor.client.network_config.chain_id) + base_wallet = lcd_client.wallet(mk) + base_wallet_address = base_wallet.key.acc_address + print( + f"base address: {base_wallet_address}\n" + f"base address balance: {lcd_client.bank.balance(address=base_wallet_address)[0]}\n" + f"number of wallets: {ADDRESSES_NUMBER}\n" + f"send token to the contract: {SEND_TOKEN_TO_CONTRACT}\n" + f"activate contract: {ACTIVATE_CONTRACT}\n" + f"send token to wallets: {SEND_TOKEN_TO_WALLETS}\n" + ) + + send_token_to_contract() + activate_contract() + accounts = get_accounts() + + tasks = accounts + print(f"Number of tasks: {len(tasks):>,}") + print(f"Number of threads: {NUMBER_OF_THREADS:>,}") + + with Pool(processes=NUMBER_OF_THREADS) as pool: + res_participation = list(tqdm(pool.imap(workflow, tasks), total=len(tasks))) + + display_state() From 7796eddce85317d4146e8eba91bbc8a0553457ae Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Mon, 12 Feb 2024 16:00:34 +0800 Subject: [PATCH 09/23] - replace cyber_sdk and cyberutils to cosmpy in load testing --- load_test_main.py | 203 +++++++++++++++++++--------------------------- 1 file changed, 85 insertions(+), 118 deletions(-) diff --git a/load_test_main.py b/load_test_main.py index 7075833..84bb03f 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -2,19 +2,15 @@ from random import sample from time import sleep from typing import Union, TypedDict, Optional -from torch.multiprocessing import Pool -from cyber_sdk.client.lcd import LCDClient -from cyber_sdk.client.lcd.api.tx import CreateTxOptions, BlockTxBroadcastResult -from cyber_sdk.core import Coin, Coins, AccAddress -from cyber_sdk.core.bank import MsgSend -from cyber_sdk.core.fee import Fee -from cyber_sdk.exceptions import LCDResponseError -from cyber_sdk.key.mnemonic import MnemonicKey -from cyberutils.bash import execute_bash -from cyberutils.contract import execute_contract +import pandas as pd +from cosmpy.aerial.tx_helpers import SubmittedTx +from cosmpy.aerial.wallet import LocalWallet +from cosmpy.crypto.address import Address +from torch.multiprocessing import Pool from tqdm import tqdm +from cybertensor import __local_network__ as network from cybertensor import cwtensor, Wallet @@ -33,7 +29,6 @@ class Account(TypedDict): parser.add_argument("--activate-contract", default="false") parser.add_argument("--send-to-wallets", default="true") parser.add_argument("--threads", default=5) -parser.add_argument("--lcd", default="http://localhost:1317") args = parser.parse_args() ADDRESSES_NUMBER = int(args.addresses) @@ -41,33 +36,21 @@ class Account(TypedDict): ACTIVATE_CONTRACT = args.activate_contract.lower() in ["true", "1", "t", "y", "yes"] SEND_TOKEN_TO_WALLETS = args.send_to_wallets.lower() in ["true", "1", "t", "y", "yes"] NUMBER_OF_THREADS = int(args.threads) -LCD_URL = args.lcd def send_coins( - to_address: Union[str, AccAddress], amount: int, denom: str = "boot" -) -> Optional[BlockTxBroadcastResult]: - _msgs = [ - MsgSend( - from_address=base_wallet_address, - to_address=AccAddress(to_address), - amount=Coins([Coin(amount=amount, denom=denom)]), - ) - ] - _tx_signed = base_wallet.create_and_sign_tx( - CreateTxOptions( - msgs=_msgs, - memo="cybertensor test", - fee=Fee(1000000, Coins([Coin(amount=0, denom=tensor.token)])), - gas_adjustment=1.6, - ) - ) - + to_address: Union[str, Address], amount: int, denom: str = "boot" +) -> Optional[SubmittedTx]: try: - _tx_broadcasted = lcd_client.tx.broadcast(_tx_signed) + _tx_broadcasted = tensor.client.send_tokens( + destination=Address(to_address), + amount=amount, + denom=denom, + sender=base_wallet, + ).wait_to_complete() return _tx_broadcasted - except LCDResponseError as _e: - print(f"LCDResponseError: {_e}") + except Exception as _e: + print(f"Exception: {_e}") return None @@ -79,41 +62,36 @@ def send_token_to_contract() -> None: def activate_contract() -> None: if ACTIVATE_CONTRACT: - tx = execute_contract( - execute_msgs=[{"activate": {}}], - wallet=base_wallet, - contract_address=tensor.contract_address, - lcd_client=lcd_client, - fee_denom=tensor.token, - ) - print(tx) - print(f"contract balance: {tensor.get_balance(tensor.contract_address)}") + _tx = tensor.contract.execute( + args={"activate": {}}, sender=base_wallet + ).wait_to_complete() + print(_tx) def get_accounts(addresses_number: int = ADDRESSES_NUMBER) -> list[Account]: - accounts: list[Account] = [] - for i in range(1, addresses_number + 1): - wallet_name = f"wallet{i}" - wallet = Wallet(name=wallet_name, hotkey=wallet_name, path="temp") - wallet.create_if_non_existent( + _accounts: list[Account] = [] + for _i in range(1, addresses_number + 1): + _wallet_name = f"wallet{_i}" + _wallet = Wallet(name=_wallet_name, hotkey=_wallet_name, path="temp") + _wallet.create_if_non_existent( coldkey_use_password=False, hotkey_use_password=False ) - wallet_address = wallet.get_coldkey().address - wallet_hotkey_address = wallet.get_hotkey().address - print(f"address: {wallet_address}") - amount = 20_000_000_000 + _wallet_address = _wallet.get_coldkey().address + _wallet_hotkey_address = _wallet.get_hotkey().address + print(f"{_wallet_name} address uploaded: {_wallet_address}") + _amount = 20_000_000_000 if SEND_TOKEN_TO_WALLETS: - send_coins(to_address=wallet_address, amount=amount) - send_coins(to_address=wallet_hotkey_address, amount=1_000_000) - accounts.append( + send_coins(to_address=_wallet_address, amount=_amount) + send_coins(to_address=_wallet_hotkey_address, amount=1_000_000) + _accounts.append( Account( - wallet=wallet, - wallet_address=wallet_address, - wallet_hotkey_address=wallet_hotkey_address, - start_amount=amount, + wallet=_wallet, + wallet_address=_wallet_address, + wallet_hotkey_address=_wallet_hotkey_address, + start_amount=_amount, ) ) - return accounts + return _accounts def workflow( @@ -133,27 +111,27 @@ def workflow( subnets_weights: Optional[dict[int, list[list[int], list[float]]]] = None, ) -> None: try: - tensor = cwtensor(network="local") + _tensor = cwtensor(network="local") if register_subnetwork: - tensor.register_subnetwork(wallet=account["wallet"]) + _tensor.register_subnetwork(wallet=account["wallet"]) if root_register: - tensor.root_register(wallet=account["wallet"]) + _tensor.root_register(wallet=account["wallet"]) if netuids is None: - netuids = tensor.get_all_subnet_netuids() + netuids = _tensor.get_all_subnet_netuids() if subnet_register: for _netuid in netuids: - tensor.burned_register(wallet=account["wallet"], netuid=_netuid) + _tensor.burned_register(wallet=account["wallet"], netuid=_netuid) if subnet_nominate: - tensor.nominate(wallet=account["wallet"]) + _tensor.nominate(wallet=account["wallet"]) # you can stake only to root validators if self_stake: - tensor.add_stake( + _tensor.add_stake( wallet=account["wallet"], hotkey=account["wallet_hotkey_address"], amount=self_stake_amount, ) if self_unstake: - tensor.unstake( + _tensor.unstake( wallet=account["wallet"], hotkey=account["wallet_hotkey_address"], amount=self_unstake_amount, @@ -161,30 +139,34 @@ def workflow( if root_set_weight: if root_weights is None: root_weights = sample(range(1, 1 + len(netuids)), len(netuids)) - print(f'netuids: {netuids}' - f'len(netuids): {len(netuids)}' - f'root_weights: {root_weights}') - tensor.root_set_weights( + print( + f"netuids: {netuids}\t" + f"len(netuids): {len(netuids)}\t" + f"root_weights: {root_weights}" + ) + _tensor.root_set_weights( wallet=account["wallet"], netuids=netuids, weights=root_weights ) if subnets_set_weight: sleep(10) if subnets_weights is None: subnets_weights = { - netuid: [ + _netuid: [ [ - neuron.uid - for neuron in tensor.metagraph(netuid=netuid).neurons + _neuron.uid + for _neuron in _tensor.metagraph(netuid=_netuid).neurons ], sample( - range(1, 1 + len(tensor.metagraph(netuid=netuid).neurons)), - len(tensor.metagraph(netuid=netuid).neurons), + range( + 1, 1 + len(_tensor.metagraph(netuid=_netuid).neurons) + ), + len(_tensor.metagraph(netuid=_netuid).neurons), ), ] - for netuid in netuids + for _netuid in netuids } for _netuid in subnets_weights.keys(): - tensor.set_weights( + _tensor.set_weights( wallet=account["wallet"], netuid=_netuid, uids=subnets_weights[_netuid][0], @@ -195,50 +177,34 @@ def workflow( def display_state() -> None: - tensor = cwtensor(network="local") - netuids = tensor.get_all_subnet_netuids() - print(f"contract balance: {tensor.get_balance(tensor.contract_address)}") - print(f"existing subnets: {netuids}\n") - print(f"delegates: {tensor.get_delegates()}\n") - print(f"root weights {tensor.weights(netuid=0)}\n") - for netuid in netuids[1:]: - print(f"subnet {netuid} weights {tensor.weights(netuid=netuid)}") - - for netuid in netuids: - print(f'{"subnet" + str(netuid) if netuid != 0 else "root"}:') - for i, _account in enumerate(accounts): - print( - f"\twallet {i + 1} registration: " - f'{tensor.is_hotkey_registered_on_subnet(hotkey=_account["wallet_hotkey_address"], netuid=netuid)}' - ) - - -def run_workflow(account_name: str) -> bool: - print(f"account name: {account_name}") - _output, _error = execute_bash( - f"source ./venv/bin/activate && python load_test_job.py --wallet-name={account_name}", - timeout=400, - shell=True, - ) - - if _output: - print(_output) - print(f"{account_name} done") - return True - else: - # print(f"{account_name} error: {_error}") - return False + _tensor = cwtensor(network="local") + _netuids = _tensor.get_all_subnet_netuids() + print(f"\ncontract address: {_tensor.contract_address}") + print(f"contract balance: {_tensor.get_balance(_tensor.contract_address)}") + print(f"existing subnets: {_netuids}\n") + print(f"delegates: {_tensor.get_delegates()}\n") + print(f"root weights {_tensor.weights(netuid=0)}\n") + for _netuid in _netuids[1:]: + print(f"subnet {_netuid} weights {_tensor.weights(netuid=_netuid)}") + + _registration_data = [[f'{"subnet" + str(_netuid) if _netuid != 0 else "root"}'] + + [tensor.is_hotkey_registered_on_subnet(hotkey=_account["wallet_hotkey_address"], netuid=_netuid) + for _account in accounts] + for _netuid in _netuids] + _registration_columns = ['Subnet'] + [_account['wallet'].name for _account in accounts] + print('\nwallet registration:') + print(pd.DataFrame(data=_registration_data, columns=_registration_columns)) if __name__ == "__main__": tensor = cwtensor(network="local") - mk = MnemonicKey(mnemonic=BASE_WALLET_SEED) - lcd_client = LCDClient(url=LCD_URL, chain_id=tensor.client.network_config.chain_id) - base_wallet = lcd_client.wallet(mk) - base_wallet_address = base_wallet.key.acc_address + base_wallet = LocalWallet.from_mnemonic( + mnemonic=BASE_WALLET_SEED, prefix=network.address_prefix + ) + base_wallet_address = str(base_wallet) print( f"base address: {base_wallet_address}\n" - f"base address balance: {lcd_client.bank.balance(address=base_wallet_address)[0]}\n" + f"base address balance: {tensor.get_balance(address=base_wallet_address)}\n" f"number of wallets: {ADDRESSES_NUMBER}\n" f"send token to the contract: {SEND_TOKEN_TO_CONTRACT}\n" f"activate contract: {ACTIVATE_CONTRACT}\n" @@ -248,10 +214,11 @@ def run_workflow(account_name: str) -> bool: send_token_to_contract() activate_contract() accounts = get_accounts() + display_state() tasks = accounts - print(f"Number of tasks: {len(tasks):>,}") - print(f"Number of threads: {NUMBER_OF_THREADS:>,}") + print(f"\nnumber of tasks: {len(tasks):>,}") + print(f"number of threads: {NUMBER_OF_THREADS:>,}") with Pool(processes=NUMBER_OF_THREADS) as pool: res_participation = list(tqdm(pool.imap(workflow, tasks), total=len(tasks))) From 2e607c6d491dc55859b6eaed353c2eb88436d116 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Tue, 13 Feb 2024 12:15:00 +0800 Subject: [PATCH 10/23] - fix root weight setting in load testing --- load_test_main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/load_test_main.py b/load_test_main.py index 84bb03f..abe7981 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -118,6 +118,7 @@ def workflow( _tensor.root_register(wallet=account["wallet"]) if netuids is None: netuids = _tensor.get_all_subnet_netuids() + _subnetuids = [_netuid for _netuid in netuids if _netuid != 0] if subnet_register: for _netuid in netuids: _tensor.burned_register(wallet=account["wallet"], netuid=_netuid) @@ -138,14 +139,13 @@ def workflow( ) if root_set_weight: if root_weights is None: - root_weights = sample(range(1, 1 + len(netuids)), len(netuids)) + root_weights = sample(range(1, 1 + len(_subnetuids)), len(_subnetuids)) print( - f"netuids: {netuids}\t" - f"len(netuids): {len(netuids)}\t" + f"netuids: {_subnetuids}\t" f"root_weights: {root_weights}" ) _tensor.root_set_weights( - wallet=account["wallet"], netuids=netuids, weights=root_weights + wallet=account["wallet"], netuids=_subnetuids, weights=root_weights, wait_for_finalization=True ) if subnets_set_weight: sleep(10) @@ -163,7 +163,7 @@ def workflow( len(_tensor.metagraph(netuid=_netuid).neurons), ), ] - for _netuid in netuids + for _netuid in _subnetuids } for _netuid in subnets_weights.keys(): _tensor.set_weights( From 90288cf96941bc3c29dc51914fa7eb29f129a35c Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Tue, 13 Feb 2024 13:35:35 +0800 Subject: [PATCH 11/23] - set error logging level for sys.stdout --- cybertensor/ctlogging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cybertensor/ctlogging.py b/cybertensor/ctlogging.py index aa52502..5064eef 100644 --- a/cybertensor/ctlogging.py +++ b/cybertensor/ctlogging.py @@ -25,7 +25,7 @@ import torch from loguru import logger -from .config import Config +from cybertensor.config import Config logger = logger.opt(colors=True) @@ -101,7 +101,7 @@ def __new__( # Add filtered sys.stdout. cls.__std_sink__ = logger.add( sys.stdout, - level=0, + level=40, filter=cls.log_filter, colorize=True, enqueue=True, From c84f52ef66ae0ce19c15ee440676f4b7a7598c93 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Tue, 13 Feb 2024 16:36:01 +0800 Subject: [PATCH 12/23] - fix warning in load testing --- load_test_main.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/load_test_main.py b/load_test_main.py index abe7981..b191aaf 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -1,8 +1,11 @@ +import warnings from argparse import ArgumentParser from random import sample from time import sleep from typing import Union, TypedDict, Optional +warnings.filterwarnings("ignore", category=DeprecationWarning) + import pandas as pd from cosmpy.aerial.tx_helpers import SubmittedTx from cosmpy.aerial.wallet import LocalWallet @@ -145,10 +148,12 @@ def workflow( f"root_weights: {root_weights}" ) _tensor.root_set_weights( - wallet=account["wallet"], netuids=_subnetuids, weights=root_weights, wait_for_finalization=True + wallet=account["wallet"], + netuids=_subnetuids, + weights=root_weights, + wait_for_finalization=True, ) if subnets_set_weight: - sleep(10) if subnets_weights is None: subnets_weights = { _netuid: [ @@ -166,6 +171,7 @@ def workflow( for _netuid in _subnetuids } for _netuid in subnets_weights.keys(): + sleep(10) _tensor.set_weights( wallet=account["wallet"], netuid=_netuid, @@ -187,12 +193,20 @@ def display_state() -> None: for _netuid in _netuids[1:]: print(f"subnet {_netuid} weights {_tensor.weights(netuid=_netuid)}") - _registration_data = [[f'{"subnet" + str(_netuid) if _netuid != 0 else "root"}'] + - [tensor.is_hotkey_registered_on_subnet(hotkey=_account["wallet_hotkey_address"], netuid=_netuid) - for _account in accounts] - for _netuid in _netuids] - _registration_columns = ['Subnet'] + [_account['wallet'].name for _account in accounts] - print('\nwallet registration:') + _registration_data = [ + [f'{"subnet" + str(_netuid) if _netuid != 0 else "root"}'] + + [ + tensor.is_hotkey_registered_on_subnet( + hotkey=_account["wallet_hotkey_address"], netuid=_netuid + ) + for _account in accounts + ] + for _netuid in _netuids + ] + _registration_columns = ["Subnet"] + [ + _account["wallet"].name for _account in accounts + ] + print("\nwallet registration:") print(pd.DataFrame(data=_registration_data, columns=_registration_columns)) From 705915ba630b79b25ffd9abb0f0e05bb634d452c Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Tue, 13 Feb 2024 17:05:47 +0800 Subject: [PATCH 13/23] - add contract schema to the package - remove path of contract wasm code --- cybertensor/__init__.py | 4 +- cybertensor/contract/schema/execute.json | 1453 ++++++++++++++++++ cybertensor/contract/schema/instantiate.json | 6 + cybertensor/contract/schema/query.json | 856 +++++++++++ 4 files changed, 2317 insertions(+), 2 deletions(-) create mode 100644 cybertensor/contract/schema/execute.json create mode 100644 cybertensor/contract/schema/instantiate.json create mode 100644 cybertensor/contract/schema/query.json diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index ef0355b..e29b2eb 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -170,8 +170,8 @@ def __init__( contract_address="pussy1ddwq8rxgdsm27pvpxqdy2ep9enuen6t2yhrqujvj9qwl4dtukx0s8hpka9", ) -__contract_path__ = Path(__file__).home() / ".cybertensor/contract/cybernet.wasm" -__contract_schema_path__ = Path(__file__).home() / ".cybertensor/contract/schema" +__contract_path__ = None +__contract_schema_path__ = "contract/schema" __default_gas__ = None __default_transfer_gas__ = 100_000 diff --git a/cybertensor/contract/schema/execute.json b/cybertensor/contract/schema/execute.json new file mode 100644 index 0000000..a9599e1 --- /dev/null +++ b/cybertensor/contract/schema/execute.json @@ -0,0 +1,1453 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "activate" + ], + "properties": { + "activate": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "deactivate" + ], + "properties": { + "deactivate": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "block_step" + ], + "properties": { + "block_step": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "set_weights" + ], + "properties": { + "set_weights": { + "type": "object", + "required": [ + "dests", + "netuid", + "version_key", + "weights" + ], + "properties": { + "dests": { + "type": "array", + "items": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "version_key": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "weights": { + "type": "array", + "items": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "become_delegate" + ], + "properties": { + "become_delegate": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "add_stake" + ], + "properties": { + "add_stake": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "remove_stake" + ], + "properties": { + "remove_stake": { + "type": "object", + "required": [ + "amount", + "hotkey" + ], + "properties": { + "amount": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "serve_axon" + ], + "properties": { + "serve_axon": { + "type": "object", + "required": [ + "ip", + "ip_type", + "netuid", + "placeholder1", + "placeholder2", + "port", + "protocol", + "version" + ], + "properties": { + "ip": { + "type": "integer", + "format": "uint128", + "minimum": 0.0 + }, + "ip_type": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "placeholder1": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "placeholder2": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "port": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "protocol": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "version": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "serve_prometheus" + ], + "properties": { + "serve_prometheus": { + "type": "object", + "required": [ + "ip", + "ip_type", + "netuid", + "port", + "version" + ], + "properties": { + "ip": { + "type": "integer", + "format": "uint128", + "minimum": 0.0 + }, + "ip_type": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "port": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "version": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "register" + ], + "properties": { + "register": { + "type": "object", + "required": [ + "block_number", + "coldkey", + "hotkey", + "netuid", + "nonce", + "work" + ], + "properties": { + "block_number": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "coldkey": { + "type": "string" + }, + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "nonce": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "work": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "root_register" + ], + "properties": { + "root_register": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "burned_register" + ], + "properties": { + "burned_register": { + "type": "object", + "required": [ + "hotkey", + "netuid" + ], + "properties": { + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "register_network" + ], + "properties": { + "register_network": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "dissolve_network" + ], + "properties": { + "dissolve_network": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_register" + ], + "properties": { + "sudo_register": { + "type": "object", + "required": [ + "coldkey", + "hotkey", + "netuid" + ], + "properties": { + "coldkey": { + "type": "string" + }, + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_default_take" + ], + "properties": { + "sudo_set_default_take": { + "type": "object", + "required": [ + "default_take" + ], + "properties": { + "default_take": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_serving_rate_limit" + ], + "properties": { + "sudo_set_serving_rate_limit": { + "type": "object", + "required": [ + "netuid", + "serving_rate_limit" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "serving_rate_limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_tx_rate_limit" + ], + "properties": { + "sudo_set_tx_rate_limit": { + "type": "object", + "required": [ + "tx_rate_limit" + ], + "properties": { + "tx_rate_limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_burn" + ], + "properties": { + "sudo_set_max_burn": { + "type": "object", + "required": [ + "max_burn", + "netuid" + ], + "properties": { + "max_burn": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_min_burn" + ], + "properties": { + "sudo_set_min_burn": { + "type": "object", + "required": [ + "min_burn", + "netuid" + ], + "properties": { + "min_burn": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_difficulty" + ], + "properties": { + "sudo_set_max_difficulty": { + "type": "object", + "required": [ + "max_difficulty", + "netuid" + ], + "properties": { + "max_difficulty": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_min_difficulty" + ], + "properties": { + "sudo_set_min_difficulty": { + "type": "object", + "required": [ + "min_difficulty", + "netuid" + ], + "properties": { + "min_difficulty": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_weights_set_rate_limit" + ], + "properties": { + "sudo_set_weights_set_rate_limit": { + "type": "object", + "required": [ + "netuid", + "weights_set_rate_limit" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "weights_set_rate_limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_weights_version_key" + ], + "properties": { + "sudo_set_weights_version_key": { + "type": "object", + "required": [ + "netuid", + "weights_version_key" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "weights_version_key": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_bonds_moving_average" + ], + "properties": { + "sudo_set_bonds_moving_average": { + "type": "object", + "required": [ + "bonds_moving_average", + "netuid" + ], + "properties": { + "bonds_moving_average": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_allowed_validators" + ], + "properties": { + "sudo_set_max_allowed_validators": { + "type": "object", + "required": [ + "max_allowed_validators", + "netuid" + ], + "properties": { + "max_allowed_validators": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_difficulty" + ], + "properties": { + "sudo_set_difficulty": { + "type": "object", + "required": [ + "difficulty", + "netuid" + ], + "properties": { + "difficulty": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_adjustment_interval" + ], + "properties": { + "sudo_set_adjustment_interval": { + "type": "object", + "required": [ + "adjustment_interval", + "netuid" + ], + "properties": { + "adjustment_interval": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_target_registrations_per_interval" + ], + "properties": { + "sudo_set_target_registrations_per_interval": { + "type": "object", + "required": [ + "netuid", + "target_registrations_per_interval" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "target_registrations_per_interval": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_activity_cutoff" + ], + "properties": { + "sudo_set_activity_cutoff": { + "type": "object", + "required": [ + "activity_cutoff", + "netuid" + ], + "properties": { + "activity_cutoff": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_rho" + ], + "properties": { + "sudo_set_rho": { + "type": "object", + "required": [ + "netuid", + "rho" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "rho": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_kappa" + ], + "properties": { + "sudo_set_kappa": { + "type": "object", + "required": [ + "kappa", + "netuid" + ], + "properties": { + "kappa": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_allowed_uids" + ], + "properties": { + "sudo_set_max_allowed_uids": { + "type": "object", + "required": [ + "max_allowed_uids", + "netuid" + ], + "properties": { + "max_allowed_uids": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_min_allowed_weights" + ], + "properties": { + "sudo_set_min_allowed_weights": { + "type": "object", + "required": [ + "min_allowed_weights", + "netuid" + ], + "properties": { + "min_allowed_weights": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_validator_prune_len" + ], + "properties": { + "sudo_set_validator_prune_len": { + "type": "object", + "required": [ + "netuid", + "validator_prune_len" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "validator_prune_len": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_immunity_period" + ], + "properties": { + "sudo_set_immunity_period": { + "type": "object", + "required": [ + "immunity_period", + "netuid" + ], + "properties": { + "immunity_period": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_weight_limit" + ], + "properties": { + "sudo_set_max_weight_limit": { + "type": "object", + "required": [ + "max_weight_limit", + "netuid" + ], + "properties": { + "max_weight_limit": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_max_registrations_per_block" + ], + "properties": { + "sudo_set_max_registrations_per_block": { + "type": "object", + "required": [ + "max_registrations_per_block", + "netuid" + ], + "properties": { + "max_registrations_per_block": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_total_issuance" + ], + "properties": { + "sudo_set_total_issuance": { + "type": "object", + "required": [ + "total_issuance" + ], + "properties": { + "total_issuance": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_tempo" + ], + "properties": { + "sudo_set_tempo": { + "type": "object", + "required": [ + "netuid", + "tempo" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "tempo": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_rao_recycled" + ], + "properties": { + "sudo_set_rao_recycled": { + "type": "object", + "required": [ + "netuid", + "rao_recycled" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "rao_recycled": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_registration_allowed" + ], + "properties": { + "sudo_set_registration_allowed": { + "type": "object", + "required": [ + "netuid", + "registration_allowed" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "registration_allowed": { + "type": "boolean" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_adjustment_alpha" + ], + "properties": { + "sudo_set_adjustment_alpha": { + "type": "object", + "required": [ + "adjustment_alpha", + "netuid" + ], + "properties": { + "adjustment_alpha": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_subnet_owner_cut" + ], + "properties": { + "sudo_set_subnet_owner_cut": { + "type": "object", + "required": [ + "cut" + ], + "properties": { + "cut": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_network_rate_limit" + ], + "properties": { + "sudo_set_network_rate_limit": { + "type": "object", + "required": [ + "rate_limit" + ], + "properties": { + "rate_limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_network_immunity_period" + ], + "properties": { + "sudo_set_network_immunity_period": { + "type": "object", + "required": [ + "immunity_period" + ], + "properties": { + "immunity_period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_network_min_lock_cost" + ], + "properties": { + "sudo_set_network_min_lock_cost": { + "type": "object", + "required": [ + "lock_cost" + ], + "properties": { + "lock_cost": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_subnet_limit" + ], + "properties": { + "sudo_set_subnet_limit": { + "type": "object", + "required": [ + "max_subnets" + ], + "properties": { + "max_subnets": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_lock_reduction_interval" + ], + "properties": { + "sudo_set_lock_reduction_interval": { + "type": "object", + "required": [ + "interval" + ], + "properties": { + "interval": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_validator_permit_for_uid" + ], + "properties": { + "sudo_set_validator_permit_for_uid": { + "type": "object", + "required": [ + "netuid", + "permit", + "uid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "permit": { + "type": "boolean" + }, + "uid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_block_emission" + ], + "properties": { + "sudo_set_block_emission": { + "type": "object", + "required": [ + "emission" + ], + "properties": { + "emission": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "sudo_set_subnet_metadata" + ], + "properties": { + "sudo_set_subnet_metadata": { + "type": "object", + "required": [ + "netuid", + "particle" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "particle": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] +} diff --git a/cybertensor/contract/schema/instantiate.json b/cybertensor/contract/schema/instantiate.json new file mode 100644 index 0000000..1352613 --- /dev/null +++ b/cybertensor/contract/schema/instantiate.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "additionalProperties": false +} diff --git a/cybertensor/contract/schema/query.json b/cybertensor/contract/schema/query.json new file mode 100644 index 0000000..d2bf796 --- /dev/null +++ b/cybertensor/contract/schema/query.json @@ -0,0 +1,856 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_delegates" + ], + "properties": { + "get_delegates": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_delegate" + ], + "properties": { + "get_delegate": { + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_delegated" + ], + "properties": { + "get_delegated": { + "type": "object", + "required": [ + "delegatee" + ], + "properties": { + "delegatee": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_neurons_lite" + ], + "properties": { + "get_neurons_lite": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_neuron_lite" + ], + "properties": { + "get_neuron_lite": { + "type": "object", + "required": [ + "netuid", + "uid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "uid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_neurons" + ], + "properties": { + "get_neurons": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_neuron" + ], + "properties": { + "get_neuron": { + "type": "object", + "required": [ + "netuid", + "uid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "uid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_subnet_info" + ], + "properties": { + "get_subnet_info": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_subnets_info" + ], + "properties": { + "get_subnets_info": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_subnet_hyperparams" + ], + "properties": { + "get_subnet_hyperparams": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_stake_info_for_coldkey" + ], + "properties": { + "get_stake_info_for_coldkey": { + "type": "object", + "required": [ + "coldkey" + ], + "properties": { + "coldkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_stake_info_for_coldkeys" + ], + "properties": { + "get_stake_info_for_coldkeys": { + "type": "object", + "required": [ + "coldkeys" + ], + "properties": { + "coldkeys": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_total_stake_for_hotkey" + ], + "properties": { + "get_total_stake_for_hotkey": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_total_stake_for_coldkey" + ], + "properties": { + "get_total_stake_for_coldkey": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_stake_for_coldkey_and_hotkey" + ], + "properties": { + "get_stake_for_coldkey_and_hotkey": { + "type": "object", + "required": [ + "coldkey", + "hotkey" + ], + "properties": { + "coldkey": { + "type": "string" + }, + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_hotkey_owner" + ], + "properties": { + "get_hotkey_owner": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_uid_for_hotkey_on_subnet" + ], + "properties": { + "get_uid_for_hotkey_on_subnet": { + "type": "object", + "required": [ + "hotkey", + "netuid" + ], + "properties": { + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_netuids_for_hotkey" + ], + "properties": { + "get_netuids_for_hotkey": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_hotkey_exist" + ], + "properties": { + "get_hotkey_exist": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_stake" + ], + "properties": { + "get_stake": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_delegate_take" + ], + "properties": { + "get_delegate_take": { + "type": "object", + "required": [ + "hotkey" + ], + "properties": { + "hotkey": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_subnet_exist" + ], + "properties": { + "get_subnet_exist": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_subnet_owner" + ], + "properties": { + "get_subnet_owner": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_max_weight_limit" + ], + "properties": { + "get_max_weight_limit": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_min_allowed_weights" + ], + "properties": { + "get_min_allowed_weights": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_burn" + ], + "properties": { + "get_burn": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_difficulty" + ], + "properties": { + "get_difficulty": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_tempo" + ], + "properties": { + "get_tempo": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_emission_value_by_subnet" + ], + "properties": { + "get_emission_value_by_subnet": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_network_registration_cost" + ], + "properties": { + "get_network_registration_cost": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_total_networks" + ], + "properties": { + "get_total_networks": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_networks_added" + ], + "properties": { + "get_networks_added": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_all_subnet_netuids" + ], + "properties": { + "get_all_subnet_netuids": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_total_issuance" + ], + "properties": { + "get_total_issuance": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_total_stake" + ], + "properties": { + "get_total_stake": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_tx_rate_limit" + ], + "properties": { + "get_tx_rate_limit": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_axon_info" + ], + "properties": { + "get_axon_info": { + "type": "object", + "required": [ + "hotkey", + "netuid" + ], + "properties": { + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_prometheus_info" + ], + "properties": { + "get_prometheus_info": { + "type": "object", + "required": [ + "hotkey", + "netuid" + ], + "properties": { + "hotkey": { + "type": "string" + }, + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_weights" + ], + "properties": { + "get_weights": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_weights_sparse" + ], + "properties": { + "get_weights_sparse": { + "type": "object", + "required": [ + "netuid" + ], + "properties": { + "netuid": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_state" + ], + "properties": { + "get_state": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] +} From 185de912326fea58b8c046ba5fdb458e3167ccb3 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Tue, 13 Feb 2024 18:26:57 +0800 Subject: [PATCH 14/23] - update python version --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f28cdc7..544c3fd 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ def read_requirements(path): include_package_data=True, author_email="", license="MIT", - python_requires=">=3.8", + python_requires="3.9,<3.12", install_requires=requirements, extras_require={ "dev": extra_requirements_dev, @@ -86,9 +86,9 @@ def read_requirements(path): # Pick your license as you wish "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Mathematics", "Topic :: Scientific/Engineering :: Artificial Intelligence", From ee9129730d64a36eb114fa0fa7ea14522f96287f Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Wed, 14 Feb 2024 18:35:53 +0800 Subject: [PATCH 15/23] - optimize imports - add random start time for load test --- cybertensor/__init__.py | 40 +++++++++++++-------------- cybertensor/axon.py | 6 ++-- cybertensor/chain_data.py | 4 +-- cybertensor/cli.py | 8 +++--- cybertensor/commands/__init__.py | 26 ++++++++--------- cybertensor/commands/delegates.py | 20 +++++++------- cybertensor/commands/inspect.py | 15 +++++----- cybertensor/commands/list.py | 4 +-- cybertensor/commands/metagraph.py | 13 +++++---- cybertensor/commands/network.py | 10 +++---- cybertensor/commands/overview.py | 21 +++++++------- cybertensor/commands/register.py | 12 ++++---- cybertensor/commands/root.py | 10 +++---- cybertensor/commands/stake.py | 6 ++-- cybertensor/commands/transfer.py | 8 +++--- cybertensor/commands/unstake.py | 12 ++++---- cybertensor/commands/utils.py | 8 +++--- cybertensor/commands/wallets.py | 8 +++--- cybertensor/cwtensor.py | 39 +++++++++++++------------- cybertensor/dendrite.py | 2 +- cybertensor/keyfile.py | 8 +++--- cybertensor/keypair.py | 8 +++--- cybertensor/messages/delegation.py | 28 +++++++++---------- cybertensor/messages/log_utilities.py | 4 +-- cybertensor/messages/network.py | 6 ++-- cybertensor/messages/prometheus.py | 9 +++--- cybertensor/messages/registration.py | 8 +++--- cybertensor/messages/root.py | 6 ++-- cybertensor/messages/serving.py | 8 +++--- cybertensor/messages/set_weights.py | 6 ++-- cybertensor/messages/staking.py | 34 +++++++++++------------ cybertensor/messages/transfer.py | 16 +++++------ cybertensor/messages/unstaking.py | 26 ++++++++--------- cybertensor/stream.py | 4 +-- cybertensor/threadpool.py | 6 ++-- cybertensor/utils/__init__.py | 4 +-- cybertensor/utils/registration.py | 8 +++--- cybertensor/utils/weight_utils.py | 2 +- cybertensor/wallet.py | 6 ++-- load_test_main.py | 3 +- requirements/prod.txt | 1 + 41 files changed, 238 insertions(+), 235 deletions(-) diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index ad031c6..51ae704 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -18,7 +18,6 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -from pathlib import Path from typing import Optional, Union # Install and apply nest asyncio to allow the async functions @@ -176,26 +175,25 @@ def __init__( __default_gas__ = None __default_transfer_gas__ = 100_000 -from .errors import * -from .config import * -from .keyfile import * -from .keypair import * -from .wallet import * -from .utils import * -from .utils.balance import Balance as Balance -from .chain_data import * -from .cwtensor import cwtensor as cwtensor -from .cli import cli as cli, COMMANDS as ALL_COMMANDS -from .ctlogging import logging as logging -from .metagraph import metagraph as metagraph -from .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor - -from .synapse import * -from .stream import * -from .tensor import * -from .axon import axon as axon -from .dendrite import dendrite as dendrite -from .config import Config +from cybertensor.errors import * +from cybertensor.keyfile import keyfile +from cybertensor.keypair import Keypair +from cybertensor.wallet import Wallet +from cybertensor.utils import * +from cybertensor.utils.balance import Balance +from cybertensor.chain_data import AxonInfo, NeuronInfo, NeuronInfoLite, PrometheusInfo, StakeInfo, SubnetInfo, SubnetHyperparameters +from cybertensor.cwtensor import cwtensor +from cybertensor.cli import cli, COMMANDS as ALL_COMMANDS +from cybertensor.ctlogging import logging +from cybertensor.metagraph import metagraph +from cybertensor.threadpool import PriorityThreadPoolExecutor + +from cybertensor.synapse import TerminalInfo, Synapse +from cybertensor.stream import StreamingSynapse +from cybertensor.tensor import tensor, Tensor +from cybertensor.axon import axon +from cybertensor.dendrite import dendrite +from cybertensor.config import Config configs = [ axon.config(), diff --git a/cybertensor/axon.py b/cybertensor/axon.py index 7d746bc..cd51d98 100644 --- a/cybertensor/axon.py +++ b/cybertensor/axon.py @@ -40,9 +40,9 @@ from starlette.responses import Response import cybertensor -from .keypair import Keypair -from .wallet import Wallet -from .config import Config +from cybertensor.keypair import Keypair +from cybertensor.wallet import Wallet +from cybertensor.config import Config """ Create and init Axon, which services Forward and Backward requests from other neurons. """ diff --git a/cybertensor/chain_data.py b/cybertensor/chain_data.py index 7105a80..c2f5af1 100644 --- a/cybertensor/chain_data.py +++ b/cybertensor/chain_data.py @@ -22,8 +22,8 @@ import cybertensor # from cybertensor import SubnetHyperparameters -from .utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA -from .utils.balance import Balance +from cybertensor.utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA +from cybertensor.utils.balance import Balance # Dataclasses for chain data. diff --git a/cybertensor/cli.py b/cybertensor/cli.py index d458b10..62876c4 100644 --- a/cybertensor/cli.py +++ b/cybertensor/cli.py @@ -21,10 +21,10 @@ from typing import List, Optional import cybertensor -from . import __console__ as console -from .commands import * -from .commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand -from .config import Config +from cybertensor.commands import * +from cybertensor.commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand +from cybertensor.config import Config +from cybertensor import __console__ as console ALIAS_TO_COMMAND = { "subnets": "subnets", diff --git a/cybertensor/commands/__init__.py b/cybertensor/commands/__init__.py index 6266583..0a3d192 100644 --- a/cybertensor/commands/__init__.py +++ b/cybertensor/commands/__init__.py @@ -63,22 +63,22 @@ } ) -from .overview import OverviewCommand -from .stake import StakeCommand, StakeShow -from .unstake import UnStakeCommand -from .register import ( +from cybertensor.commands.overview import OverviewCommand +from cybertensor.commands.stake import StakeCommand, StakeShow +from cybertensor.commands.unstake import UnStakeCommand +from cybertensor.commands.register import ( PowRegisterCommand, RegisterCommand, # RunFaucetCommand ) -from .delegates import ( +from cybertensor.commands.delegates import ( NominateCommand, ListDelegatesCommand, DelegateStakeCommand, DelegateUnstakeCommand, MyDelegatesCommand, ) -from .wallets import ( +from cybertensor.commands.wallets import ( NewColdkeyCommand, NewHotkeyCommand, RegenColdkeyCommand, @@ -88,12 +88,12 @@ WalletCreateCommand, WalletBalanceCommand, ) -from .transfer import TransferCommand -from .inspect import InspectCommand -from .metagraph import MetagraphCommand -from .list import ListCommand -# from .misc import UpdateCommand -from .network import ( +from cybertensor.commands.transfer import TransferCommand +from cybertensor.commands.inspect import InspectCommand +from cybertensor.commands.metagraph import MetagraphCommand +from cybertensor.commands.list import ListCommand +# from cybertensor.commands.misc import UpdateCommand +from cybertensor.commands.network import ( RegisterSubnetworkCommand, SubnetLockCostCommand, SubnetListCommand, @@ -101,7 +101,7 @@ SubnetHyperparamsCommand, SubnetGetHyperparamsCommand, ) -from .root import ( +from cybertensor.commands.root import ( RootRegisterCommand, RootList, RootSetWeightsCommand, diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py index 19c5663..e71ba9f 100644 --- a/cybertensor/commands/delegates.py +++ b/cybertensor/commands/delegates.py @@ -22,17 +22,17 @@ from typing import List, Dict, Optional from rich.console import Text -from rich.prompt import Confirm from rich.prompt import Prompt from rich.table import Table from tqdm import tqdm import cybertensor -from . import defaults -from .utils import DelegatesDetails -from .. import __console__ as console -from ..config import Config -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.commands.utils import DelegatesDetails +from cybertensor.config import Config +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: @@ -168,7 +168,7 @@ def show_delegates( lambda x: x[0] == delegate.owner, delegate.nominators ), # filter for owner ), - cybertensor.Balance.from_boot(0), # default to 0 if no owner stake. + Balance.from_boot(0), # default to 0 if no owner stake. ) if delegate.hotkey in registered_delegate_info: delegate_name = registered_delegate_info[delegate.hotkey].name @@ -215,8 +215,8 @@ def show_delegates( rate_change_in_stake_str, str(delegate.registrations), f"{delegate.take * 100:.1f}%", - f"{cybertensor.Balance.from_gboot(delegate.total_daily_return.gboot * (1000 / (0.001 + delegate.total_stake.gboot)))!s:6.6}", - f"{cybertensor.Balance.from_gboot(delegate.total_daily_return.gboot * (0.18)) !s:6.6}", + f"{Balance.from_gboot(delegate.total_daily_return.gboot * (1000 / (0.001 + delegate.total_stake.gboot)))!s:6.6}", + f"{Balance.from_gboot(delegate.total_daily_return.gboot * (0.18)) !s:6.6}", str(delegate_description), end_section=True, ) @@ -765,7 +765,7 @@ def run(cli): delegate[0].nominators, ), # filter for owner ), - cybertensor.Balance.from_boot(0), # default to 0 if no owner stake. + Balance.from_boot(0), # default to 0 if no owner stake. ) if delegate[0].hotkey in registered_delegate_info: delegate_name = registered_delegate_info[ diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py index c02e60b..03ed967 100644 --- a/cybertensor/commands/inspect.py +++ b/cybertensor/commands/inspect.py @@ -25,11 +25,12 @@ from tqdm import tqdm import cybertensor -from . import defaults -from .utils import get_delegates_details, DelegatesDetails -from ..config import Config -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.commands.utils import get_delegates_details, DelegatesDetails +from cybertensor.config import Config +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: @@ -160,7 +161,7 @@ def run(cli) -> None: ) for wallet in tqdm(wallets): delegates: List[ - Tuple[cybertensor.DelegateInfo, cybertensor.Balance] + Tuple[cybertensor.DelegateInfo, Balance] ] = cwtensor.get_delegated(delegatee=wallet.coldkeypub.address) if not wallet.coldkeypub_file.exists_on_device(): continue @@ -212,7 +213,7 @@ def run(cli) -> None: str(netuid), f"{hotkey_name}{neuron.hotkey}", str(neuron.stake), - str(cybertensor.Balance.from_boot(neuron.emission)), + str(Balance.from_boot(neuron.emission)), ) console.print(table) diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py index ea322ff..277e98e 100644 --- a/cybertensor/commands/list.py +++ b/cybertensor/commands/list.py @@ -23,8 +23,8 @@ from rich.tree import Tree import cybertensor -from ..wallet import Wallet -from ..config import Config +from cybertensor.config import Config +from cybertensor.wallet import Wallet class ListCommand: diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py index b5b9940..d18ab14 100644 --- a/cybertensor/commands/metagraph.py +++ b/cybertensor/commands/metagraph.py @@ -21,9 +21,10 @@ from rich.table import Table import cybertensor -from .utils import check_netuid_set -from .. import __console__ as console -from ..config import Config +from cybertensor import __console__ as console +from cybertensor.commands.utils import check_netuid_set +from cybertensor.config import Config +from cybertensor.utils.balance import Balance # TODO change tokens in table to boot and gigaboot @@ -84,10 +85,10 @@ def run(cli): metagraph: cybertensor.metagraph = cwtensor.metagraph(netuid=cli.config.netuid) metagraph.save() difficulty = cwtensor.difficulty(cli.config.netuid) - # subnet_emission = cybertensor.Balance.from_gboot( + # subnet_emission = Balance.from_gboot( # cwtensor.get_emission_value_by_subnet(cli.config.netuid) # ) - total_issuance = cybertensor.Balance.from_boot(cwtensor.total_issuance().boot) + total_issuance = Balance.from_boot(cwtensor.total_issuance().boot) TABLE_DATA = [] total_stake = 0.0 @@ -137,7 +138,7 @@ def run(cli): metagraph.block.item(), sum(metagraph.active.tolist()), metagraph.n.item(), - cybertensor.Balance.from_gboot(total_stake), + Balance.from_gboot(total_stake), total_issuance, difficulty, ) diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py index 314925e..db37fb7 100644 --- a/cybertensor/commands/network.py +++ b/cybertensor/commands/network.py @@ -26,11 +26,11 @@ from rich.table import Table import cybertensor -from . import defaults -from .utils import DelegatesDetails, check_netuid_set -from .. import __console__ as console -from ..config import Config -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.commands.utils import DelegatesDetails, check_netuid_set +from cybertensor.config import Config +from cybertensor.wallet import Wallet class RegisterSubnetworkCommand: diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index a813136..b14a7a7 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -27,15 +27,16 @@ from tqdm import tqdm import cybertensor -from . import defaults -from .utils import ( +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.commands.utils import ( get_hotkey_wallets_for_wallet, get_coldkey_wallets_for_path, get_all_wallets_for_path, ) -from ..config import Config -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor.config import Config +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet class OverviewCommand: @@ -83,7 +84,7 @@ def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5) cwtensor: "cybertensor.cwtensor" = cybertensor.cwtensor(config=cli.config) all_hotkeys = [] - total_balance = cybertensor.Balance(0) + total_balance = Balance(0) # We are printing for every coldkey. if cli.config.get("all", d=None): @@ -185,7 +186,7 @@ def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5) neurons[str(netuid)] = neurons_result total_coldkey_stake_from_metagraph = defaultdict( - lambda: cybertensor.Balance(0.0) + lambda: Balance(0.0) ) checked_hotkeys = set() for neuron_list in neurons.values(): @@ -246,7 +247,7 @@ def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5) de_registered_neuron.coldkey = ( coldkey_wallet.coldkeypub.address ) - de_registered_neuron.total_stake = cybertensor.Balance(our_stake) + de_registered_neuron.total_stake = Balance(our_stake) de_registered_neurons.append(de_registered_neuron) @@ -558,12 +559,12 @@ def _get_neurons_for_netuid( def _get_de_registered_stake_for_coldkey_wallet( args_tuple, ) -> Tuple[ - "Wallet", List[Tuple[str, "cybertensor.Balance"]], Optional[str] + "Wallet", List[Tuple[str, "Balance"]], Optional[str] ]: cwtensor_config, all_hotkey_addresses, coldkey_wallet = args_tuple # List of (hotkey_addr, our_stake) tuples. - result: List[Tuple[str, "cybertensor.Balance"]] = [] + result: List[Tuple[str, "Balance"]] = [] try: cwtensor = cybertensor.cwtensor(config=cwtensor_config) diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py index fa58e50..08bdec0 100644 --- a/cybertensor/commands/register.py +++ b/cybertensor/commands/register.py @@ -22,12 +22,12 @@ from rich.prompt import Prompt, Confirm import cybertensor -from . import defaults -from .utils import check_netuid_set, check_for_cuda_reg_config -from .. import __console__ as console -from ..config import Config -from ..utils.balance import Balance -from ..wallet import Wallet +from cybertensor.commands import defaults +from cybertensor.commands.utils import check_netuid_set, check_for_cuda_reg_config +from cybertensor import __console__ as console +from cybertensor.config import Config +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet class RegisterCommand: diff --git a/cybertensor/commands/root.py b/cybertensor/commands/root.py index b46f17c..b792bc7 100644 --- a/cybertensor/commands/root.py +++ b/cybertensor/commands/root.py @@ -27,11 +27,11 @@ from rich.table import Table import cybertensor -from . import defaults -from .utils import DelegatesDetails -from .. import __console__ as console -from ..config import Config -from ..wallet import Wallet +from cybertensor.commands import defaults +from cybertensor.commands.utils import DelegatesDetails +from cybertensor import __console__ as console +from cybertensor.config import Config +from cybertensor.wallet import Wallet class RootRegisterCommand: diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index 26a5fe3..fdb4efd 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -21,9 +21,9 @@ from rich.prompt import Confirm -from .utils import get_hotkey_wallets_for_wallet -from ..config import Config -from ..utils.balance import Balance +from cybertensor.commands.utils import get_hotkey_wallets_for_wallet +from cybertensor.config import Config +from cybertensor.utils.balance import Balance class StakeCommand: diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py index 7cebeda..a96716b 100644 --- a/cybertensor/commands/transfer.py +++ b/cybertensor/commands/transfer.py @@ -23,10 +23,10 @@ from rich.prompt import Prompt import cybertensor -from . import defaults -from .. import __console__ as console -from ..config import Config -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.config import Config +from cybertensor.wallet import Wallet class TransferCommand: diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py index 413ecef..f9b855b 100644 --- a/cybertensor/commands/unstake.py +++ b/cybertensor/commands/unstake.py @@ -23,12 +23,12 @@ from tqdm import tqdm import cybertensor -from . import defaults -from .utils import get_hotkey_wallets_for_wallet -from .. import __console__ as console -from ..config import Config -from ..utils.balance import Balance -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.commands.utils import get_hotkey_wallets_for_wallet +from cybertensor.config import Config +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet class UnStakeCommand: diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py index f8699e2..adcf228 100644 --- a/cybertensor/commands/utils.py +++ b/cybertensor/commands/utils.py @@ -26,10 +26,10 @@ from rich.prompt import Confirm, PromptBase import cybertensor -from . import defaults -from .wallets import Wallet -from .. import __console__ as console -from ..config import Config +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.config import Config +from cybertensor.wallet import Wallet class IntListPrompt(PromptBase): diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index b69f83e..9d3e7c2 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -25,10 +25,10 @@ from rich.table import Table import cybertensor -from . import defaults -from ..wallet import Wallet -from ..config import Config -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.commands import defaults +from cybertensor.config import Config +from cybertensor.wallet import Wallet # TODO rewrite to use raw pubkey against hex or rewrite keypair/keyfile to use hex diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index 89b62c6..7f3236a 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -32,7 +32,8 @@ from retry import retry import cybertensor -from .chain_data import ( +from cybertensor import __console__ as console +from cybertensor.chain_data import ( NeuronInfo, DelegateInfo, PrometheusInfo, @@ -42,34 +43,34 @@ NeuronInfoLite, AxonInfo, ) -from .commands.utils import DelegatesDetails -from .config import Config -from .errors import * -from .messages.delegation import ( +from cybertensor.commands.utils import DelegatesDetails +from cybertensor.config import Config +from cybertensor.errors import * +from cybertensor.messages.delegation import ( delegate_message, nominate_message, undelegate_message, ) -from .messages.network import ( +from cybertensor.messages.network import ( register_subnetwork_message, set_hyperparameter_message, ) -from .messages.prometheus import prometheus_message -from .messages.registration import ( +from cybertensor.messages.prometheus import prometheus_message +from cybertensor.messages.registration import ( register_message, burned_register_message, ) -from .messages.root import root_register_message, set_root_weights_message -from .messages.serving import serve_message, serve_axon_message -from .messages.set_weights import set_weights_message -from .messages.staking import add_stake_message, add_stake_multiple_message -from .messages.transfer import transfer_message -from .messages.unstaking import unstake_message, unstake_multiple_message -from .types import AxonServeCallParams, PrometheusServeCallParams -from .utils import U16_NORMALIZED_FLOAT, coin_from_str -from .utils.balance import Balance -from .utils.registration import POWSolution -from .wallet import Wallet +from cybertensor.messages.root import root_register_message, set_root_weights_message +from cybertensor.messages.serving import serve_message, serve_axon_message +from cybertensor.messages.set_weights import set_weights_message +from cybertensor.messages.staking import add_stake_message, add_stake_multiple_message +from cybertensor.messages.transfer import transfer_message +from cybertensor.messages.unstaking import unstake_message, unstake_multiple_message +from cybertensor.types import AxonServeCallParams, PrometheusServeCallParams +from cybertensor.utils import U16_NORMALIZED_FLOAT, coin_from_str +from cybertensor.utils.balance import Balance +from cybertensor.utils.registration import POWSolution +from cybertensor.wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/dendrite.py b/cybertensor/dendrite.py index 9c1dd2d..d49e2fe 100644 --- a/cybertensor/dendrite.py +++ b/cybertensor/dendrite.py @@ -30,7 +30,7 @@ from fastapi import Response import cybertensor -from .wallet import Wallet +from cybertensor.wallet import Wallet class dendrite(torch.nn.Module): diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index 14dc438..85c129c 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -37,10 +37,10 @@ from termcolor import colored import cybertensor -from .keypair import Keypair -from . import __console__ as console -from . import __chain_address_prefix__ -from .errors import KeyFileError +from cybertensor import __chain_address_prefix__ +from cybertensor.errors import KeyFileError +from cybertensor.keypair import Keypair +from cybertensor import __console__ as console NACL_SALT = b"\x13q\x83\xdf\xf1Z\t\xbc\x9c\x90\xb5Q\x879\xe9\xb1" diff --git a/cybertensor/keypair.py b/cybertensor/keypair.py index a8f3117..afbbb25 100644 --- a/cybertensor/keypair.py +++ b/cybertensor/keypair.py @@ -26,7 +26,7 @@ validate_mnemonic_and_normalise, ) -import cybertensor +from cybertensor import __chain_address_prefix__ class Keypair: @@ -49,7 +49,7 @@ def __init__( """ if prefix is None: - prefix = cybertensor.__chain_address_prefix__ + prefix = __chain_address_prefix__ self.prefix = prefix @@ -120,7 +120,7 @@ def create_from_mnemonic( """ if prefix is None: - prefix = cybertensor.__chain_address_prefix__ + prefix = __chain_address_prefix__ mnemonic = validate_mnemonic_and_normalise(mnemonic) @@ -149,7 +149,7 @@ def create_from_private_key( """ if prefix is None: - prefix = cybertensor.__chain_address_prefix__ + prefix = __chain_address_prefix__ return cls( public_key=PrivateKey(private_key).public_key.public_key, diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py index 91c44f5..924973e 100644 --- a/cybertensor/messages/delegation.py +++ b/cybertensor/messages/delegation.py @@ -24,10 +24,10 @@ from rich.prompt import Confirm import cybertensor -from .. import __console__ as console -from ..errors import * -from ..utils.balance import Balance -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.errors import * +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet logger = logger.opt(colors=True) @@ -140,18 +140,18 @@ def delegate_message( coldkey=wallet.coldkeypub.address, hotkey=delegate ) - # Convert to cybertensor.Balance + # Convert to Balance if amount is None: # Stake it all. - staking_balance = cybertensor.Balance.from_gboot(my_prev_coldkey_balance.gboot) - elif not isinstance(amount, cybertensor.Balance): - staking_balance = cybertensor.Balance.from_gboot(amount) + staking_balance = Balance.from_gboot(my_prev_coldkey_balance.gboot) + elif not isinstance(amount, Balance): + staking_balance = Balance.from_gboot(amount) else: staking_balance = amount # Remove existential balance to keep key alive. - if staking_balance > cybertensor.Balance.from_boot(1000000): - staking_balance = staking_balance - cybertensor.Balance.from_boot(1000000) + if staking_balance > Balance.from_boot(1000000): + staking_balance = staking_balance - Balance.from_boot(1000000) else: staking_balance = staking_balance @@ -274,13 +274,13 @@ def undelegate_message( coldkey=wallet.coldkeypub.address, hotkey=delegate ) - # Convert to cybertensor.Balance + # Convert to Balance if amount is None: # Stake it all. - unstaking_balance = cybertensor.Balance.from_gboot(my_prev_delegated_stake.gboot) + unstaking_balance = Balance.from_gboot(my_prev_delegated_stake.gboot) - elif not isinstance(amount, cybertensor.Balance): - unstaking_balance = cybertensor.Balance.from_gboot(amount) + elif not isinstance(amount, Balance): + unstaking_balance = Balance.from_gboot(amount) else: unstaking_balance = amount diff --git a/cybertensor/messages/log_utilities.py b/cybertensor/messages/log_utilities.py index 625f108..a824b4e 100644 --- a/cybertensor/messages/log_utilities.py +++ b/cybertensor/messages/log_utilities.py @@ -11,8 +11,8 @@ from rich.table import Table import cybertensor -from ..wallet import Wallet -from ..config import Config +from cybertensor.wallet import Wallet +from cybertensor.config import Config class ValidatorLogger: diff --git a/cybertensor/messages/network.py b/cybertensor/messages/network.py index a7f2524..3cd901e 100644 --- a/cybertensor/messages/network.py +++ b/cybertensor/messages/network.py @@ -22,9 +22,9 @@ from rich.prompt import Confirm import cybertensor -from ..utils.balance import Balance -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet def register_subnetwork_message( diff --git a/cybertensor/messages/prometheus.py b/cybertensor/messages/prometheus.py index 8737d7b..d15934f 100644 --- a/cybertensor/messages/prometheus.py +++ b/cybertensor/messages/prometheus.py @@ -20,11 +20,10 @@ import json import cybertensor - -from ..wallet import Wallet -from ..utils import networking as net -from ..types import PrometheusServeCallParams -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.types import PrometheusServeCallParams +from cybertensor.utils import networking as net +from cybertensor.wallet import Wallet def prometheus_message( diff --git a/cybertensor/messages/registration.py b/cybertensor/messages/registration.py index 201bfa7..4627fa3 100644 --- a/cybertensor/messages/registration.py +++ b/cybertensor/messages/registration.py @@ -24,10 +24,10 @@ from rich.prompt import Confirm import cybertensor -from ..utils.balance import Balance -from ..utils.registration import POWSolution, create_pow -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.utils.balance import Balance +from cybertensor.utils.registration import POWSolution, create_pow +from cybertensor.wallet import Wallet def register_message( diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index d9f0c21..d2b1b8c 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -25,9 +25,9 @@ from rich.prompt import Confirm import cybertensor -from .. import __console__ as console -from ..utils import weight_utils -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.utils.weight_utils import normalize_max_weight, convert_weights_and_uids_for_emit +from cybertensor.wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py index efab35f..eece0a8 100644 --- a/cybertensor/messages/serving.py +++ b/cybertensor/messages/serving.py @@ -21,10 +21,10 @@ from rich.prompt import Confirm import cybertensor -from .. import __console__ as console -from ..types import AxonServeCallParams -from ..utils import networking as net -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.types import AxonServeCallParams +from cybertensor.utils import networking as net +from cybertensor.wallet import Wallet def serve_message( diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index d67fddb..38fc593 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -24,9 +24,9 @@ from rich.prompt import Confirm import cybertensor -from .. import __console__ as console -from ..utils import weight_utils -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.utils import weight_utils +from cybertensor.wallet import Wallet logger = logger.opt(colors=True) diff --git a/cybertensor/messages/staking.py b/cybertensor/messages/staking.py index ed0d644..9cd05de 100644 --- a/cybertensor/messages/staking.py +++ b/cybertensor/messages/staking.py @@ -23,9 +23,9 @@ from rich.prompt import Confirm import cybertensor -from ..utils.balance import Balance -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet def add_stake_message( @@ -93,18 +93,18 @@ def add_stake_message( coldkey=wallet.coldkeypub.address, hotkey=hotkey ) - # Convert to cybertensor.Balance + # Convert to Balance if amount is None: # Stake it all. - staking_balance = cybertensor.Balance.from_gboot(old_balance.gboot) - elif not isinstance(amount, cybertensor.Balance): - staking_balance = cybertensor.Balance.from_gboot(amount) + staking_balance = Balance.from_gboot(old_balance.gboot) + elif not isinstance(amount, Balance): + staking_balance = Balance.from_gboot(amount) else: staking_balance = amount # Remove existential balance to keep key alive. - if staking_balance > cybertensor.Balance.from_boot(1000000): - staking_balance = staking_balance - cybertensor.Balance.from_boot(1000000) + if staking_balance > Balance.from_boot(1000000): + staking_balance = staking_balance - Balance.from_boot(1000000) else: staking_balance = staking_balance @@ -236,7 +236,7 @@ def add_stake_multiple_message( isinstance(amount, (Balance, float)) for amount in amounts ): raise TypeError( - "amounts must be a [list of cybertensor.Balance or float] or None" + "amounts must be a [list of Balance or float] or None" ) if amounts is None: @@ -244,7 +244,7 @@ def add_stake_multiple_message( else: # Convert to Balance amounts = [ - cybertensor.Balance.from_gboot(amount) + Balance.from_gboot(amount) if isinstance(amount, float) else amount for amount in amounts @@ -279,7 +279,7 @@ def add_stake_multiple_message( if total_staking_boot == 0: # Staking all to the first wallet. if old_balance.boot > 1000000: - old_balance -= cybertensor.Balance.from_boot(1000000) + old_balance -= Balance.from_boot(1000000) elif total_staking_boot < 1000000: # Staking less than 1000 boot to the wallets. @@ -297,14 +297,14 @@ def add_stake_multiple_message( zip(hotkeys, amounts, old_stakes) ): staking_all = False - # Convert to cybertensor.Balance + # Convert to Balance if amount is None: # Stake it all. - staking_balance = cybertensor.Balance.from_gboot(old_balance.gboot) + staking_balance = Balance.from_gboot(old_balance.gboot) staking_all = True else: # Amounts are cast to balance earlier in the function - assert isinstance(amount, cybertensor.Balance) + assert isinstance(amount, Balance) staking_balance = amount # Check enough to stake @@ -409,7 +409,7 @@ def __do_add_stake_single( cwtensor: "cybertensor.cwtensor", wallet: "Wallet", hotkey: str, - amount: "cybertensor.Balance", + amount: "Balance", wait_for_finalization: bool = True, ) -> bool: r""" @@ -419,7 +419,7 @@ def __do_add_stake_single( cybertensor wallet object. hotkey (str): Hotkey to stake to. - amount (cybertensor.Balance): + amount (Balance): Amount to stake as cybertensor balance object. wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning true, diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py index 4e264db..13da2f2 100644 --- a/cybertensor/messages/transfer.py +++ b/cybertensor/messages/transfer.py @@ -24,10 +24,10 @@ from rich.prompt import Confirm import cybertensor -from ..utils import is_valid_address -from ..utils.balance import Balance -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor.utils import is_valid_address +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet +from cybertensor import __console__ as console def transfer_message( @@ -73,9 +73,9 @@ def transfer_message( # Unlock wallet coldkey. wallet.coldkey - # Convert to cybertensor.Balance - if not isinstance(amount, cybertensor.Balance): - transfer_balance = cybertensor.Balance.from_gboot(amount) + # Convert to Balance + if not isinstance(amount, Balance): + transfer_balance = Balance.from_gboot(amount) else: transfer_balance = amount @@ -90,7 +90,7 @@ def transfer_message( if not keep_alive: # Check if the transfer should keep_alive the account - existential_deposit = cybertensor.Balance(0) + existential_deposit = Balance(0) # Check if we have enough balance. if account_balance < (transfer_balance + fee + existential_deposit): diff --git a/cybertensor/messages/unstaking.py b/cybertensor/messages/unstaking.py index 8494282..28631bb 100644 --- a/cybertensor/messages/unstaking.py +++ b/cybertensor/messages/unstaking.py @@ -23,16 +23,16 @@ from rich.prompt import Confirm import cybertensor -from ..utils.balance import Balance -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor import __console__ as console +from cybertensor.utils.balance import Balance +from cybertensor.wallet import Wallet def __do_remove_stake_single( cwtensor: "cybertensor.cwtensor", wallet: "Wallet", hotkey: str, - amount: "cybertensor.Balance", + amount: "Balance", wait_for_finalization: bool = True, ) -> bool: r""" @@ -42,7 +42,7 @@ def __do_remove_stake_single( Cybertensor wallet object. hotkey (str): Hotkey address to unstake from. - amount (cybertensor.Balance): + amount (Balance): Amount to unstake as cybertensor balance object. wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning true, @@ -114,12 +114,12 @@ def unstake_message( coldkey=wallet.coldkeypub.address, hotkey=hotkey ) - # Convert to cybertensor.Balance + # Convert to Balance if amount is None: # Unstake it all. unstaking_balance = old_stake - elif not isinstance(amount, cybertensor.Balance): - unstaking_balance = cybertensor.Balance.from_gboot(amount) + elif not isinstance(amount, Balance): + unstaking_balance = Balance.from_gboot(amount) else: unstaking_balance = amount @@ -235,7 +235,7 @@ def unstake_multiple_message( isinstance(amount, (Balance, float)) for amount in amounts ): raise TypeError( - "amounts must be a [list of cybertensor.Balance or float] or None" + "amounts must be a [list of Balance or float] or None" ) if amounts is None: @@ -243,7 +243,7 @@ def unstake_multiple_message( else: # Convert to Balance amounts = [ - cybertensor.Balance.from_gboot(amount) + Balance.from_gboot(amount) if isinstance(amount, float) else amount for amount in amounts @@ -270,12 +270,12 @@ def unstake_multiple_message( successful_unstakes = 0 for idx, (hotkey, amount, old_stake) in enumerate(zip(hotkey, amounts, old_stakes)): - # Covert to cybertensor.Balance + # Covert to Balance if amount is None: # Unstake it all. unstaking_balance = old_stake - elif not isinstance(amount, cybertensor.Balance): - unstaking_balance = cybertensor.Balance.from_gboot(amount) + elif not isinstance(amount, Balance): + unstaking_balance = Balance.from_gboot(amount) else: unstaking_balance = amount diff --git a/cybertensor/stream.py b/cybertensor/stream.py index 0ddd795..6367d9f 100644 --- a/cybertensor/stream.py +++ b/cybertensor/stream.py @@ -6,7 +6,7 @@ from starlette.responses import StreamingResponse as _StreamingResponse from starlette.types import Send, Receive, Scope -import cybertensor +from cybertensor.synapse import Synapse class BTStreamingResponseModel(BaseModel): @@ -30,7 +30,7 @@ class BTStreamingResponseModel(BaseModel): token_streamer: Callable[[Send], Awaitable[None]] -class StreamingSynapse(cybertensor.Synapse, ABC): +class StreamingSynapse(Synapse, ABC): """ The StreamingSynapse class is designed to be subclassed for handling streaming responses in the Cybertensor network. It provides abstract methods that must be implemented by the subclass to deserialize, process streaming responses, diff --git a/cybertensor/threadpool.py b/cybertensor/threadpool.py index 5893735..17842b8 100644 --- a/cybertensor/threadpool.py +++ b/cybertensor/threadpool.py @@ -19,8 +19,8 @@ from loguru import logger -import cybertensor -from .config import Config +from cybertensor import __blocktime__ +from cybertensor.config import Config # Workers are created as daemon threads. This is done to allow the interpreter # to exit when there are still idle threads in a ThreadPoolExecutor's thread @@ -52,7 +52,7 @@ def run(self): """Run the given work item""" # Checks if future is canceled or if work item is stale if (not self.future.set_running_or_notify_cancel()) or ( - time.time() - self.start_time > cybertensor.__blocktime__ + time.time() - self.start_time > __blocktime__ ): return diff --git a/cybertensor/utils/__init__.py b/cybertensor/utils/__init__.py index f9212a6..c4bfe96 100644 --- a/cybertensor/utils/__init__.py +++ b/cybertensor/utils/__init__.py @@ -22,8 +22,8 @@ import requests import cybertensor -from .formatting import get_human_readable, millify -from .wallet_utils import * +from cybertensor.utils.formatting import get_human_readable, millify +from cybertensor.utils.wallet_utils import is_valid_cybertensor_address_or_public_key, is_valid_address, coin_from_str GIGA = 1e9 U16_MAX = 65535 diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py index 33a8e48..3fb4d52 100644 --- a/cybertensor/utils/registration.py +++ b/cybertensor/utils/registration.py @@ -17,10 +17,10 @@ from rich import status as rich_status import cybertensor -from ._register_cuda import solve_cuda -from .formatting import get_human_readable, millify -from .. import __console__ as console -from ..wallet import Wallet +from cybertensor import __console__ as console +from cybertensor.utils._register_cuda import solve_cuda +from cybertensor.utils.formatting import get_human_readable, millify +from cybertensor.wallet import Wallet class CUDAException(Exception): diff --git a/cybertensor/utils/weight_utils.py b/cybertensor/utils/weight_utils.py index ce21571..f0be0b5 100644 --- a/cybertensor/utils/weight_utils.py +++ b/cybertensor/utils/weight_utils.py @@ -230,7 +230,7 @@ def process_weights_for_netuid( if not isinstance(weights, torch.FloatTensor): weights = weights.type(torch.float32) - # Network configuration parameters from an cwtensor. + # Network configuration parameters from a cwtensor. # These parameters determine the range of acceptable weights for each neuron. quantile = exclude_quantile / U16_MAX min_allowed_weights = cwtensor.min_allowed_weights(netuid=netuid) diff --git a/cybertensor/wallet.py b/cybertensor/wallet.py index 907071c..365cf2a 100644 --- a/cybertensor/wallet.py +++ b/cybertensor/wallet.py @@ -24,9 +24,9 @@ from termcolor import colored import cybertensor -from .config import Config -from .keypair import Keypair -from .utils import is_valid_cybertensor_address_or_public_key +from cybertensor.config import Config +from cybertensor.keypair import Keypair +from cybertensor.utils import is_valid_cybertensor_address_or_public_key def display_mnemonic_msg(keypair: Keypair, key_type: str): diff --git a/load_test_main.py b/load_test_main.py index b191aaf..74645df 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -1,6 +1,6 @@ import warnings from argparse import ArgumentParser -from random import sample +from random import sample, randint from time import sleep from typing import Union, TypedDict, Optional @@ -113,6 +113,7 @@ def workflow( subnets_set_weight: bool = True, subnets_weights: Optional[dict[int, list[list[int], list[float]]]] = None, ) -> None: + sleep(randint(0, 40)) try: _tensor = cwtensor(network="local") if register_subnetwork: diff --git a/requirements/prod.txt b/requirements/prod.txt index 7e2b97b..022c105 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -26,6 +26,7 @@ pytest retry requests rich +setuptools<=65.6.3 termcolor torch>=1.13.1 tqdm From 1f7094d667bfb2e106521cfaafd814b68ebc0edc Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Wed, 14 Feb 2024 18:53:00 +0800 Subject: [PATCH 16/23] - refactor root register and root set weights --- cybertensor/cwtensor.py | 76 +++++++++++++++++++++++++++------- cybertensor/errors.py | 5 +++ cybertensor/messages/root.py | 80 +++++++++--------------------------- 3 files changed, 85 insertions(+), 76 deletions(-) diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index 7f3236a..96c10fa 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -254,10 +254,11 @@ def __repr__(self) -> str: return self.__str__() # TODO check decorator and improve error handling - @retry(delay=2, tries=3, backoff=2, max_delay=4) + @retry(delay=3, tries=3, backoff=2, max_delay=8) def make_call_with_retry(self, wait_for_finalization: bool, msg: dict, - signer_wallet: LocalWallet, error, + signer_wallet: LocalWallet, + error, gas: Optional[int] = cybertensor.__default_gas__, funds: Optional[str] = None) -> Optional[bool]: if not wait_for_finalization: @@ -275,7 +276,49 @@ def make_call_with_retry(self, wait_for_finalization: bool, except Exception as e: raise error(e.__str__()) - @retry(delay=2, tries=3, backoff=2, max_delay=4) + def _execute_contract(self, wait_for_finalization: bool, + msg: dict, + wallet: Wallet, + error, + logging_prefix: str, + use_hotkey: bool = True, + success_text: str = 'Finalized', + exception_text: str = 'Failed', + gas: Optional[int] = cybertensor.__default_gas__, + funds: Optional[str] = None): + try: + _private_key = wallet.hotkey.private_key if use_hotkey else wallet.coldkey.private_key + signer_wallet = LocalWallet( + PrivateKey(_private_key), self.address_prefix + ) + res = self.make_call_with_retry( + wait_for_finalization=wait_for_finalization, + msg=msg, + signer_wallet=signer_wallet, + error=error, + gas=gas, + funds=funds) + if res is True: + console.print( + f":white_heavy_check_mark: [green]{success_text}[/green]" + ) + cybertensor.logging.success( + prefix=logging_prefix, + sufix=f"{success_text}", + ) + return True + except Exception as e: + console.print( + f":cross_mark: [red]{exception_text}[/red]: error:{e}" + ) + cybertensor.logging.warning( + prefix=logging_prefix, + sufix=f"[red]{exception_text}[/red]: error:{e}", + ) + + return False + + @retry(delay=3, tries=3, backoff=2, max_delay=8) def make_call_with_retry_2(self, wait_for_finalization: bool, msg: dict, signer_wallet: LocalWallet, gas: Optional[int] = cybertensor.__default_gas__, funds: Optional[str] = None) -> [bool, Optional[str]]: @@ -432,7 +475,8 @@ def _do_set_weights( netuid: int, version_key: int = cybertensor.__version_as_int__, wait_for_finalization: bool = True, - ) -> Tuple[bool, Optional[str]]: # (success, error_message) + ) -> bool: + set_weights_msg = { "set_weights": { "netuid": netuid, @@ -441,14 +485,14 @@ def _do_set_weights( "version_key": version_key, } } - signer_wallet = LocalWallet( - PrivateKey(wallet.hotkey.private_key), self.address_prefix - ) - return self.make_call_with_retry_2( + return self._execute_contract( wait_for_finalization=wait_for_finalization, msg=set_weights_msg, - signer_wallet=signer_wallet) + wallet=wallet, + error=NotSetWeightError, + logging_prefix='Set weights' + ) ###################### #### Registration #### @@ -927,16 +971,18 @@ def _do_root_register( self, wallet: "Wallet", wait_for_finalization: bool = True, - ) -> Tuple[bool, Optional[str]]: + ) -> bool: + root_register_msg = {"root_register": {"hotkey": wallet.hotkey.address}} - signer_wallet = LocalWallet( - PrivateKey(wallet.coldkey.private_key), self.address_prefix - ) - return self.make_call_with_retry_2( + return self._execute_contract( wait_for_finalization=wait_for_finalization, msg=root_register_msg, - signer_wallet=signer_wallet) + wallet=wallet, + error=RegistrationError, + use_hotkey=False, + logging_prefix='root register', + exception_text='Neuron was not registered in root') def root_set_weights( self, diff --git a/cybertensor/errors.py b/cybertensor/errors.py index 270b3ba..a40de93 100644 --- a/cybertensor/errors.py +++ b/cybertensor/errors.py @@ -77,6 +77,11 @@ class NotDelegateError(StakeError): pass +class NotSetWeightError(ChainTransactionError): + r"""Error raised when a hotkey you are trying to set weight is not set.""" + pass + + class KeyFileError(Exception): r"""Error thrown when the keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid.""" pass diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index d2b1b8c..52637f2 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -70,25 +70,20 @@ def root_register_message( return False with console.status(":satellite: Registering to root network..."): - success, err_msg = cwtensor._do_root_register( + success = cwtensor._do_root_register( wallet=wallet, wait_for_finalization=wait_for_finalization, ) - - if success != True or success is False: - console.print( - f":cross_mark: [red]Failed[/red]: error:{err_msg}" - ) - time.sleep(0.5) + time.sleep(0.5) # Successful registration, final check for neuron and pubkey - else: + if success is True: is_registered = cwtensor.is_hotkey_registered( netuid=0, hotkey=wallet.hotkey.address ) if is_registered: console.print( - ":white_heavy_check_mark: [green]Registered[/green]" + ":white_heavy_check_mark: [green]Registered in root[/green]" ) return True else: @@ -97,6 +92,8 @@ def root_register_message( ":cross_mark: [red]Unknown error. Neuron not found.[/red]" ) + return False + def set_root_weights_message( cwtensor: "cybertensor.cwtensor", @@ -148,12 +145,8 @@ def set_root_weights_message( ) # Normalize the weights to max value. - formatted_weights = cybertensor.utils.weight_utils.normalize_max_weight( - x=weights, limit=max_weight_limit - ) - console.print( - f"\nNormalized weights: \n\t{weights} -> {formatted_weights}\n" - ) + formatted_weights = normalize_max_weight(x=weights, limit=max_weight_limit) + console.print(f"\nNormalized weights: \n\t{weights} -> {formatted_weights}\n") # Ask before moving on. if prompt: @@ -167,49 +160,14 @@ def set_root_weights_message( with console.status( f":satellite: Setting root weights on [white]{cwtensor.network}[/white] ..." ): - try: - weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit( - netuids, weights - ) - success, error_message = cwtensor._do_set_weights( - wallet=wallet, - netuid=0, - uids=weight_uids, - vals=weight_vals, - version_key=version_key, - wait_for_finalization=wait_for_finalization, - ) - - console.print(success, error_message) - - if not wait_for_finalization: - return True - - if success is True: - console.print( - ":white_heavy_check_mark: [green]Finalized[/green]" - ) - cybertensor.logging.success( - prefix="Set weights", - sufix="Finalized: " + str(success), - ) - return True - else: - console.print( - f":cross_mark: [red]Failed[/red]: error:{error_message}" - ) - cybertensor.logging.warning( - prefix="Set weights", - sufix=f"Failed: {error_message}", - ) - return False - - except Exception as e: - # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru. - console.print( - f":cross_mark: [red]Failed[/red]: error:{e}" - ) - cybertensor.logging.warning( - prefix="Set weights", sufix=f"Failed: {e}" - ) - return False + weight_uids, weight_vals = convert_weights_and_uids_for_emit( + netuids, weights + ) + return cwtensor._do_set_weights( + wallet=wallet, + netuid=0, + uids=weight_uids, + vals=weight_vals, + version_key=version_key, + wait_for_finalization=wait_for_finalization, + ) From 8dc3ab52491ae50ab0c73b231dc91f13276200bb Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 11:36:44 +0800 Subject: [PATCH 17/23] - update imports --- cybertensor/commands/stake.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index fdb4efd..8aa1d8d 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -280,10 +280,10 @@ def add_args(cls, parser: argparse.ArgumentParser): from typing import Union from concurrent.futures import ThreadPoolExecutor -from .utils import DelegatesDetails -from . import defaults -from ..wallet import Wallet -from .. import __console__ as console +from cybertensor.commands.utils import DelegatesDetails +from cybertensor.commands import defaults +from cybertensor.wallet import Wallet +from cybertensor import __console__ as console def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]: From 88f6ba7c601a1fe89650b56ce85ccf3e7e6ffe0a Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 12:30:24 +0800 Subject: [PATCH 18/23] - fix overview path error --- cybertensor/commands/overview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index b14a7a7..0771a50 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -148,7 +148,7 @@ def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5) all_wallet_names = set([wallet.name for wallet in all_hotkeys]) all_coldkey_wallets = [ - Wallet(name=wallet_name) for wallet_name in all_wallet_names + Wallet(name=wallet_name, path=cli.config.wallet.path) for wallet_name in all_wallet_names ] hotkey_coldkey_to_hotkey_wallet = {} From 9946d5fcabca876d93d26ad15f5454ca42d4ee81 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 13:25:22 +0800 Subject: [PATCH 19/23] - fix wallet creation and transfer - update help message for ctcli w balance --- cybertensor/commands/wallets.py | 2 +- cybertensor/keyfile.py | 4 ++-- cybertensor/messages/transfer.py | 2 +- cybertensor/utils/__init__.py | 19 ++++++++++--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index 9d3e7c2..90613f9 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -812,7 +812,7 @@ def run(cli): @staticmethod def add_args(parser: argparse.ArgumentParser): balance_parser = parser.add_parser( - "balance", help="""Checks the balance of the wallet.""" + "balance", help="""Checks balances of wallets in the wallet path.""" ) Wallet.add_args(balance_parser) cybertensor.cwtensor.add_args(balance_parser) diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index 85c129c..42d54d8 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -215,7 +215,7 @@ def encrypt_keyfile_data(keyfile_data: bytes, password: str = None) -> bytes: Returns: encrypted_data (bytes): The encrypted data. """ - password = cybertensor.ask_password_to_encrypt() if password is None else password + password = ask_password_to_encrypt() if password is None else password password = bytes(password, "utf-8") kdf = pwhash.argon2i.kdf key = kdf( @@ -388,7 +388,7 @@ def set_keypair( self.make_dirs() keyfile_data = serialized_keypair_to_keyfile_data(keypair) if encrypt: - keyfile_data = cybertensor.encrypt_keyfile_data(keyfile_data, password) + keyfile_data = encrypt_keyfile_data(keyfile_data, password) self._write_keyfile_data_to_file(keyfile_data, overwrite=overwrite) def get_keypair(self, password: str = None) -> "Keypair": diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py index 13da2f2..5b1a04f 100644 --- a/cybertensor/messages/transfer.py +++ b/cybertensor/messages/transfer.py @@ -129,7 +129,7 @@ def transfer_message( console.print(f"[green]Tx Hash: {tx_hash}[/green]") explorer_url = cybertensor.utils.get_explorer_url_for_network( - cwtensor.network, tx_hash, cwtensor.network_explorer + network_config=cwtensor.network_config, tx_hash=tx_hash ) if explorer_url is not None: console.print( diff --git a/cybertensor/utils/__init__.py b/cybertensor/utils/__init__.py index c4bfe96..87381b6 100644 --- a/cybertensor/utils/__init__.py +++ b/cybertensor/utils/__init__.py @@ -22,8 +22,13 @@ import requests import cybertensor +from cybertensor import NetworkConfigCwTensor from cybertensor.utils.formatting import get_human_readable, millify -from cybertensor.utils.wallet_utils import is_valid_cybertensor_address_or_public_key, is_valid_address, coin_from_str +from cybertensor.utils.wallet_utils import ( + is_valid_cybertensor_address_or_public_key, + is_valid_address, + coin_from_str, +) GIGA = 1e9 U16_MAX = 65535 @@ -89,15 +94,14 @@ def get_explorer_root_url_by_network_from_map( def get_explorer_url_for_network( - network: str, tx_hash: str, network_map: Dict[str, str] + network_config: "NetworkConfigCwTensor", tx_hash: str ) -> Optional[str]: r""" - Returns the explorer url for the given block hash and network. + Returns the explorer url for the given tx hash and network config. Args: - network(str): The network to get the explorer url for. + network_config("NetworkConfigCwTensor"): The network config to get the explorer url for. tx_hash(str): The transaction hash to get the explorer url for. - network_map(Dict[str, str]): The network map to get the explorer url from. Returns: The explorer url for the given block hash and network. @@ -105,10 +109,7 @@ def get_explorer_url_for_network( """ explorer_url: Optional[str] = None - # Will be None if the network is not known. i.e. not in network_map - explorer_root_url: Optional[str] = get_explorer_root_url_by_network_from_map( - network, network_map - ) + explorer_root_url = network_config.network_explorer if explorer_root_url is not None: # We are on a known network. From f43dcd67fc88be9971e60e3dea09dd1cfed24a9e Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 13:38:57 +0800 Subject: [PATCH 20/23] - bump the package version --- cybertensor/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index 51ae704..c21efa6 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -30,14 +30,13 @@ nest_asyncio.apply() # Cybertensor code and protocol version. -__version__ = "0.1.4" +__version__ = "0.1.5" version_split = __version__.split(".") __version_as_int__ = ( (100 * int(version_split[0])) + (10 * int(version_split[1])) + (1 * int(version_split[2])) ) -__new_signature_version__ = 360 # Rich console. __console__ = Console() From 877824f9922dd420c644ee0691f2c5129b631235 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 14:20:33 +0800 Subject: [PATCH 21/23] - update copyrights --- LICENSE | 2 +- bin/ctcli | 2 +- cybertensor/__init__.py | 2 +- cybertensor/axon.py | 2 +- cybertensor/chain_data.py | 2 +- cybertensor/cli.py | 2 +- cybertensor/commands/__init__.py | 2 +- cybertensor/commands/delegates.py | 2 +- cybertensor/commands/inspect.py | 2 +- cybertensor/commands/list.py | 2 +- cybertensor/commands/metagraph.py | 2 +- cybertensor/commands/network.py | 2 +- cybertensor/commands/overview.py | 2 +- cybertensor/commands/register.py | 2 +- cybertensor/commands/stake.py | 2 +- cybertensor/commands/transfer.py | 2 +- cybertensor/commands/unstake.py | 2 +- cybertensor/commands/utils.py | 2 +- cybertensor/commands/wallets.py | 2 +- cybertensor/config.py | 2 +- cybertensor/ctlogging.py | 2 +- cybertensor/cwtensor.py | 2 +- cybertensor/dendrite.py | 2 +- cybertensor/errors.py | 2 +- cybertensor/keyfile.py | 2 +- cybertensor/keypair.py | 2 +- cybertensor/messages/__init__.py | 2 +- cybertensor/messages/delegation.py | 2 +- cybertensor/messages/network.py | 2 +- cybertensor/messages/prometheus.py | 2 +- cybertensor/messages/registration.py | 2 +- cybertensor/messages/root.py | 2 +- cybertensor/messages/serving.py | 2 +- cybertensor/messages/set_weights.py | 2 +- cybertensor/messages/staking.py | 2 +- cybertensor/messages/transfer.py | 2 +- cybertensor/messages/unstaking.py | 2 +- cybertensor/metagraph.py | 2 +- cybertensor/synapse.py | 2 +- cybertensor/types.py | 2 +- cybertensor/utils/__init__.py | 2 +- cybertensor/utils/balance.py | 2 +- cybertensor/utils/networking.py | 2 +- cybertensor/utils/stats.py | 2 +- cybertensor/utils/wallet_utils.py | 2 +- cybertensor/utils/weight_utils.py | 2 +- cybertensor/wallet.py | 2 +- load_test_main.py | 17 +++++++++++++++++ setup.py | 2 +- 49 files changed, 65 insertions(+), 48 deletions(-) diff --git a/LICENSE b/LICENSE index a2837ed..d3f52c2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ The MIT License (MIT) -Copyright © 2023 cyber~Congress +Copyright © 2024 cyber~Congress Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/bin/ctcli b/bin/ctcli index a863004..c2ec6bd 100755 --- a/bin/ctcli +++ b/bin/ctcli @@ -11,7 +11,7 @@ if __name__ == '__main__': # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py index c21efa6..0c45e7d 100644 --- a/cybertensor/__init__.py +++ b/cybertensor/__init__.py @@ -2,7 +2,7 @@ # Copyright © 2021 Yuma Rao # Copyright © 2022-2023 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/axon.py b/cybertensor/axon.py index cd51d98..b5cbab8 100644 --- a/cybertensor/axon.py +++ b/cybertensor/axon.py @@ -2,7 +2,7 @@ # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/chain_data.py b/cybertensor/chain_data.py index c2f5af1..b1a7451 100644 --- a/cybertensor/chain_data.py +++ b/cybertensor/chain_data.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/cli.py b/cybertensor/cli.py index 62876c4..7157dd4 100644 --- a/cybertensor/cli.py +++ b/cybertensor/cli.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/__init__.py b/cybertensor/commands/__init__.py index 0a3d192..a7c2a8f 100644 --- a/cybertensor/commands/__init__.py +++ b/cybertensor/commands/__init__.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py index e71ba9f..4688f8d 100644 --- a/cybertensor/commands/delegates.py +++ b/cybertensor/commands/delegates.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 OpenTensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py index 03ed967..815a769 100644 --- a/cybertensor/commands/inspect.py +++ b/cybertensor/commands/inspect.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py index 277e98e..de1f53f 100644 --- a/cybertensor/commands/list.py +++ b/cybertensor/commands/list.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py index d18ab14..c2be7e8 100644 --- a/cybertensor/commands/metagraph.py +++ b/cybertensor/commands/metagraph.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py index db37fb7..ba25df2 100644 --- a/cybertensor/commands/network.py +++ b/cybertensor/commands/network.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py index 0771a50..29e82a9 100644 --- a/cybertensor/commands/overview.py +++ b/cybertensor/commands/overview.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py index 08bdec0..3009af5 100644 --- a/cybertensor/commands/register.py +++ b/cybertensor/commands/register.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py index 8aa1d8d..399fc66 100644 --- a/cybertensor/commands/stake.py +++ b/cybertensor/commands/stake.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py index a96716b..75b71b0 100644 --- a/cybertensor/commands/transfer.py +++ b/cybertensor/commands/transfer.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py index f9b855b..ae5cfe3 100644 --- a/cybertensor/commands/unstake.py +++ b/cybertensor/commands/unstake.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py index adcf228..260ec62 100644 --- a/cybertensor/commands/utils.py +++ b/cybertensor/commands/utils.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py index 90613f9..039078c 100644 --- a/cybertensor/commands/wallets.py +++ b/cybertensor/commands/wallets.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/config.py b/cybertensor/config.py index 8314f87..b0fc335 100644 --- a/cybertensor/config.py +++ b/cybertensor/config.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/ctlogging.py b/cybertensor/ctlogging.py index 5064eef..cfa0a0f 100644 --- a/cybertensor/ctlogging.py +++ b/cybertensor/ctlogging.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py index 96c10fa..971faf4 100644 --- a/cybertensor/cwtensor.py +++ b/cybertensor/cwtensor.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/dendrite.py b/cybertensor/dendrite.py index d49e2fe..ab823d5 100644 --- a/cybertensor/dendrite.py +++ b/cybertensor/dendrite.py @@ -2,7 +2,7 @@ # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/errors.py b/cybertensor/errors.py index a40de93..69f0bf7 100644 --- a/cybertensor/errors.py +++ b/cybertensor/errors.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py index 42d54d8..01b8c94 100644 --- a/cybertensor/keyfile.py +++ b/cybertensor/keyfile.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/keypair.py b/cybertensor/keypair.py index afbbb25..416aa05 100644 --- a/cybertensor/keypair.py +++ b/cybertensor/keypair.py @@ -1,5 +1,5 @@ # The MIT License (MIT) -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/__init__.py b/cybertensor/messages/__init__.py index 2e27c35..1a7544b 100644 --- a/cybertensor/messages/__init__.py +++ b/cybertensor/messages/__init__.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py index 924973e..2aaac0d 100644 --- a/cybertensor/messages/delegation.py +++ b/cybertensor/messages/delegation.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/network.py b/cybertensor/messages/network.py index 3cd901e..e426208 100644 --- a/cybertensor/messages/network.py +++ b/cybertensor/messages/network.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/prometheus.py b/cybertensor/messages/prometheus.py index d15934f..c83a93c 100644 --- a/cybertensor/messages/prometheus.py +++ b/cybertensor/messages/prometheus.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/registration.py b/cybertensor/messages/registration.py index 4627fa3..e8d31d1 100644 --- a/cybertensor/messages/registration.py +++ b/cybertensor/messages/registration.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py index 52637f2..9a96eb0 100644 --- a/cybertensor/messages/root.py +++ b/cybertensor/messages/root.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py index eece0a8..3422578 100644 --- a/cybertensor/messages/serving.py +++ b/cybertensor/messages/serving.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index 38fc593..486172c 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/staking.py b/cybertensor/messages/staking.py index 9cd05de..962368c 100644 --- a/cybertensor/messages/staking.py +++ b/cybertensor/messages/staking.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py index 5b1a04f..4f00bb7 100644 --- a/cybertensor/messages/transfer.py +++ b/cybertensor/messages/transfer.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/messages/unstaking.py b/cybertensor/messages/unstaking.py index 28631bb..86939b7 100644 --- a/cybertensor/messages/unstaking.py +++ b/cybertensor/messages/unstaking.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/metagraph.py b/cybertensor/metagraph.py index df8d351..7368264 100644 --- a/cybertensor/metagraph.py +++ b/cybertensor/metagraph.py @@ -2,7 +2,7 @@ # Copyright © 2021 Yuma Rao # Copyright © 2023 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/synapse.py b/cybertensor/synapse.py index 137e086..ec8d244 100644 --- a/cybertensor/synapse.py +++ b/cybertensor/synapse.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/types.py b/cybertensor/types.py index 6c29423..1e4341a 100644 --- a/cybertensor/types.py +++ b/cybertensor/types.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/__init__.py b/cybertensor/utils/__init__.py index 87381b6..284fc6c 100644 --- a/cybertensor/utils/__init__.py +++ b/cybertensor/utils/__init__.py @@ -1,7 +1,7 @@ # The MIT License (MIT) # Copyright © 2022 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/balance.py b/cybertensor/utils/balance.py index 0995c6b..0625209 100644 --- a/cybertensor/utils/balance.py +++ b/cybertensor/utils/balance.py @@ -2,7 +2,7 @@ # Copyright © 2021-2022 Yuma Rao # Copyright © 2022 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/networking.py b/cybertensor/utils/networking.py index 96f0a05..b22ac02 100644 --- a/cybertensor/utils/networking.py +++ b/cybertensor/utils/networking.py @@ -2,7 +2,7 @@ # Copyright © 2021-2022 Yuma Rao # Copyright © 2022-2023 Opentensor Foundation # Copyright © 2023 Opentensor Technologies -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/stats.py b/cybertensor/utils/stats.py index 8a46bc0..9a89758 100644 --- a/cybertensor/utils/stats.py +++ b/cybertensor/utils/stats.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/wallet_utils.py b/cybertensor/utils/wallet_utils.py index 10bfefb..25da987 100644 --- a/cybertensor/utils/wallet_utils.py +++ b/cybertensor/utils/wallet_utils.py @@ -2,7 +2,7 @@ # Copyright © 2021 Yuma Rao # Copyright © 2022 Opentensor Foundation # Copyright © 2023 Opentensor Technologies Inc -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/utils/weight_utils.py b/cybertensor/utils/weight_utils.py index f0be0b5..1dd4bb7 100644 --- a/cybertensor/utils/weight_utils.py +++ b/cybertensor/utils/weight_utils.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/cybertensor/wallet.py b/cybertensor/wallet.py index 365cf2a..97a00da 100644 --- a/cybertensor/wallet.py +++ b/cybertensor/wallet.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation diff --git a/load_test_main.py b/load_test_main.py index 74645df..3e7329f 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -1,3 +1,20 @@ +# Copyright © 2024 cyber~Congress + +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the “Software”), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of +# the Software. + +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + + import warnings from argparse import ArgumentParser from random import sample, randint diff --git a/setup.py b/setup.py index 4e4227f..f799ca3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # Copyright © 2021 Yuma Rao -# Copyright © 2023 cyber~Congress +# Copyright © 2024 cyber~Congress # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the “Software”), to deal in the Software without restriction, including without limitation From fac0f6e414787d1a852e98d5ba680443ff827299 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 15:51:41 +0800 Subject: [PATCH 22/23] - add arguments in load test --- load_test_main.py | 104 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/load_test_main.py b/load_test_main.py index 3e7329f..b6114d0 100644 --- a/load_test_main.py +++ b/load_test_main.py @@ -15,6 +15,11 @@ # DEALINGS IN THE SOFTWARE. +# Example usage: +# >>> python load_test_main.py --wallets=15 --skip-wallets=10 --send-to-contract=y --send-to-wallets=y \ +# --register-subnet=n --root-register=y --subnet-register=y --subnet-nominate=n --self-stake=y --self-unstake=n \ +# --set-root-weight=y --set-subnets-weight=y``` + import warnings from argparse import ArgumentParser from random import sample, randint @@ -44,18 +49,64 @@ class Account(TypedDict): BASE_WALLET_SEED = "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" parser = ArgumentParser() -parser.add_argument("--addresses", default=10) -parser.add_argument("--send-to-contract", default="false") -parser.add_argument("--activate-contract", default="false") -parser.add_argument("--send-to-wallets", default="true") -parser.add_argument("--threads", default=5) +parser.add_argument("--wallets", default=10, type=int, help="Number of wallets") +parser.add_argument("--skip-wallets", default=0, type=int, help="Skip wallets") +parser.add_argument( + "--send-to-contract", default="false", type=str, help="Send tokens to the contract" +) +parser.add_argument( + "--activate-contract", + default="false", + type=str, + help="Activate dmn thought for the contract", +) +parser.add_argument( + "--send-to-wallets", default="true", type=str, help="Send tokens to wallets" +) +parser.add_argument("--threads", default=5, type=int, help="Number of threads") +parser.add_argument( + "--register-subnet", default="false", type=str, help="Register new subnetworks" +) +parser.add_argument( + "--root-register", default="true", type=str, help="Register wallets in root" +) +parser.add_argument( + "--subnet-register", + default="true", + type=str, + help="Register wallets in subnetworks", +) +parser.add_argument( + "--subnet-nominate", + default="false", + type=str, + help="Nominate wallets in subnetworks", +) +parser.add_argument("--self-stake", default="true", type=str, help="Self stake") +parser.add_argument("--self-unstake", default="false", type=str, help="Self unstake") +parser.add_argument( + "--set-root-weight", default="true", type=str, help="Set roots' weights" +) +parser.add_argument( + "--set-subnets-weight", default="false", type=str, help="Set subnets' weights" +) args = parser.parse_args() -ADDRESSES_NUMBER = int(args.addresses) + +NUMBER_OF_WALLETS = int(args.wallets) +SKIP_WALLETS = int(args.skip_wallets) SEND_TOKEN_TO_CONTRACT = args.send_to_contract.lower() in ["true", "1", "t", "y", "yes"] ACTIVATE_CONTRACT = args.activate_contract.lower() in ["true", "1", "t", "y", "yes"] SEND_TOKEN_TO_WALLETS = args.send_to_wallets.lower() in ["true", "1", "t", "y", "yes"] NUMBER_OF_THREADS = int(args.threads) +REGISTER_SUBNET = args.register_subnet.lower() in ["true", "1", "t", "y", "yes"] +REGISTER_IN_ROOT = args.root_register.lower() in ["true", "1", "t", "y", "yes"] +REGISTER_IN_SUBNET = args.subnet_register.lower() in ["true", "1", "t", "y", "yes"] +NOMINATE_IN_SUBNET = args.subnet_nominate.lower() in ["true", "1", "t", "y", "yes"] +SELF_STAKE = args.self_stake.lower() in ["true", "1", "t", "y", "yes"] +SELF_UNSTAKE = args.self_unstake.lower() in ["true", "1", "t", "y", "yes"] +SET_ROOT_WEIGHT = args.set_root_weight.lower() in ["true", "1", "t", "y", "yes"] +SET_SUBNETS_WEIGHT = args.set_subnets_weight.lower() in ["true", "1", "t", "y", "yes"] def send_coins( @@ -88,9 +139,11 @@ def activate_contract() -> None: print(_tx) -def get_accounts(addresses_number: int = ADDRESSES_NUMBER) -> list[Account]: +def get_accounts( + number_of_wallets: int = NUMBER_OF_WALLETS, skip_wallets: int = SKIP_WALLETS +) -> list[Account]: _accounts: list[Account] = [] - for _i in range(1, addresses_number + 1): + for _i in range(skip_wallets, number_of_wallets): _wallet_name = f"wallet{_i}" _wallet = Wallet(name=_wallet_name, hotkey=_wallet_name, path="temp") _wallet.create_if_non_existent( @@ -117,17 +170,17 @@ def get_accounts(addresses_number: int = ADDRESSES_NUMBER) -> list[Account]: def workflow( account: Account, netuids: Optional[list[int]] = None, - register_subnetwork: bool = True, - root_register: bool = True, - subnet_register: bool = True, - subnet_nominate: bool = True, - self_stake: bool = True, + register_subnetwork: bool = REGISTER_SUBNET, + root_register: bool = REGISTER_IN_ROOT, + subnet_register: bool = REGISTER_IN_SUBNET, + subnet_nominate: bool = NOMINATE_IN_SUBNET, + self_stake: bool = SELF_STAKE, self_stake_amount: float = 1, - self_unstake: bool = True, + self_unstake: bool = SELF_UNSTAKE, self_unstake_amount: float = 0.1, - root_set_weight: bool = True, + root_set_weight: bool = SET_ROOT_WEIGHT, root_weights: Optional[list[float]] = None, - subnets_set_weight: bool = True, + subnets_set_weight: bool = SET_SUBNETS_WEIGHT, subnets_weights: Optional[dict[int, list[list[int], list[float]]]] = None, ) -> None: sleep(randint(0, 40)) @@ -161,10 +214,7 @@ def workflow( if root_set_weight: if root_weights is None: root_weights = sample(range(1, 1 + len(_subnetuids)), len(_subnetuids)) - print( - f"netuids: {_subnetuids}\t" - f"root_weights: {root_weights}" - ) + print(f"netuids: {_subnetuids}\troot_weights: {root_weights}") _tensor.root_set_weights( wallet=account["wallet"], netuids=_subnetuids, @@ -237,10 +287,20 @@ def display_state() -> None: print( f"base address: {base_wallet_address}\n" f"base address balance: {tensor.get_balance(address=base_wallet_address)}\n" - f"number of wallets: {ADDRESSES_NUMBER}\n" f"send token to the contract: {SEND_TOKEN_TO_CONTRACT}\n" f"activate contract: {ACTIVATE_CONTRACT}\n" - f"send token to wallets: {SEND_TOKEN_TO_WALLETS}\n" + f"number of wallets: {NUMBER_OF_WALLETS}\n" + f"number of skipped wallets: {SKIP_WALLETS}\n" + f"send token to the wallets: {SEND_TOKEN_TO_WALLETS}\n" + f"number of threads: {NUMBER_OF_THREADS}\n" + f"register new subnets: {REGISTER_SUBNET}\n" + f"register in root: {REGISTER_IN_ROOT}\n" + f"register in subnets: {REGISTER_IN_SUBNET}\n" + f"nominate in subnets: {NOMINATE_IN_SUBNET}\n" + f"self stake: {SELF_STAKE}\n" + f"self unstake: {SELF_UNSTAKE}\n" + f"set root weights: {SET_ROOT_WEIGHT}\n" + f"set subnets weights: {SET_SUBNETS_WEIGHT}\n" ) send_token_to_contract() From 80c0460382cb2ec8df696fb9f860c4cdc6c47c36 Mon Sep 17 00:00:00 2001 From: Snedashkovsky Date: Thu, 15 Feb 2024 18:46:42 +0800 Subject: [PATCH 23/23] - refactor of setting subnet weights --- cybertensor/messages/set_weights.py | 33 +---------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py index 486172c..3970769 100644 --- a/cybertensor/messages/set_weights.py +++ b/cybertensor/messages/set_weights.py @@ -86,8 +86,7 @@ def set_weights_message( with console.status( f":satellite: Setting weights on [white]{cwtensor.network}[/white] ..." ): - try: - success, error_message = cwtensor._do_set_weights( + return cwtensor._do_set_weights( wallet=wallet, netuid=netuid, uids=weight_uids, @@ -95,33 +94,3 @@ def set_weights_message( version_key=version_key, wait_for_finalization=wait_for_finalization, ) - - if not wait_for_finalization: - return True - - if success is True: - console.print( - ":white_heavy_check_mark: [green]Finalized[/green]" - ) - cybertensor.logging.success( - prefix="Set weights", - sufix=f"Finalized: {success}", - ) - return True - else: - console.print( - f":cross_mark: [red]Failed[/red]: error:{error_message}", - ) - cybertensor.logging.warning( - prefix="Set weights", - sufix=f"Failed: {error_message}", - ) - return False - - except Exception as e: - # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru. - console.print(f":cross_mark: [red]Failed[/red]: error:{e}") - cybertensor.logging.warning( - prefix="Set weights", sufix=f"Failed: {e}" - ) - return False