Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get correct information for Bittensor validator #2564

Open
antonr-p2p opened this issue Dec 30, 2024 · 1 comment · May be fixed by #2567
Open

Cannot get correct information for Bittensor validator #2564

antonr-p2p opened this issue Dec 30, 2024 · 1 comment · May be fixed by #2567
Labels
bug Something isn't working

Comments

@antonr-p2p
Copy link

antonr-p2p commented Dec 30, 2024

Describe the bug

I try to get info about validator. Most of the fields get correct info, but not all of them.
I use get_delegate_by_hotkey method for which return_per_1000 and total_daily_return options return either 0 values or incorrect ones.

I tried to use get_delegates method as well, but it look like there is an issue with code in your library around decoded = bt_decode.DelegateInfo.decode_vec(vec_u8) in core/chain_data/delegate_info.py

So both methods either don't work or return incorrect info. Please fix or provide any other way.
Thanks in advance!

To Reproduce

WAY 1:

import bittensor as bt
sub=bt.subtensor()
v=sub.get_delegate_by_hotkey(hotkey_ss58='VAL_HOTKEY')
v.total_daily_return
## τ0.000000000
v.return_per_1000
## τ0.000000000

WAY 2:

from bittensor.core.chain_data import DelegateInfo 
import bittensor as bt

sub=bt.subtensor()
delegates: List[DelegateInfo] = sub.get_delegates()
>>>Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anton/bt/bt_prod/lib/python3.10/site-packages/bittensor/utils/networking.py", line 198, in wrapper
    return func(self, *args, **kwargs)
  File "/home/anton/bt/bt_prod/lib/python3.10/site-packages/bittensor/core/subtensor.py", line 1670, in get_delegates
    return DelegateInfo.list_from_vec_u8(result)
  File "/home/anton/bt/bt_prod/lib/python3.10/site-packages/bittensor/core/chain_data/delegate_info.py", line 65, in list_from_vec_u8
    decoded = bt_decode.DelegateInfo.decode_vec(vec_u8)
TypeError: argument 'encoded': 'list' object cannot be converted to 'PyBytes'

Expected behavior

I get correct values for validator daily return and return per 1000 TAO.

Screenshots

No response

Environment

Bittensor python package 8.5.1

Additional context

No response

@antonr-p2p antonr-p2p added the bug Something isn't working label Dec 30, 2024
@antonr-p2p
Copy link
Author

I found one more issue. registrations value is also incorrect.
Please check that both get_delegate_by_hotkey.registrations and get_netuids_for_hotkey provide incorrect info about SNs 54 and 55. Checking with is_hotkey_registered_on_subnet function.

>>> import bittensor as bt
>>> sub=bt.subtensor()
>>> v=sub.get_delegate_by_hotkey(hotkey_ss58='5HRB5xi9W1yEdJGEWPsgtH71mPjAvN2Z9HxNvRMMcK5kXuW2')
>>> v.registrations
[15, 16, 37, 49, 54, 55, 56, 57, 60, 61, 62]
>>> sub.get_netuids_for_hotkey(hotkey_ss58='5HRB5xi9W1yEdJGEWPsgtH71mPjAvN2Z9HxNvRMMcK5kXuW2')
[15, 16, 37, 49, 54, 55, 56, 57, 60, 61, 62]
>>> sub.is_hotkey_registered_on_subnet(hotkey_ss58='5HRB5xi9W1yEdJGEWPsgtH71mPjAvN2Z9HxNvRMMcK5kXuW2',netuid=54)
False
>>> sub.is_hotkey_registered_on_subnet(hotkey_ss58='5HRB5xi9W1yEdJGEWPsgtH71mPjAvN2Z9HxNvRMMcK5kXuW2',netuid=55)
False
>>> sub.is_hotkey_registered_on_subnet(hotkey_ss58='5HRB5xi9W1yEdJGEWPsgtH71mPjAvN2Z9HxNvRMMcK5kXuW2',netuid=56)
True

So I'm confused why hotkey is shown as registered when it doesn't have hotkey registered.

Riccardo-RG added a commit to Riccardo-RG/bittensor that referenced this issue Jan 3, 2025
Fixes opentensor#2564

Fix the issue with `bt_decode.DelegateInfo.decode_vec` in `bittensor/core/chain_data/delegate_info.py` to handle the decoding of `vec_u8` correctly.

* Add a new method `from_vec_u8` to decode `vec_u8` and return a `DelegateInfo` object.
* Update the `list_from_vec_u8` method to correctly decode `vec_u8` and return a list of `DelegateInfo` objects.
* Ensure that `total_daily_return` and `return_per_1000` are correctly decoded and returned.

Update `bittensor/core/chain_data/delegate_info_lite.py` to handle type conversions and ensure correct data types.

* Add a new method `from_raw_data` to create a `DelegateInfoLite` instance from raw data with proper type conversions.
* Ensure that `registrations` and `validator_permits` are lists of integers.
* Ensure that `take` is rounded to 6 decimal places and `nominators`, `return_per_1000`, and `total_daily_return` are integers.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/opentensor/bittensor/issues/2564?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant