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

Fix delegate info methods to return correct values #2567

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Riccardo-RG
Copy link

@Riccardo-RG Riccardo-RG commented Jan 3, 2025

Fixes #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.

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).
@thewhaleking
Copy link
Contributor

You've got some failing tests. Please fix those and I'll have a review.

@Riccardo-RG
Copy link
Author

Sorry i hope to get more familiar with the project in the next day and to offer a valid contribution

You've got some failing tests. Please fix those and I'll have a review.

@thewhaleking
Copy link
Contributor

thewhaleking commented Jan 13, 2025

Hey @Riccardo-RG,
I'm looking at this, and I don't really see any changes, besides the from_raw_data, but because it's a dataclass, is this necessary? The changes to the *from_vec_u8 methods don't appear to actually change anything. I could be missing something here though.

The only change I see is that registrations are changed from the decoded data to a list of ints from the raw data. However, if we look at the decoder:

#[pyclass(get_all)]
#[derive(Decode, Encode, Clone, Debug)]
struct DelegateInfo {
    delegate_ss58: AccountId,
    take: Compact<u16>,
    nominators: Vec<(AccountId, Compact<u64>)>, // map of nominator_ss58 to stake amount
    owner_ss58: AccountId,
    registrations: Vec<Compact<u16>>, // Vec of netuid this delegate is registered on
    validator_permits: Vec<Compact<u16>>, // Vec of netuid this delegate has validator permit on
    return_per_1000: Compact<u64>, // Delegators current daily return per 1000 TAO staked minus take fee
    total_daily_return: Compact<u64>, // Delegators current daily return
}

We can see that the registrations are always going to be a Vec<Compact<u16>> (i.e. a list of ints).

Second thing I'll say is that we use the list for type annotations rather than typing.List, as this was only necessary pre-3.9 (which we don't support).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot get correct information for Bittensor validator
2 participants