From 674d7517c8730fb7dcc364202e9aea3ded912544 Mon Sep 17 00:00:00 2001 From: ifrit98 Date: Thu, 5 Oct 2023 17:29:47 +0000 Subject: [PATCH 1/2] fix cli test --- tests/integration_tests/test_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration_tests/test_cli.py b/tests/integration_tests/test_cli.py index 9b6241b076..ffc973d78c 100644 --- a/tests/integration_tests/test_cli.py +++ b/tests/integration_tests/test_cli.py @@ -150,7 +150,6 @@ def test_overview(self, _): coldkey=wallet.coldkey.ss58_address, hotkey=wallet.hotkey.ss58_address, ) - self.assertTrue(result, err) def mock_get_wallet(*args, **kwargs): hk = kwargs.get("hotkey") From c44e88e1803b72ccac920114261e4f7363ce3413 Mon Sep 17 00:00:00 2001 From: philanthrope Date: Thu, 5 Oct 2023 13:46:38 -0400 Subject: [PATCH 2/2] fix double-counted hotkeys per subnet and non-iterable stake obj (#1539) * fix double-counted hotkeys per subnet and non-iterable stake obj * run black --- bittensor/commands/overview.py | 76 +++++++++++++++++----------------- bittensor/utils/formatting.py | 1 + 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/bittensor/commands/overview.py b/bittensor/commands/overview.py index 877b4226fb..d262d92d6b 100644 --- a/bittensor/commands/overview.py +++ b/bittensor/commands/overview.py @@ -160,11 +160,15 @@ def run(cli: "bittensor.cli"): total_coldkey_stake_from_metagraph = defaultdict( lambda: bittensor.Balance(0.0) ) + checked_hotkeys = set() for neuron_list in neurons.values(): for neuron in neuron_list: + if neuron.hotkey in checked_hotkeys: + continue total_coldkey_stake_from_metagraph[ neuron.coldkey ] += neuron.stake_dict[neuron.coldkey] + checked_hotkeys.add(neuron.hotkey) alerts_table = Table(show_header=True, header_style="bold magenta") alerts_table.add_column("🥩 alert!") @@ -209,40 +213,38 @@ def run(cli: "bittensor.cli"): ) executor.shutdown(wait=True) # wait for all complete - for result in results: - coldkey_wallet, de_registered_stake, err_msg = result - if err_msg is not None: - console.print(err_msg) + for result in results: + coldkey_wallet, de_registered_stake, err_msg = result + if err_msg is not None: + console.print(err_msg) + + if len(de_registered_stake) == 0: + continue # We have no de-registered stake with this coldkey. + + de_registered_neurons = [] + for hotkey_addr, our_stake in de_registered_stake: + # Make a neuron info lite for this hotkey and coldkey. + de_registered_neuron = bittensor.NeuronInfoLite._null_neuron() + de_registered_neuron.hotkey = hotkey_addr + de_registered_neuron.coldkey = ( + coldkey_wallet.coldkeypub.ss58_address + ) + de_registered_neuron.total_stake = bittensor.Balance(our_stake) + + de_registered_neurons.append(de_registered_neuron) + + # Add this hotkey to the wallets dict + wallet_ = bittensor.Wallet( + name=wallet, + ) + wallet_.hotkey = hotkey_addr + wallet.hotkey_str = hotkey_addr[:5] # Max length of 5 characters + hotkey_coldkey_to_hotkey_wallet[hotkey_addr][ + coldkey_wallet.coldkeypub.ss58_address + ] = wallet_ - if len(de_registered_stake) == 0: - continue # We have no de-registered stake with this coldkey. - - de_registered_neurons = [] - for hotkey_addr, our_stake in de_registered_stake: - # Make a neuron info lite for this hotkey and coldkey. - de_registered_neuron = bittensor.NeuronInfoLite._null_neuron() - de_registered_neuron.hotkey = hotkey_addr - de_registered_neuron.coldkey = ( - coldkey_wallet.coldkeypub.ss58_address - ) - de_registered_neuron.total_stake = bittensor.Balance(our_stake) - - de_registered_neurons.append(de_registered_neuron) - - # Add this hotkey to the wallets dict - wallet_ = bittensor.Wallet( - name=wallet, - ) - wallet_.hotkey = hotkey_addr - wallet.hotkey_str = hotkey_addr[ - :5 - ] # Max length of 5 characters - hotkey_coldkey_to_hotkey_wallet[hotkey_addr][ - coldkey_wallet.coldkeypub.ss58_address - ] = wallet_ - - # Add neurons to overview. - neurons["-1"].extend(de_registered_neurons) + # Add neurons to overview. + neurons["-1"].extend(de_registered_neurons) # Setup outer table. grid = Table.grid(pad_edge=False) @@ -551,13 +553,11 @@ def _get_de_registered_stake_for_coldkey_wallet( ## Filter out hotkeys that are in our wallets ## Filter out hotkeys that are delegates. def _filter_stake_info(stake_info: "bittensor.StakeInfo") -> bool: - hotkey_addr, our_stake = stake_info - - if our_stake == 0: + if stake_info.stake == 0: return False # Skip hotkeys that we have no stake with. - if hotkey_addr in all_hotkey_addresses: + if stake_info.hotkey_ss58 in all_hotkey_addresses: return False # Skip hotkeys that are in our wallets. - if subtensor.is_hotkey_delegate(hotkey_ss58=hotkey_addr): + if subtensor.is_hotkey_delegate(hotkey_ss58=stake_info.hotkey_ss58): return False # Skip hotkeys that are delegates, they show up in btcli my_delegates table. return True diff --git a/bittensor/utils/formatting.py b/bittensor/utils/formatting.py index 32ec42cbba..1e93ce8340 100644 --- a/bittensor/utils/formatting.py +++ b/bittensor/utils/formatting.py @@ -1,5 +1,6 @@ import math + def get_human_readable(num, suffix="H"): for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: if abs(num) < 1000.0: