Skip to content

Make alpha a type-safe#1856

Merged
sam0x17 merged 13 commits intodevnet-readyfrom
sasha/chore/currency-types
Jul 17, 2025
Merged

Make alpha a type-safe#1856
sam0x17 merged 13 commits intodevnet-readyfrom
sasha/chore/currency-types

Conversation

@ales-otf
Copy link
Contributor

@ales-otf ales-otf commented Jul 16, 2025

Description

Introduces a type for alpha currency.

Haven't touched tao yet, because it requires too much changes and takes too long to refactor and hard to maintain the branch, so only a half of the overall work on making tao/alpha type safe in this PR.

As we learned with the netuid refactoring, this new type has manual (non-derived) implementation for TypeInfo in a way when it produces the same type info as for u64 to make it backward compatible.

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe): refactoring

Breaking Change

Basically, this is a wrapper. It's done the same way, we wrapped netuid (u16) and the new type's binary representation and metadata should be identical to u64. So it supposed to be backward-compatible and should not affect the clients.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

@ales-otf ales-otf added skip-cargo-audit This PR fails cargo audit but needs to be merged anyway run-bittensor-e2e-tests labels Jul 16, 2025
@ales-otf ales-otf marked this pull request as ready for review July 16, 2025 10:58
@ales-otf ales-otf changed the title Make alpha type safe Make alpha a type-safe Jul 16, 2025
Copy link
Collaborator

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job overall!

I noticed that you introduce aliases more often than use Alpha as it is. What do you think about renaming it instead? Maybe AlphaToken instead of AlphaCurrency?

@ales-otf
Copy link
Contributor Author

Great job overall!

I noticed that you introduce aliases more often than use Alpha as it is. What do you think about renaming it instead? Maybe AlphaToken instead of AlphaCurrency?

Thanks!

Yeah, I was thinking about it as well. Just didn't want to introduce AlphaCurrency, TaoCurrency, *Currency that implement Currency trait inside the currency module. But looks like it would be better to rename it indeed. Thanks

Copy link
Collaborator

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer "AlphaToken".

@sam0x17 sam0x17 merged commit e13bc28 into devnet-ready Jul 17, 2025
88 of 90 checks passed
///
/// * 'stake_to_be_added' (u64):
/// - The amount of stake to be added to the hotkey staking account.
/// * 'alpha_unstaked' (Alpha):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// * 'alpha_unstaked' (Alpha):
/// * 'alpha_unstaked' (AlphaCurrency):


// 3. Swap the alpha to tao and update counters for this subnet.
let tao_unstaked: u64 = Self::unstake_from_subnet(
// 3. Swap the alpba to tao and update counters for this subnet.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 3. Swap the alpba to tao and update counters for this subnet.
// 3. Swap the alpha to tao and update counters for this subnet.

Comment on lines +573 to +574
let amount = amount.to_u64() as i64;
let actual_alpha = alpha_share_pool.update_value_for_one(coldkey, amount);
Copy link
Collaborator

@l0r1s l0r1s Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause overflow and cause an produce negative value

Comment on lines +587 to +588
let amount = amount.to_u64() as i64;
alpha_share_pool.sim_update_value_for_one(amount)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, maybe this is something to be fixed in another PR?

Copy link
Collaborator

@l0r1s l0r1s Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was referenced Jul 17, 2025
@ales-otf ales-otf mentioned this pull request Aug 4, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants